diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..89c2e1e --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.bash_history +build-* +.vscode +compile_commands.json diff --git a/LICENSE b/LICENSE index 5758acc..92a8418 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 Michel Pollet +Copyright (c) 2023 Michel Pollet Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..fe9befb --- /dev/null +++ b/Makefile @@ -0,0 +1,105 @@ + +# GCC is default -- simply because it's faster! +CC = gcc +SHELL = /bin/bash +# This is where (g)make looks for the source files for implicit rules +VPATH := src src/format src/drivers nuklear contrib + +CPPFLAGS += -Isrc -Isrc/format -Isrc/roms -Isrc/drivers +CPPFLAGS += -Icontrib -Inuklear +CPPFLAGS += -Ilibmish/src +CFLAGS += --std=gnu99 -Wall -Wextra -O2 -g +CFLAGS += -Wno-unused-parameter -Wno-unused-function +LDLIBS += -lX11 -lm -lGL -lGLU + +HAS_ALSA := $(shell pkg-config --exists alsa && echo 1) +ifeq ($(HAS_ALSA),1) +LDLIBS += $(shell pkg-config --libs alsa) +CPPFLAGS += $(shell pkg-config --cflags alsa) -DHAS_ALSA +else +${warning ALSA not found, no sound support} +endif + +O := build-$(shell $(CC) -dumpmachine) +BIN := $(O)/bin +LIB := $(O)/lib +OBJ := $(O)/obj + +all : $(BIN)/mii_emu + +MII_SRC := $(wildcard src/*.c src/format/*.c \ + src/drivers/*.c contrib/*.c) +UI_SRC := $(wildcard nuklear/*.c) +SRC := $(MII_SRC) $(UI_SRC) +ALL_OBJ := ${patsubst %, ${OBJ}/%, ${notdir ${SRC:.c=.o}}} + +$(BIN)/mii_emu : $(ALL_OBJ) +$(BIN)/mii_emu : $(LIB)/libmish.a + +libmish : $(LIB)/libmish.a +LDLIBS += $(LIB)/libmish.a +$(LIB)/libmish.a : | $(LIB) $(OBJ) $(BIN) + make -j -C libmish O=$(PWD) + +# Smartport firmware needs the assembler first +test/asm/%.bin : test/asm/%.asm | $(BIN)/mii_asm + $(BIN)/mii_asm -v -o $@ $< +# And it also INCBIN the firmware driver +$(OBJ)/mii_smarport.o : test/asm/mii_smartport_driver.bin + +$(OBJ)/libsofd.o : CPPFLAGS += -DHAVE_X11 + +clean : + rm -rf $(O) + +# This is for development purpose. This will recompile the project +# everytime a file is modified. +watch : + while true; do \ + clear; $(MAKE) -j all tests; \ + inotifywait -qre close_write src src/format nuklear test; \ + done + +tests : $(BIN)/mii_test $(BIN)/mii_cpu_test $(BIN)/mii_asm + +# Just the library for mii, not any of the UI stuff +TEST_OBJ := ${patsubst %, ${OBJ}/%, ${notdir ${MII_SRC:.c=.o}}} +VPATH += test +# Base test without the UI, for performance testing +$(BIN)/mii_test : $(TEST_OBJ) +$(BIN)/mii_test : $(OBJ)/mii_test.o $(OBJ)/mii_mish.o +$(OBJ)/mii_test.o : CFLAGS += -O0 -Og + +$(OBJ)/mii_cpu_test.o : CFLAGS += -O0 -Og +$(BIN)/mii_cpu_test : $(OBJ)/mii_cpu_test.o $(TEST_OBJ) + +$(BIN)/mii_asm : $(OBJ)/mii_asm.o $(TEST_OBJ) + +ifeq ($(V),1) +Q := +else +Q := @ +endif + +$(OBJ)/%.o : %.c | $(OBJ) + @echo " CC $<" + $(Q)$(CC) -MMD $(CPPFLAGS) $(CFLAGS) -c -o $@ $< + +$(BIN)/% : | $(BIN) + @echo " LD $@" + $(Q)$(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS) + +$(OBJ) $(BIN) $(LIB) : + @mkdir -p $@ + +# Generates the necessary file to help clangd index the files properly. +# This currently has to be done manually, but helps a lot if you use 'kate' +# editor or anthing else that is compatible with the LSP protocol +compile_commands.json: lsp +lsp: + { $$(which gmake) CC=gcc V=1 --always-make --dry-run all tests; \ + $$(which gmake) CC=gcc V=1 --always-make --dry-run -C libmish ; } | \ + sh utils/clangd_gen.sh >compile_commands.json + +-include $(O)/*.d +-include $(O)/obj/*.d diff --git a/README.md b/README.md new file mode 100644 index 0000000..7fc16b7 --- /dev/null +++ b/README.md @@ -0,0 +1,152 @@ +# MII Apple //e Emulator + +I know there are many out there, but none of them were ticking my fancy, so I decide to write my own. To start with it was "How hard can it be really?" then it snowballed as more and more things were fixed & added. It's been shelved for a while because well, it lacked documentation, headers, licence and stuff, so I spent some time cleaning it up for release. + +One primary reason for this project was that linapple (or -pie) codebase is really horrible. It dates back from 2000's or before, with loads of Windows crud leftover, some SDL crud added, the audio just doesn't really work, and overall if you want to hack around the codebase, it's pretty dreadful. + + +![Monochrome Double-Hi res](docs/screen_main.png) +*Double hires in monochrome* + +I wanted something: + +* Modern, Clean code, modular -- in the spirit of simavr, usable as a library. +* Made for linux. In C. With a Makefile. None of the trendy bloatware. +* Small, Fast. +* Minimal dependencies. +* No gigantic config file. +* I didn't need II+ or unenhanced IIe, just 65c02 //e. + + +![Glorious NTSC colors](docs/screen_color.png) +*Double hires in color* + +## What can it do? + * 65c02 //e with 128K of ram. + * Support all known graphic modes: + * Double-hires in mono and color, with automatic switch + * All the other modes in color/mono + * Color, Green, Amber rendering + * Simulated 'scanlines' to make it look vintage + * Speaker audio. ALSA For playback. + * Adds a small 'attack' filter when playing back to soften the often annoying 'click' of typical audio effects from the apple II. + * Mouse Card -- mouse isn't captured like in some other emulators. + * No Slot Clock + * Smartport DMA 'hard drive' card + * "Titan Accelerator //e" simulation, to turn on/off fast mode. + * Terence's J Boldt [1MB ROM card](https://github.com/tjboldt/ProDOS-ROM-Drive), also because I own a couple! + * Floppy Drive [more on that later] + * No dependencies (X11) OpenGL rendering, using Nuklear backend for UI + +![Phosphorescent Green](docs/screen_green.png) +*Good old green monitor style. Theres Amber too.* + +## How to I compile it and run it? + * You need a C compiler, make, and a few libraries: + * libasound2-dev [ optional, for audio ] + * libgl-dev + * libglu-dev + * libx11-dev + * Many of them will probably be installed already. + * For more details on development, see [Compiling](docs/Compiling.md) + * Then just type `make` and it should compile. + * To run it, just type `build-x86_64-linux-gnu/bin/bin/mii_emu` and it should start. + * `mii_emu --help` will display: + + Usage: ./build-x86_64-linux-gnu/bin/mii_emu [options] + Options: + -h, --help This help + -v, --verbose Verbose output + -m, --mute Mute the speaker + -vol, --volume Set speaker volume (0.0 to 10.0) + -speed, --speed Set the CPU speed in MHz + -s, --slot : Specify a slot and driver + Slot id is 1..7 + -d, --drive :: Specify a drive + Slot id is 1..7, drive is 1..2 + Alternate syntax: : + -L, --list-drivers List available drivers + -def, --default Set default drives: + Slot 4: mouse + Slot 6: disk2 + Slot 7: smartport + -nsc[=0|1] Enable/Disable No Slot Clock: + 0: disable + 1: enable [Enabled by default] + -titan[=0|1] Enable/Disable Titan Accelerator IIe: + 0: disable [default] + 1: enable [Start at 3.58MHz] + And the available drivers: + + $ ./build-x86_64-linux-gnu/bin/mii_emu -L + mii: available drivers: + titan - Titan Accelerator IIe + smartport - SmartPort card + nsc - No Slot Clock + mouse - Mouse card + eecard - EEPROM 1MB card + disk2 - Apple Disk ][ + +## Key Bindings +There are just a few keys that are mapped for anything useful. + * **Control-F12** is Control-Reset on the IIe. (**Shift-Control-F12** is **Open Apple-Reset**) + * **'Super'** left and **'Super'** right are **Open** and **Close Apple** keys. + These keys are mapped to the left and right 'Windows' keys on a PC keyboard, and they might want to open the start menu (I know it's the case with Cinnamon), so you might want to disable that. + * **F5** sets the CPU speed to 1MHz + * **F6** to 4MHz. + * These keys control the built-in debugger: + * **Control-F11** Stops the emulator; see the command prompt/telnet for how to proceed, dump state, disassembly etc. + * **Control-F10** 'steps' the emulator, ie one instruction at a time. + * **Control-F9** is 'continue' -- resumes the emulator. + + +![Telnet into mii_emu](docs/screen_mish.png) +*The built-in shell, telnet into the emulator!* + +## Anything else? + * Well it has it's own command line shell, using my own [libmish](https://github.com/buserror/libmish) so there's loads you can do by... *telnet into* the emulator! + * Yes, you can telnet into the running emulator! + + The telnet port is displayed in the window title bar. + + The port is 'semi random' -- it tries to find one that is derivative of the program name, but it will try several until it finds one that is free. + * It has it's own debugger shell. You can: + + Add break/watch points. + + Step, Next (jump over JSR's), Continue, Halt + + Has a 16 instruction trace history when hitting a breakpoint. + + Dump memory map + + Trigger soft switches + + Disassemble + * Also MII comes with it's own mini-assembler, used to compile some driver and the CPU unit tests (inspired by apple2ts, see bellow) + * It embeds all the files it needs, ROMs, fonts etc so you don't need to install it, just run it, it'll work. + * MII "Hard Disk" uses 'overlay' files: + + This writes blocks on a /separate/ (sparse) file from the main file. + + This "Overlay" is created automatically and allows you to keep your image files clean, unless you want to 'commit' your overlay back in. + + This allows you to make sure your disk images aren't corrupted when 'hard rebooting' the emulator, if you are in the process of testing/developing a program for example. + +## What it cannot do + * MouseCalc crashes (VBL IRQ, or a mouse mode I don't support yet) + * A2Desktop PT3 player doesn't see keypresses. + * Sometimes the emulator goes in 'slow mode', ie 0.2MHz. Likely the frame scheduler playing up. + * Thats' about it really, all the other things I tried work + +## What it could do with + * Not sure about keeping Nuklear, it does a lot bit it's hard work customizing anything + * Add a memory extension 'card' -- not sure why, but hey, why not. + * Joystick support. As soon as I find a USB joystick that vaguely looks retro, I'll get one. + * The main window is 1280x720 on purpose, so it could do Full Screen. + * Port it to Raspbery Pi. I don't expect compiling issues, just video issues with GLes + * Make a tool to 'flatten' overlay files back into the primary image. + * Some sort of UI to select/eject disks. + + +![Total Replay](docs/screen_total.png) +*Obligatory View of [Total Replay](https://github.com/a2-4am/4cade), from legend [4am](https://github.com/a2-4am)* +## Inspiration, Licence etc + * MIT Licence, I think this is the most permissive, and this work is a derivative and has a lot of inpsiration from too many projects to claim anything more restrictive. + * The CPU Emulation was inspired by a few other implementations: + * [Chips](https://github.com/floooh/chips) -- which I used for a little while, but it was a pain to add the 65c02 instructions, and it had stuff I didn't want/need like 6510 emulation. + * [Apple2ts](https://github.com/ct6502/apple2ts/) -- In fact I converted a few bits from there; and I got the idea for the built-in assember from there, and some of the unit tests, AND the Smartport driver emulation idea! + * Other bits were inspired by: + * [bobbin](https://github.com/micahcowan/bobbin) which is newish as well, and is great for text mode, but I didn't like the fact its' all globals etc. I still borrowed the Floppy emulation from there, until I get around to do one. + * [isapple2](https://github.com/ivanizag/izapple2/) for other bits and pieces. + * And of course, countless books, articles and posts read over the last 40 years! + diff --git a/contrib/incbin.h b/contrib/incbin.h new file mode 100644 index 0000000..1fb4add --- /dev/null +++ b/contrib/incbin.h @@ -0,0 +1,379 @@ +/** + * @file incbin.h + * @author Dale Weiler + * @brief Utility for including binary files + * + * Facilities for including binary files into the current translation unit and + * making use from them externally in other translation units. + */ +#ifndef INCBIN_HDR +#define INCBIN_HDR +#include + +// Michel addition: +// Allow the included file to have an extra zero, to include text files +// as plain zero terminated strings +#ifdef INCBIN_TRAILING_ZERO +#define INCBIN_TRAIL INCBIN_BYTE "0\n" +#else +#define INCBIN_TRAIL +#endif + +#if defined(__AVX512BW__) || \ + defined(__AVX512CD__) || \ + defined(__AVX512DQ__) || \ + defined(__AVX512ER__) || \ + defined(__AVX512PF__) || \ + defined(__AVX512VL__) || \ + defined(__AVX512F__) +# define INCBIN_ALIGNMENT_INDEX 6 +#elif defined(__AVX__) || \ + defined(__AVX2__) +# define INCBIN_ALIGNMENT_INDEX 5 +#elif defined(__SSE__) || \ + defined(__SSE2__) || \ + defined(__SSE3__) || \ + defined(__SSSE3__) || \ + defined(__SSE4_1__) || \ + defined(__SSE4_2__) || \ + defined(__neon__) +# define INCBIN_ALIGNMENT_INDEX 4 +#elif ULONG_MAX != 0xffffffffu +# define INCBIN_ALIGNMENT_INDEX 3 +# else +# define INCBIN_ALIGNMENT_INDEX 2 +#endif + +/* Lookup table of (1 << n) where `n' is `INCBIN_ALIGNMENT_INDEX' */ +#define INCBIN_ALIGN_SHIFT_0 1 +#define INCBIN_ALIGN_SHIFT_1 2 +#define INCBIN_ALIGN_SHIFT_2 4 +#define INCBIN_ALIGN_SHIFT_3 8 +#define INCBIN_ALIGN_SHIFT_4 16 +#define INCBIN_ALIGN_SHIFT_5 32 +#define INCBIN_ALIGN_SHIFT_6 64 + +/* Actual alignment value */ +#define INCBIN_ALIGNMENT \ + INCBIN_CONCATENATE( \ + INCBIN_CONCATENATE(INCBIN_ALIGN_SHIFT, _), \ + INCBIN_ALIGNMENT_INDEX) + +/* Stringize */ +#define INCBIN_STR(X) \ + #X +#define INCBIN_STRINGIZE(X) \ + INCBIN_STR(X) +/* Concatenate */ +#define INCBIN_CAT(X, Y) \ + X ## Y +#define INCBIN_CONCATENATE(X, Y) \ + INCBIN_CAT(X, Y) +/* Deferred macro expansion */ +#define INCBIN_EVAL(X) \ + X +#define INCBIN_INVOKE(N, ...) \ + INCBIN_EVAL(N(__VA_ARGS__)) + +/* Green Hills uses a different directive for including binary data */ +#if defined(__ghs__) +# if (__ghs_asm == 2) +# define INCBIN_MACRO ".file" +/* Or consider the ".myrawdata" entry in the ld file */ +# else +# define INCBIN_MACRO "\tINCBIN" +# endif +#else +# define INCBIN_MACRO ".incbin" +#endif + +#ifndef _MSC_VER +# define INCBIN_ALIGN \ + __attribute__((aligned(INCBIN_ALIGNMENT))) +#else +# define INCBIN_ALIGN __declspec(align(INCBIN_ALIGNMENT)) +#endif + +#if defined(__arm__) || /* GNU C and RealView */ \ + defined(__arm) || /* Diab */ \ + defined(_ARM) /* ImageCraft */ +# define INCBIN_ARM +#endif + +#ifdef __GNUC__ +/* Utilize .balign where supported */ +# define INCBIN_ALIGN_HOST ".balign " INCBIN_STRINGIZE(INCBIN_ALIGNMENT) "\n" +# define INCBIN_ALIGN_BYTE ".balign 1\n" +#elif defined(INCBIN_ARM) +/* + * On arm assemblers, the alignment value is calculated as (1 << n) where `n' is + * the shift count. This is the value passed to `.align' + */ +# define INCBIN_ALIGN_HOST ".align " INCBIN_STRINGIZE(INCBIN_ALIGNMENT_INDEX) "\n" +# define INCBIN_ALIGN_BYTE ".align 0\n" +#else +/* We assume other inline assembler's treat `.align' as `.balign' */ +# define INCBIN_ALIGN_HOST ".align " INCBIN_STRINGIZE(INCBIN_ALIGNMENT) "\n" +# define INCBIN_ALIGN_BYTE ".align 1\n" +#endif + +/* INCBIN_CONST is used by incbin.c generated files */ +#if defined(__cplusplus) +# define INCBIN_EXTERNAL extern "C" +# define INCBIN_CONST extern const +#else +# define INCBIN_EXTERNAL extern +# define INCBIN_CONST const +#endif + +/** + * @brief Optionally override the linker section into which data is emitted. + * + * @warning If you use this facility, you'll have to deal with platform-specific linker output + * section naming on your own + * + * Overriding the default linker output section, e.g for esp8266/Arduino: + * @code + * #define INCBIN_OUTPUT_SECTION ".irom.text" + * #include "incbin.h" + * INCBIN(Foo, "foo.txt"); + * // Data is emitted into program memory that never gets copied to RAM + * @endcode + */ +#if !defined(INCBIN_OUTPUT_SECTION) +# if defined(__APPLE__) +# define INCBIN_OUTPUT_SECTION ".const_data" +# else +# define INCBIN_OUTPUT_SECTION ".rodata" +# endif +#endif + +#if defined(__APPLE__) +/* The directives are different for Apple branded compilers */ +# define INCBIN_SECTION INCBIN_OUTPUT_SECTION "\n" +# define INCBIN_GLOBAL(NAME) ".globl " INCBIN_MANGLE INCBIN_STRINGIZE(INCBIN_PREFIX) #NAME "\n" +# define INCBIN_INT ".long " +# define INCBIN_MANGLE "_" +# define INCBIN_BYTE ".byte " +# define INCBIN_TYPE(...) +#else +# define INCBIN_SECTION ".section " INCBIN_OUTPUT_SECTION "\n" +# define INCBIN_GLOBAL(NAME) ".global " INCBIN_STRINGIZE(INCBIN_PREFIX) #NAME "\n" +# if defined(__ghs__) +# define INCBIN_INT ".word " +# else +# define INCBIN_INT ".int " +# endif +# if defined(__USER_LABEL_PREFIX__) +# define INCBIN_MANGLE INCBIN_STRINGIZE(__USER_LABEL_PREFIX__) +# else +# define INCBIN_MANGLE "" +# endif +# if defined(INCBIN_ARM) +/* On arm assemblers, `@' is used as a line comment token */ +# define INCBIN_TYPE(NAME) ".type " INCBIN_STRINGIZE(INCBIN_PREFIX) #NAME ", %object\n" +# elif defined(__MINGW32__) || defined(__MINGW64__) +/* Mingw doesn't support this directive either */ +# define INCBIN_TYPE(NAME) +# else +/* It's safe to use `@' on other architectures */ +# define INCBIN_TYPE(NAME) ".type " INCBIN_STRINGIZE(INCBIN_PREFIX) #NAME ", @object\n" +# endif +# define INCBIN_BYTE ".byte " +#endif + +/* List of style types used for symbol names */ +#define INCBIN_STYLE_CAMEL 0 +#define INCBIN_STYLE_SNAKE 1 + +/** + * @brief Specify the prefix to use for symbol names. + * + * By default this is `g', producing symbols of the form: + * @code + * #include "incbin.h" + * INCBIN(Foo, "foo.txt"); + * + * // Now you have the following symbols: + * // const unsigned char gFooData[]; + * // const unsigned char *const gFooEnd; + * // const unsigned int gFooSize; + * @endcode + * + * If however you specify a prefix before including: e.g: + * @code + * #define INCBIN_PREFIX incbin + * #include "incbin.h" + * INCBIN(Foo, "foo.txt"); + * + * // Now you have the following symbols instead: + * // const unsigned char incbinFooData[]; + * // const unsigned char *const incbinFooEnd; + * // const unsigned int incbinFooSize; + * @endcode + */ +#if !defined(INCBIN_PREFIX) +# define INCBIN_PREFIX g +#endif + +/** + * @brief Specify the style used for symbol names. + * + * Possible options are + * - INCBIN_STYLE_CAMEL "CamelCase" + * - INCBIN_STYLE_SNAKE "snake_case" + * + * Default option is *INCBIN_STYLE_CAMEL* producing symbols of the form: + * @code + * #include "incbin.h" + * INCBIN(Foo, "foo.txt"); + * + * // Now you have the following symbols: + * // const unsigned char FooData[]; + * // const unsigned char *const FooEnd; + * // const unsigned int FooSize; + * @endcode + * + * If however you specify a style before including: e.g: + * @code + * #define INCBIN_STYLE INCBIN_STYLE_SNAKE + * #include "incbin.h" + * INCBIN(foo, "foo.txt"); + * + * // Now you have the following symbols: + * // const unsigned char foo_data[]; + * // const unsigned char *const foo_end; + * // const unsigned int foo_size; + * @endcode + */ +#if !defined(INCBIN_STYLE) +# define INCBIN_STYLE INCBIN_STYLE_CAMEL +#endif + +/* Style lookup tables */ +#define INCBIN_STYLE_0_DATA Data +#define INCBIN_STYLE_0_END End +#define INCBIN_STYLE_0_SIZE Size +#define INCBIN_STYLE_1_DATA _data +#define INCBIN_STYLE_1_END _end +#define INCBIN_STYLE_1_SIZE _size + +/* Style lookup: returning identifier */ +#define INCBIN_STYLE_IDENT(TYPE) \ + INCBIN_CONCATENATE( \ + INCBIN_STYLE_, \ + INCBIN_CONCATENATE( \ + INCBIN_EVAL(INCBIN_STYLE), \ + INCBIN_CONCATENATE(_, TYPE))) + +/* Style lookup: returning string literal */ +#define INCBIN_STYLE_STRING(TYPE) \ + INCBIN_STRINGIZE( \ + INCBIN_STYLE_IDENT(TYPE)) \ + +/* Generate the global labels by indirectly invoking the macro with our style + * type and concatenating the name against them. */ +#define INCBIN_GLOBAL_LABELS(NAME, TYPE) \ + INCBIN_INVOKE( \ + INCBIN_GLOBAL, \ + INCBIN_CONCATENATE( \ + NAME, \ + INCBIN_INVOKE( \ + INCBIN_STYLE_IDENT, \ + TYPE))) \ + INCBIN_INVOKE( \ + INCBIN_TYPE, \ + INCBIN_CONCATENATE( \ + NAME, \ + INCBIN_INVOKE( \ + INCBIN_STYLE_IDENT, \ + TYPE))) + +/** + * @brief Externally reference binary data included in another translation unit. + * + * Produces three external symbols that reference the binary data included in + * another translation unit. + * + * The symbol names are a concatenation of `INCBIN_PREFIX' before *NAME*; with + * "Data", as well as "End" and "Size" after. An example is provided below. + * + * @param NAME The name given for the binary data + * + * @code + * INCBIN_EXTERN(Foo); + * + * // Now you have the following symbols: + * // extern const unsigned char FooData[]; + * // extern const unsigned char *const FooEnd; + * // extern const unsigned int FooSize; + * @endcode + */ +#define INCBIN_EXTERN(NAME) \ + INCBIN_EXTERNAL const INCBIN_ALIGN unsigned char \ + INCBIN_CONCATENATE( \ + INCBIN_CONCATENATE(INCBIN_PREFIX, NAME), \ + INCBIN_STYLE_IDENT(DATA))[]; \ + INCBIN_EXTERNAL const INCBIN_ALIGN unsigned char *const \ + INCBIN_CONCATENATE( \ + INCBIN_CONCATENATE(INCBIN_PREFIX, NAME), \ + INCBIN_STYLE_IDENT(END)); \ + INCBIN_EXTERNAL const unsigned int \ + INCBIN_CONCATENATE( \ + INCBIN_CONCATENATE(INCBIN_PREFIX, NAME), \ + INCBIN_STYLE_IDENT(SIZE)) + +/** + * @brief Include a binary file into the current translation unit. + * + * Includes a binary file into the current translation unit, producing three symbols + * for objects that encode the data and size respectively. + * + * The symbol names are a concatenation of `INCBIN_PREFIX' before *NAME*; with + * "Data", as well as "End" and "Size" after. An example is provided below. + * + * @param NAME The name to associate with this binary data (as an identifier.) + * @param FILENAME The file to include (as a string literal.) + * + * @code + * INCBIN(Icon, "icon.png"); + * + * // Now you have the following symbols: + * // const unsigned char IconData[]; + * // const unsigned char *const IconEnd; + * // const unsigned int IconSize; + * @endcode + * + * @warning This must be used in global scope + * @warning The identifiers may be different if INCBIN_STYLE is not default + * + * To externally reference the data included by this in another translation unit + * please @see INCBIN_EXTERN. + */ +#ifdef _MSC_VER +#define INCBIN(NAME, FILENAME) \ + INCBIN_EXTERN(NAME) +#else +#define INCBIN(NAME, FILENAME) \ + __asm__(INCBIN_SECTION \ + INCBIN_GLOBAL_LABELS(NAME, DATA) \ + INCBIN_ALIGN_HOST \ + INCBIN_MANGLE INCBIN_STRINGIZE(INCBIN_PREFIX) #NAME INCBIN_STYLE_STRING(DATA) ":\n" \ + INCBIN_MACRO " \"" FILENAME "\"\n" \ + INCBIN_TRAIL \ + INCBIN_GLOBAL_LABELS(NAME, END) \ + INCBIN_ALIGN_BYTE \ + INCBIN_MANGLE INCBIN_STRINGIZE(INCBIN_PREFIX) #NAME INCBIN_STYLE_STRING(END) ":\n" \ + INCBIN_BYTE "1\n" \ + INCBIN_GLOBAL_LABELS(NAME, SIZE) \ + INCBIN_ALIGN_HOST \ + INCBIN_MANGLE INCBIN_STRINGIZE(INCBIN_PREFIX) #NAME INCBIN_STYLE_STRING(SIZE) ":\n" \ + INCBIN_INT INCBIN_MANGLE INCBIN_STRINGIZE(INCBIN_PREFIX) #NAME INCBIN_STYLE_STRING(END) " - " \ + INCBIN_MANGLE INCBIN_STRINGIZE(INCBIN_PREFIX) #NAME INCBIN_STYLE_STRING(DATA) "\n" \ + INCBIN_ALIGN_HOST \ + ".text\n" \ + ); \ + INCBIN_EXTERN(NAME) + +#endif +#endif diff --git a/contrib/libsofd.c b/contrib/libsofd.c new file mode 100644 index 0000000..f475b67 --- /dev/null +++ b/contrib/libsofd.c @@ -0,0 +1,2413 @@ +/* libSOFD - Simple Open File Dialog [for X11 without toolkit] + * + * Copyright (C) 2014 Robin Gareus + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +/* Test and example: + * gcc -Wall -D SOFD_TEST -g -o sofd libsofd.c -lX11 + * + * public API documentation and example code at the bottom of this file + * + * This small lib may one day include openGL rendering and + * wayland window support, but not today. Today we celebrate + * 30 years of X11. + */ + +#ifdef SOFD_TEST +#define HAVE_X11 +#include "libsofd.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// shared 'recently used' implementation +// sadly, xbel does not qualify as simple. +// hence we use a simple format alike the +// gtk-bookmark list (one file per line) + +#define MAX_RECENT_ENTRIES 24 +#define MAX_RECENT_AGE (15552000) // 180 days (in sec) + +typedef struct { + char path[1024]; + time_t atime; +} FibRecentFile; + +static FibRecentFile *_recentlist = NULL; +static unsigned int _recentcnt = 0; +static uint8_t _recentlock = 0; + +static int fib_isxdigit (const char x) { + if ( + (x >= '0' && x <= '9') + || + (x >= 'a' && x <= 'f') + || + (x >= 'A' && x <= 'F') + ) return 1; + return 0; +} + +static void decode_3986 (char *str) { + int len = strlen (str); + int idx = 0; + while (idx + 2 < len) { + char *in = &str[idx]; + if (('%' == *in) && fib_isxdigit (in[1]) && fib_isxdigit (in[2])) { + char hexstr[3]; + hexstr[0] = in[1]; + hexstr[1] = in[2]; + hexstr[2] = 0; + long hex = strtol (hexstr, NULL, 16); + *in = hex; + memmove (&str[idx+1], &str[idx + 3], len - idx - 2); + len -= 2; + } + ++idx; + } +} + +static char *encode_3986 (const char *str) { + size_t alloc, newlen; + char *ns = NULL; + unsigned char in; + size_t i = 0; + size_t length; + + if (!str) return strdup (""); + + alloc = strlen (str) + 1; + newlen = alloc; + + ns = (char*) malloc (alloc); + + length = alloc; + while (--length) { + in = *str; + + switch (in) { + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + 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': + 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': + case '_': case '~': case '.': case '-': + case '/': case ',': // XXX not in RFC3986 + ns[i++] = in; + break; + default: + newlen += 2; /* this'll become a %XX */ + if (newlen > alloc) { + alloc *= 2; + ns = (char*) realloc (ns, alloc); + } + snprintf (&ns[i], 4, "%%%02X", in); + i += 3; + break; + } + ++str; + } + ns[i] = 0; + return ns; +} + +void x_fib_free_recent () { + free (_recentlist); + _recentlist = NULL; + _recentcnt = 0; +} + +static int cmp_recent (const void *p1, const void *p2) { + FibRecentFile *a = (FibRecentFile*) p1; + FibRecentFile *b = (FibRecentFile*) p2; + if (a->atime == b->atime) return 0; + return a->atime < b->atime; +} + +int x_fib_add_recent (const char *path, time_t atime) { + unsigned int i; + struct stat fs; + if (_recentlock) { return -1; } + if (access (path, R_OK)) { + return -1; + } + if (stat (path, &fs)) { + return -1; + } + if (!S_ISREG (fs.st_mode)) { + return -1; + } + if (atime == 0) atime = time (NULL); + if (MAX_RECENT_AGE > 0 && atime + MAX_RECENT_AGE < time (NULL)) { + return -1; + } + + for (i = 0; i < _recentcnt; ++i) { + if (!strcmp (_recentlist[i].path, path)) { + if (_recentlist[i].atime < atime) { + _recentlist[i].atime = atime; + } + qsort (_recentlist, _recentcnt, sizeof(FibRecentFile), cmp_recent); + return _recentcnt; + } + } + _recentlist = (FibRecentFile*)realloc (_recentlist, (_recentcnt + 1) * sizeof(FibRecentFile)); + _recentlist[_recentcnt].atime = atime; + strcpy (_recentlist[_recentcnt].path, path); + qsort (_recentlist, _recentcnt + 1, sizeof(FibRecentFile), cmp_recent); + + if (_recentcnt >= MAX_RECENT_ENTRIES) { + return (_recentcnt); + } + return (++_recentcnt); +} + +#ifdef PATHSEP +#undef PATHSEP +#endif + +#ifdef PLATFORM_WINDOWS +#define DIRSEP '\\' +#else +#define DIRSEP '/' +#endif + +static void mkpath(const char *dir) { + char tmp[1024]; + char *p; + size_t len; + + snprintf (tmp, sizeof(tmp), "%s", dir); + len = strlen(tmp); + if (tmp[len - 1] == '/') + tmp[len - 1] = 0; + for (p = tmp + 1; *p; ++p) + if(*p == DIRSEP) { + *p = 0; +#ifdef PLATFORM_WINDOWS + mkdir(tmp); +#else + mkdir(tmp, 0755); +#endif + *p = DIRSEP; + } +#ifdef PLATFORM_WINDOWS + mkdir(tmp); +#else + mkdir(tmp, 0755); +#endif +} + +int x_fib_save_recent (const char *fn) { + if (_recentlock) { return -1; } + if (!fn) { return -1; } + if (_recentcnt < 1 || !_recentlist) { return -1; } + unsigned int i; + char *dn = strdup (fn); + mkpath (dirname (dn)); + free (dn); + + FILE *rf = fopen (fn, "w"); + if (!rf) return -1; + + qsort (_recentlist, _recentcnt, sizeof(FibRecentFile), cmp_recent); + for (i = 0; i < _recentcnt; ++i) { + char *n = encode_3986 (_recentlist[i].path); + fprintf (rf, "%s %lu\n", n, _recentlist[i].atime); + free (n); + } + fclose (rf); + return 0; +} + +int x_fib_load_recent (const char *fn) { + char tmp[1024]; + if (_recentlock) { return -1; } + if (!fn) { return -1; } + x_fib_free_recent (); + if (access (fn, R_OK)) { + return -1; + } + FILE *rf = fopen (fn, "r"); + if (!rf) return -1; + while (fgets (tmp, sizeof(tmp), rf) + && strlen (tmp) > 1 + && strlen (tmp) < sizeof(tmp)) + { + char *s; + tmp[strlen (tmp) - 1] = '\0'; // strip newline + if (!(s = strchr (tmp, ' '))) { // find name <> atime sep + continue; + } + *s = '\0'; + time_t t = atol (++s); + decode_3986 (tmp); + x_fib_add_recent (tmp, t); + } + fclose (rf); + return 0; +} + +unsigned int x_fib_recent_count () { + return _recentcnt; +} + +const char *x_fib_recent_at (unsigned int i) { + if (i >= _recentcnt) + return NULL; + return _recentlist[i].path; +} + +#ifdef PLATFORM_WINDOWS +#define PATHSEP "\\" +#else +#define PATHSEP "/" +#endif + +const char *x_fib_recent_file(const char *appname) { + static char recent_file[1024]; + assert(!strchr(appname, '/')); + const char *xdg = getenv("XDG_DATA_HOME"); + if (xdg && (strlen(xdg) + strlen(appname) + 10) < sizeof(recent_file)) { + sprintf(recent_file, "%s" PATHSEP "%s" PATHSEP "recent", xdg, appname); + return recent_file; + } +#ifdef PLATFORM_WINDOWS + const char * homedrive = getenv("HOMEDRIVE"); + const char * homepath = getenv("HOMEPATH"); + if (homedrive && homepath && (strlen(homedrive) + strlen(homepath) + strlen(appname) + 29) < PATH_MAX) { + sprintf(recent_file, "%s%s" PATHSEP "Application Data" PATHSEP "%s" PATHSEP "recent.txt", homedrive, homepath, appname); + return recent_file; + } +#elif defined PLATFORM_OSX + const char *home = getenv("HOME"); + if (home && (strlen(home) + strlen(appname) + 29) < sizeof(recent_file)) { + sprintf(recent_file, "%s/Library/Preferences/%s/recent", home, appname); + return recent_file; + } +#else + const char *home = getenv("HOME"); + if (home && (strlen(home) + strlen(appname) + 22) < sizeof(recent_file)) { + sprintf(recent_file, "%s/.local/share/%s/recent", home, appname); + return recent_file; + } +#endif + return NULL; +} + +#ifdef HAVE_X11 +#include +#include + +#include +#include +#include +#include +#include + +#ifndef MIN +#define MIN(A,B) ( (A) < (B) ? (A) : (B) ) +#endif + +#ifndef MAX +#define MAX(A,B) ( (A) < (B) ? (B) : (A) ) +#endif + +static Window _fib_win = 0; +static GC _fib_gc = 0; +static XColor _c_gray0, _c_gray1, _c_gray2, _c_gray3, _c_gray4, _c_gray5, _c_gray6; +static Font _fibfont = 0; +static Pixmap _pixbuffer = None; + +static int _fib_width = 100; +static int _fib_height = 100; +static int _btn_w = 0; +static int _btn_span = 0; + +static int _fib_font_height = 0; +static int _fib_dir_indent = 0; +static int _fib_spc_norm = 0; +static int _fib_font_ascent = 0; +static int _fib_font_vsep = 0; +static int _fib_font_size_width = 0; +static int _fib_font_time_width = 0; +static int _fib_place_width = 0; + +static int _scrl_f = 0; +static int _scrl_y0 = -1; +static int _scrl_y1 = -1; +static int _scrl_my = -1; +static int _scrl_mf = -1; +static int _view_p = -1; + +static int _fsel = -1; +static int _hov_b = -1; +static int _hov_f = -1; +static int _hov_p = -1; +static int _hov_h = -1; +static int _hov_l = -1; +static int _hov_s = -1; +static int _sort = 0; +static int _columns = 0; +static int _fib_filter_fn = 1; +static int _fib_hidden_fn = 0; +static int _fib_show_places = 0; + +static uint8_t _fib_mapped = 0; +static uint8_t _fib_resized = 0; +static unsigned long _dblclk = 0; + +static int _status = -2; +static char _rv_open[1024] = ""; + +static char _fib_cfg_custom_places[1024] = ""; +static char _fib_cfg_custom_font[256] = ""; +static char _fib_cfg_title[128] = "xjadeo - Open Video File"; + +typedef struct { + char name[256]; + int x0; + int xw; +} FibPathButton; + +typedef struct { + char name[256]; + char strtime[32]; + char strsize[32]; + int ssizew; + off_t size; + time_t mtime; + uint8_t flags; // 2: selected, 4: isdir 8: recent-entry + FibRecentFile *rfp; +} FibFileEntry; + +typedef struct { + char text[24]; + uint8_t flags; // 2: selected, 4: toggle, 8 disable + int x0; + int tw; + int xw; + void (*callback)(Display*); +} FibButton; + +typedef struct { + char name[256]; + char path[1024]; + uint8_t flags; // 1: hover, 2: selected, 4:add sep +} FibPlace; + +static char _cur_path[1024] = ""; +static FibFileEntry *_dirlist = NULL; +static FibPathButton *_pathbtn = NULL; +static FibPlace *_placelist = NULL; +static int _dircount = 0; +static int _pathparts = 0; +static int _placecnt = 0; + +static FibButton _btn_ok; +static FibButton _btn_cancel; +static FibButton _btn_filter; +static FibButton _btn_places; +static FibButton _btn_hidden; +static FibButton *_btns[] = {&_btn_places, &_btn_filter, &_btn_hidden, &_btn_cancel, &_btn_ok}; + +static int (*_fib_filter_function)(const char *filename); + +/* hardcoded layout */ +#define DSEP 6 // px; horiz space beween elements, also l+r margin for file-list +#define PSEP 4 // px; horiz space beween paths +#define FILECOLUMN (17 * _fib_dir_indent) //px; min width of file-column +#define LISTTOP 2.7 //em; top of the file-browser list +#define LISTBOT 4.75 //em; bottom of the file-browers list +#define BTNBTMMARGIN 0.75 //em; height/margin of the button row +#define BTNPADDING 2 // px - only used for open/cancel buttons +#define SCROLLBARW (3 + (_fib_spc_norm&~1)) //px; - should be SCROLLBARW = (N * 2 + 3) +#define SCROLLBOXH 10 //px; arrow box top+bottom +#define PLACESW _fib_place_width //px; +#define PLACESWMAX (15 *_fib_spc_norm) //px; +#define PATHBTNTOP _fib_font_vsep //px; offset by (_fib_font_ascent); +#define FAREAMRGB 3 //px; base L+R margin +#define FAREAMRGR (FAREAMRGB + 1) //px; right margin of file-area + 1 (line width) +#define FAREAMRGL (_fib_show_places ? PLACESW + FAREAMRGB : FAREAMRGB) //px; left margin of file-area +#define TEXTSEP 4 //px; +#define FAREATEXTL (FAREAMRGL + TEXTSEP) //px; filename text-left FAREAMRGL + TEXTSEP +#define SORTBTNOFF -10 //px; + +#ifndef DBLCLKTME +#define DBLCLKTME 200 //msec; double click time +#endif + +#define DRAW_OUTLINE +#define DOUBLE_BUFFER + +static int query_font_geometry (Display *dpy, GC gc, const char *txt, int *w, int *h, int *a, int *d) { + XCharStruct text_structure; + int font_direction, font_ascent, font_descent; + XFontStruct *fontinfo = XQueryFont (dpy, XGContextFromGC (gc)); + + if (!fontinfo) { return -1; } + XTextExtents (fontinfo, txt, strlen (txt), &font_direction, &font_ascent, &font_descent, &text_structure); + if (w) *w = XTextWidth (fontinfo, txt, strlen (txt)); + if (h) *h = text_structure.ascent + text_structure.descent; + if (a) *a = text_structure.ascent; + if (d) *d = text_structure.descent; + XFreeFontInfo (NULL, fontinfo, 1); + return 0; +} + +static void VDrawRectangle (Display *dpy, Drawable d, GC gc, int x, int y, unsigned int w, unsigned int h) { + const unsigned long blackColor = BlackPixel (dpy, DefaultScreen (dpy)); +#ifdef DRAW_OUTLINE + XSetForeground (dpy, gc, _c_gray5.pixel); + XDrawLine (dpy, d, gc, x + 1, y + h, x + w, y + h); + XDrawLine (dpy, d, gc, x + w, y + 1, x + w, y + h); + + XSetForeground (dpy, gc, blackColor); + XDrawLine (dpy, d, gc, x + 1, y, x + w, y); + XDrawLine (dpy, d, gc, x, y + 1, x, y + h); +#else + XSetForeground (dpy, _fib_gc, blackColor); + XDrawRectangle (dpy, d, gc, x, y, w, h); +#endif +} + +static void fib_expose (Display *dpy, Window realwin) { + int i; + XID win; + const unsigned long whiteColor = WhitePixel (dpy, DefaultScreen (dpy)); + const unsigned long blackColor = BlackPixel (dpy, DefaultScreen (dpy)); + if (!_fib_mapped) return; + + if (_fib_resized +#ifdef DOUBLE_BUFFER + || !_pixbuffer +#endif + ) + { +#ifdef DOUBLE_BUFFER + unsigned int w = 0, h = 0; + if (_pixbuffer != None) { + Window ignored_w; + int ignored_i; + unsigned int ignored_u; + XGetGeometry(dpy, _pixbuffer, &ignored_w, &ignored_i, &ignored_i, &w, &h, &ignored_u, &ignored_u); + if (_fib_width != (int)w || _fib_height != (int)h) { + XFreePixmap (dpy, _pixbuffer); + _pixbuffer = None; + } + } + if (_pixbuffer == None) { + XWindowAttributes wa; + XGetWindowAttributes (dpy, realwin, &wa); + _pixbuffer = XCreatePixmap (dpy, realwin, _fib_width, _fib_height, wa.depth); + } +#endif + if (_pixbuffer != None) { + XSetForeground (dpy, _fib_gc, _c_gray1.pixel); + XFillRectangle (dpy, _pixbuffer, _fib_gc, 0, 0, _fib_width, _fib_height); + } else { + XSetForeground (dpy, _fib_gc, _c_gray1.pixel); + XFillRectangle (dpy, realwin, _fib_gc, 0, 0, _fib_width, _fib_height); + } + _fib_resized = 0; + } + + if (_pixbuffer == None) { + win = realwin; + } else { + win = _pixbuffer; + } + + // Top Row: dirs and up navigation + + int ppw = 0; + int ppx = FAREAMRGB; + + for (i = _pathparts - 1; i >= 0; --i) { + ppw += _pathbtn[i].xw + PSEP; + if (ppw >= _fib_width - PSEP - _pathbtn[0].xw - FAREAMRGB) break; // XXX, first change is from "/" to "<", NOOP + } + ++i; + // border-less "<" parent/up, IFF space is limited + if (i > 0) { + if (0 == _hov_p || (_hov_p > 0 && _hov_p < _pathparts - 1)) { + XSetForeground (dpy, _fib_gc, _c_gray4.pixel); + } else { + XSetForeground (dpy, _fib_gc, blackColor); + } + XDrawString (dpy, win, _fib_gc, ppx, PATHBTNTOP, "<", 1); + ppx += _pathbtn[0].xw + PSEP; + if (i == _pathparts) --i; + } + + _view_p = i; + + while (i < _pathparts) { + if (i == _hov_p) { + XSetForeground (dpy, _fib_gc, _c_gray0.pixel); + } else { + XSetForeground (dpy, _fib_gc, _c_gray2.pixel); + } + XFillRectangle (dpy, win, _fib_gc, + ppx + 1, PATHBTNTOP - _fib_font_ascent, + _pathbtn[i].xw - 1, _fib_font_height); + VDrawRectangle (dpy, win, _fib_gc, + ppx, PATHBTNTOP - _fib_font_ascent, + _pathbtn[i].xw, _fib_font_height); + XDrawString (dpy, win, _fib_gc, ppx + 1 + BTNPADDING, PATHBTNTOP, + _pathbtn[i].name, strlen (_pathbtn[i].name)); + _pathbtn[i].x0 = ppx; // current position + ppx += _pathbtn[i].xw + PSEP; + ++i; + } + + // middle, scroll list of file names + const int ltop = LISTTOP * _fib_font_vsep; + const int llen = (_fib_height - LISTBOT * _fib_font_vsep) / _fib_font_vsep; + const int fsel_height = 4 + llen * _fib_font_vsep; + const int fsel_width = _fib_width - FAREAMRGL - FAREAMRGR - (llen < _dircount ? SCROLLBARW : 0); + const int t_x = FAREATEXTL; + int t_s = FAREATEXTL + fsel_width; + int t_t = FAREATEXTL + fsel_width; + + // check which colums can be visible + // depending on available width of window. + _columns = 0; + if (fsel_width > FILECOLUMN + _fib_font_size_width + _fib_font_time_width) { + _columns |= 2; + t_s = FAREAMRGL + fsel_width - _fib_font_time_width - TEXTSEP; + } + if (fsel_width > FILECOLUMN + _fib_font_size_width) { + _columns |= 1; + t_t = t_s - _fib_font_size_width - TEXTSEP; + } + + int fstop = _scrl_f; // first entry in scroll position + const int ttop = ltop - _fib_font_height + _fib_font_ascent; + + if (fstop > 0 && fstop + llen > _dircount) { + fstop = MAX (0, _dircount - llen); + _scrl_f = fstop; + } + + // list header + XSetForeground (dpy, _fib_gc, _c_gray3.pixel); + XFillRectangle (dpy, win, _fib_gc, FAREAMRGL, ltop - _fib_font_vsep, fsel_width, _fib_font_vsep); + + // draw background of file list + XSetForeground (dpy, _fib_gc, _c_gray2.pixel); + XFillRectangle (dpy, win, _fib_gc, FAREAMRGL, ltop, fsel_width, fsel_height); + +#ifdef DRAW_OUTLINE + VDrawRectangle (dpy, win, _fib_gc, FAREAMRGL, ltop - _fib_font_vsep -1, _fib_width - FAREAMRGL - FAREAMRGR, fsel_height + _fib_font_vsep + 1); +#endif + + switch (_hov_h) { + case 1: + XSetForeground (dpy, _fib_gc, _c_gray0.pixel); + XFillRectangle (dpy, win, _fib_gc, t_x + _fib_dir_indent - TEXTSEP + 1, ltop - _fib_font_vsep, t_t - t_x - _fib_dir_indent - 1, _fib_font_vsep); + break; + case 2: + XSetForeground (dpy, _fib_gc, _c_gray0.pixel); + XFillRectangle (dpy, win, _fib_gc, t_t - TEXTSEP + 1, ltop - _fib_font_vsep, _fib_font_size_width + TEXTSEP - 1, _fib_font_vsep); + break; + case 3: + XSetForeground (dpy, _fib_gc, _c_gray0.pixel); + XFillRectangle (dpy, win, _fib_gc, t_s - TEXTSEP + 1, ltop - _fib_font_vsep, TEXTSEP + TEXTSEP + _fib_font_time_width - 1, _fib_font_vsep); + break; + default: + break; + } + + // column headings and sort order + int arp = MAX (2, _fib_font_height / 5); // arrow scale + const int trioff = _fib_font_height - _fib_font_ascent - arp + 1; + XPoint ptri[4] = { {0, ttop - trioff }, {arp, -arp - arp - 1}, {-arp - arp, 0}, {arp, arp + arp + 1}}; + if (_sort & 1) { + ptri[0].y = ttop -arp - arp - 1; + ptri[1].y *= -1; + ptri[3].y *= -1; + } + switch (_sort) { + case 0: + case 1: + ptri[0].x = t_t + SORTBTNOFF + 2 - arp; + XSetForeground (dpy, _fib_gc, _c_gray6.pixel); + XFillPolygon (dpy, win, _fib_gc, ptri, 3, Convex, CoordModePrevious); + XDrawLines (dpy, win, _fib_gc, ptri, 4, CoordModePrevious); + break; + case 2: + case 3: + if (_columns & 1) { + ptri[0].x = t_s + SORTBTNOFF + 2 - arp; + XSetForeground (dpy, _fib_gc, _c_gray6.pixel); + XFillPolygon (dpy, win, _fib_gc, ptri, 3, Convex, CoordModePrevious); + XDrawLines (dpy, win, _fib_gc, ptri, 4, CoordModePrevious); + } + break; + case 4: + case 5: + if (_columns & 2) { + ptri[0].x = FAREATEXTL + fsel_width + SORTBTNOFF + 2 - arp; + XSetForeground (dpy, _fib_gc, _c_gray6.pixel); + XFillPolygon (dpy, win, _fib_gc, ptri, 3, Convex, CoordModePrevious); + XDrawLines (dpy, win, _fib_gc, ptri, 4, CoordModePrevious); + } + break; + } + +#if 0 // bottom header bottom border + XSetForeground (dpy, _fib_gc, _c_gray5.pixel); + XSetLineAttributes (dpy, _fib_gc, 1, LineOnOffDash, CapButt, JoinMiter); + XDrawLine (dpy, win, _fib_gc, + FAREAMRGL + 1, ltop, + FAREAMRGL + fsel_width, ltop); + XSetLineAttributes (dpy, _fib_gc, 1, LineSolid, CapButt, JoinMiter); +#endif + + XSetForeground (dpy, _fib_gc, _c_gray4.pixel); + XDrawLine (dpy, win, _fib_gc, + t_x + _fib_dir_indent - TEXTSEP, ltop - _fib_font_vsep + 3, + t_x + _fib_dir_indent - TEXTSEP, ltop - 3); + + XSetForeground (dpy, _fib_gc, blackColor); + XDrawString (dpy, win, _fib_gc, t_x + _fib_dir_indent, ttop, "Name", 4); + + if (_columns & 1) { + XSetForeground (dpy, _fib_gc, _c_gray4.pixel); + XDrawLine (dpy, win, _fib_gc, + t_t - TEXTSEP, ltop - _fib_font_vsep + 3, + t_t - TEXTSEP, ltop - 3); + XSetForeground (dpy, _fib_gc, blackColor); + XDrawString (dpy, win, _fib_gc, t_t, ttop, "Size", 4); + } + + if (_columns & 2) { + XSetForeground (dpy, _fib_gc, _c_gray4.pixel); + XDrawLine (dpy, win, _fib_gc, + t_s - TEXTSEP, ltop - _fib_font_vsep + 3, + t_s - TEXTSEP, ltop - 3); + XSetForeground (dpy, _fib_gc, blackColor); + if (_pathparts > 0) + XDrawString (dpy, win, _fib_gc, t_s, ttop, "Last Modified", 13); + else + XDrawString (dpy, win, _fib_gc, t_s, ttop, "Last Used", 9); + } + + // scrollbar sep + if (llen < _dircount) { + const int sx0 = _fib_width - SCROLLBARW - FAREAMRGR; + XSetForeground (dpy, _fib_gc, _c_gray4.pixel); + XDrawLine (dpy, win, _fib_gc, + sx0 - 1, ltop - _fib_font_vsep, +#ifdef DRAW_OUTLINE + sx0 - 1, ltop + fsel_height +#else + sx0 - 1, ltop - 1 +#endif + ); + } + + // clip area for file-name + XRectangle clp = {FAREAMRGL + 1, ltop, t_t - FAREAMRGL - TEXTSEP - TEXTSEP - 1, fsel_height}; + + // list files in view + for (i = 0; i < llen; ++i) { + const int j = i + fstop; + if (j >= _dircount) break; + + const int t_y = ltop + (i+1) * _fib_font_vsep - 4; + + XSetForeground (dpy, _fib_gc, blackColor); + if (_dirlist[j].flags & 2) { + XSetForeground (dpy, _fib_gc, blackColor); + XFillRectangle (dpy, win, _fib_gc, + FAREAMRGL, t_y - _fib_font_ascent, fsel_width, _fib_font_height); + XSetForeground (dpy, _fib_gc, whiteColor); + } + if (_hov_f == j && !(_dirlist[j].flags & 2)) { + XSetForeground (dpy, _fib_gc, _c_gray4.pixel); + } + if (_dirlist[j].flags & 4) { + XDrawString (dpy, win, _fib_gc, t_x, t_y, "D", 1); + } + XSetClipRectangles (dpy, _fib_gc, 0, 0, &clp, 1, Unsorted); + XDrawString (dpy, win, _fib_gc, + t_x + _fib_dir_indent, t_y, + _dirlist[j].name, strlen (_dirlist[j].name)); + XSetClipMask (dpy, _fib_gc, None); + + if (_columns & 1) // right-aligned 'size' + XDrawString (dpy, win, _fib_gc, + t_s - TEXTSEP - 2 - _dirlist[j].ssizew, t_y, + _dirlist[j].strsize, strlen (_dirlist[j].strsize)); + if (_columns & 2) + XDrawString (dpy, win, _fib_gc, + t_s, t_y, + _dirlist[j].strtime, strlen (_dirlist[j].strtime)); + } + + // scrollbar + if (llen < _dircount) { + float sl = (fsel_height + _fib_font_vsep - (SCROLLBOXH + SCROLLBOXH)) / (float) _dircount; + sl = MAX ((8. / llen), sl); // 8px min height of scroller + const int sy1 = llen * sl; + const float mx = (fsel_height + _fib_font_vsep - (SCROLLBOXH + SCROLLBOXH) - sy1) / (float)(_dircount - llen); + const int sy0 = fstop * mx; + const int sx0 = _fib_width - SCROLLBARW - FAREAMRGR; + const int stop = ltop - _fib_font_vsep; + + _scrl_y0 = stop + SCROLLBOXH + sy0; + _scrl_y1 = _scrl_y0 + sy1; + + assert (fstop + llen <= _dircount); + // scroll-bar background + XSetForeground (dpy, _fib_gc, _c_gray3.pixel); + XFillRectangle (dpy, win, _fib_gc, sx0, stop, SCROLLBARW, fsel_height + _fib_font_vsep); + + // scroller + if (_hov_s == 0) { + XSetForeground (dpy, _fib_gc, _c_gray0.pixel); + } else { + XSetForeground (dpy, _fib_gc, _c_gray1.pixel); + } + XFillRectangle (dpy, win, _fib_gc, sx0 + 1, stop + SCROLLBOXH + sy0, SCROLLBARW - 2, sy1); + + int scrw = (SCROLLBARW -3) / 2; + // arrows top and bottom + if (_hov_s == 1) { + XSetForeground (dpy, _fib_gc, _c_gray0.pixel); + } else { + XSetForeground (dpy, _fib_gc, _c_gray1.pixel); + } + XPoint ptst[4] = { {sx0 + 1, stop + 8}, {scrw, -7}, {scrw, 7}, {-2 * scrw, 0}}; + XFillPolygon (dpy, win, _fib_gc, ptst, 3, Convex, CoordModePrevious); + XDrawLines (dpy, win, _fib_gc, ptst, 4, CoordModePrevious); + + if (_hov_s == 2) { + XSetForeground (dpy, _fib_gc, _c_gray0.pixel); + } else { + XSetForeground (dpy, _fib_gc, _c_gray1.pixel); + } + XPoint ptsb[4] = { {sx0 + 1, ltop + fsel_height - 9}, {2*scrw, 0}, {-scrw, 7}, {-scrw, -7}}; + XFillPolygon (dpy, win, _fib_gc, ptsb, 3, Convex, CoordModePrevious); + XDrawLines (dpy, win, _fib_gc, ptsb, 4, CoordModePrevious); + } else { + _scrl_y0 = _scrl_y1 = -1; + } + + if (_fib_show_places) { + assert (_placecnt > 0); + + // heading + XSetForeground (dpy, _fib_gc, _c_gray3.pixel); + XFillRectangle (dpy, win, _fib_gc, FAREAMRGB, ltop - _fib_font_vsep, PLACESW - TEXTSEP, _fib_font_vsep); + + // body + XSetForeground (dpy, _fib_gc, _c_gray2.pixel); + XFillRectangle (dpy, win, _fib_gc, FAREAMRGB, ltop, PLACESW - TEXTSEP, fsel_height); + +#ifdef DRAW_OUTLINE + VDrawRectangle (dpy, win, _fib_gc, FAREAMRGB, ltop - _fib_font_vsep -1, PLACESW - TEXTSEP, fsel_height + _fib_font_vsep + 1); +#endif + + XSetForeground (dpy, _fib_gc, blackColor); + XDrawString (dpy, win, _fib_gc, FAREAMRGB + TEXTSEP, ttop, "Places", 6); + + XRectangle pclip = {FAREAMRGB + 1, ltop, PLACESW - TEXTSEP -1, fsel_height}; + XSetClipRectangles (dpy, _fib_gc, 0, 0, &pclip, 1, Unsorted); + const int plx = FAREAMRGB + TEXTSEP; + for (i = 0; i < llen && i < _placecnt; ++i) { + const int ply = ltop + (i+1) * _fib_font_vsep - 4; + if (i == _hov_l) { + XSetForeground (dpy, _fib_gc, _c_gray4.pixel); + } else { + XSetForeground (dpy, _fib_gc, blackColor); + } + XDrawString (dpy, win, _fib_gc, + plx, ply, + _placelist[i].name, strlen (_placelist[i].name)); + if (_placelist[i].flags & 4) { + XSetForeground (dpy, _fib_gc, _c_gray3.pixel); + const int plly = ply - _fib_font_ascent + _fib_font_height; + const int pllx0 = FAREAMRGB; + const int pllx1 = FAREAMRGB + (PLACESW - TEXTSEP); + XDrawLine (dpy, win, _fib_gc, pllx0, plly, pllx1, plly); + } + } + XSetClipMask (dpy, _fib_gc, None); + + if (_placecnt > llen) { + const int plly = ltop + fsel_height - _fib_font_height + _fib_font_ascent; + const int pllx0 = FAREAMRGB + (PLACESW - TEXTSEP) * .75; + const int pllx1 = FAREAMRGB + (PLACESW - TEXTSEP - TEXTSEP); + + XSetForeground (dpy, _fib_gc, blackColor); + XSetLineAttributes (dpy, _fib_gc, 1, LineOnOffDash, CapButt, JoinMiter); + XDrawLine (dpy, win, _fib_gc, pllx0, plly, pllx1, plly); + XSetLineAttributes (dpy, _fib_gc, 1, LineSolid, CapButt, JoinMiter); + } + } + + // Bottom Buttons + const int numb = sizeof(_btns) / sizeof(FibButton*); + int xtra = _fib_width - _btn_span; + const int cbox = _fib_font_ascent - 2; + const int bbase = _fib_height - BTNBTMMARGIN * _fib_font_vsep - BTNPADDING; + const int cblw = cbox > 20 ? 5 : ( cbox > 9 ? 3 : 1); + + int bx = FAREAMRGB; + for (i = 0; i < numb; ++i) { + if (_btns[i]->flags & 8) { continue; } + if (_btns[i]->flags & 4) { + // checkbutton + const int cby0 = bbase - cbox + 1 + BTNPADDING; + if (i == _hov_b) { + XSetForeground (dpy, _fib_gc, _c_gray4.pixel); + } else { + XSetForeground (dpy, _fib_gc, blackColor); + } + XDrawRectangle (dpy, win, _fib_gc, + bx, cby0 - 1, cbox + 1, cbox + 1); + + if (i == _hov_b) { + XSetForeground (dpy, _fib_gc, _c_gray5.pixel); + } else { + XSetForeground (dpy, _fib_gc, blackColor); + } + XDrawString (dpy, win, _fib_gc, BTNPADDING + bx + _fib_font_ascent, 1 + bbase + BTNPADDING, + _btns[i]->text, strlen (_btns[i]->text)); + + if (i == _hov_b) { + XSetForeground (dpy, _fib_gc, _c_gray0.pixel); + } else { + if (_btns[i]->flags & 2) { + XSetForeground (dpy, _fib_gc, _c_gray1.pixel); + } else { + XSetForeground (dpy, _fib_gc, _c_gray2.pixel); + } + } + XFillRectangle (dpy, win, _fib_gc, + bx+1, cby0, cbox, cbox); + + if (_btns[i]->flags & 2) { + XSetLineAttributes (dpy, _fib_gc, cblw, LineSolid, CapRound, JoinMiter); + XSetForeground (dpy, _fib_gc, _c_gray6.pixel); + XDrawLine (dpy, win, _fib_gc, + bx + 2, cby0 + 1, + bx + cbox - 1, cby0 + cbox - 2); + XDrawLine (dpy, win, _fib_gc, + bx + cbox - 1, cby0 + 1, + bx + 2, cby0 + cbox - 2); + XSetLineAttributes (dpy, _fib_gc, 1, LineSolid, CapButt, JoinMiter); + } + } else { + if (xtra > 0) { + bx += xtra; + xtra = 0; + } + // pushbutton + + uint8_t can_hover = 1; // special case + if (_btns[i] == &_btn_ok) { + if (_fsel < 0 || _fsel >= _dircount) { + can_hover = 0; + } + } + + if (can_hover && i == _hov_b) { + XSetForeground (dpy, _fib_gc, _c_gray0.pixel); + } else { + XSetForeground (dpy, _fib_gc, _c_gray2.pixel); + } + XFillRectangle (dpy, win, _fib_gc, + bx + 1, bbase - _fib_font_ascent, + _btn_w - 1, _fib_font_height + BTNPADDING + BTNPADDING); + VDrawRectangle (dpy, win, _fib_gc, + bx, bbase - _fib_font_ascent, + _btn_w, _fib_font_height + BTNPADDING + BTNPADDING); + XDrawString (dpy, win, _fib_gc, bx + (_btn_w - _btns[i]->tw) * .5, 1 + bbase + BTNPADDING, + _btns[i]->text, strlen (_btns[i]->text)); + } + _btns[i]->x0 = bx; + bx += _btns[i]->xw + DSEP; + } + + if (_pixbuffer != None) { + XCopyArea(dpy, _pixbuffer, realwin, _fib_gc, 0, 0, _fib_width, _fib_height, 0, 0); + } + XFlush (dpy); +} + +static void fib_reset () { + _hov_p = _hov_f = _hov_h = _hov_l = -1; + _scrl_f = 0; + _fib_resized = 1; +} + +static int cmp_n_up (const void *p1, const void *p2) { + FibFileEntry *a = (FibFileEntry*) p1; + FibFileEntry *b = (FibFileEntry*) p2; + if ((a->flags & 4) && !(b->flags & 4)) return -1; + if (!(a->flags & 4) && (b->flags & 4)) return 1; + return strcmp (a->name, b->name); +} + +static int cmp_n_down (const void *p1, const void *p2) { + FibFileEntry *a = (FibFileEntry*) p1; + FibFileEntry *b = (FibFileEntry*) p2; + if ((a->flags & 4) && !(b->flags & 4)) return -1; + if (!(a->flags & 4) && (b->flags & 4)) return 1; + return strcmp (b->name, a->name); +} + +static int cmp_t_up (const void *p1, const void *p2) { + FibFileEntry *a = (FibFileEntry*) p1; + FibFileEntry *b = (FibFileEntry*) p2; + if ((a->flags & 4) && !(b->flags & 4)) return -1; + if (!(a->flags & 4) && (b->flags & 4)) return 1; + if (a->mtime == b->mtime) return 0; + return a->mtime > b->mtime ? -1 : 1; +} + +static int cmp_t_down (const void *p1, const void *p2) { + FibFileEntry *a = (FibFileEntry*) p1; + FibFileEntry *b = (FibFileEntry*) p2; + if ((a->flags & 4) && !(b->flags & 4)) return -1; + if (!(a->flags & 4) && (b->flags & 4)) return 1; + if (a->mtime == b->mtime) return 0; + return a->mtime > b->mtime ? 1 : -1; +} + +static int cmp_s_up (const void *p1, const void *p2) { + FibFileEntry *a = (FibFileEntry*) p1; + FibFileEntry *b = (FibFileEntry*) p2; + if ((a->flags & 4) && (b->flags & 4)) return 0; // dir, no size, retain order + if ((a->flags & 4) && !(b->flags & 4)) return -1; + if (!(a->flags & 4) && (b->flags & 4)) return 1; + if (a->size == b->size) return 0; + return a->size > b->size ? -1 : 1; +} + +static int cmp_s_down (const void *p1, const void *p2) { + FibFileEntry *a = (FibFileEntry*) p1; + FibFileEntry *b = (FibFileEntry*) p2; + if ((a->flags & 4) && (b->flags & 4)) return 0; // dir, no size, retain order + if ((a->flags & 4) && !(b->flags & 4)) return -1; + if (!(a->flags & 4) && (b->flags & 4)) return 1; + if (a->size == b->size) return 0; + return a->size > b->size ? 1 : -1; +} + +static void fmt_size (Display *dpy, FibFileEntry *f) { + if (f->size > 10995116277760) { + sprintf (f->strsize, "%.0f TB", f->size / 1099511627776.f); + } + if (f->size > 1099511627776) { + sprintf (f->strsize, "%.1f TB", f->size / 1099511627776.f); + } + else if (f->size > 10737418240) { + sprintf (f->strsize, "%.0f GB", f->size / 1073741824.f); + } + else if (f->size > 1073741824) { + sprintf (f->strsize, "%.1f GB", f->size / 1073741824.f); + } + else if (f->size > 10485760) { + sprintf (f->strsize, "%.0f MB", f->size / 1048576.f); + } + else if (f->size > 1048576) { + sprintf (f->strsize, "%.1f MB", f->size / 1048576.f); + } + else if (f->size > 10240) { + sprintf (f->strsize, "%.0f KB", f->size / 1024.f); + } + else if (f->size >= 1000) { + sprintf (f->strsize, "%.1f KB", f->size / 1024.f); + } + else { + sprintf (f->strsize, "%.0f B", f->size / 1.f); + } + int sw = 0; + query_font_geometry (dpy, _fib_gc, f->strsize, &sw, NULL, NULL, NULL); + if (sw > _fib_font_size_width) { + _fib_font_size_width = sw; + } + f->ssizew = sw; +} + +static void fmt_time (Display *dpy, FibFileEntry *f) { + struct tm *tmp; + tmp = localtime (&f->mtime); + if (!tmp) { + return; + } + strftime (f->strtime, sizeof(f->strtime), "%F %H:%M", tmp); + + int tw = 0; + query_font_geometry (dpy, _fib_gc, f->strtime, &tw, NULL, NULL, NULL); + if (tw > _fib_font_time_width) { + _fib_font_time_width = tw; + } +} + +static void fib_resort (const char * sel) { + if (_dircount < 1) { return; } + int (*sortfn)(const void *p1, const void *p2); + switch (_sort) { + case 1: sortfn = &cmp_n_down; break; + case 2: sortfn = &cmp_s_down; break; + case 3: sortfn = &cmp_s_up; break; + case 4: sortfn = &cmp_t_down; break; + case 5: sortfn = &cmp_t_up; break; + default: + sortfn = &cmp_n_up; + break; + } + qsort (_dirlist, _dircount, sizeof(_dirlist[0]), sortfn); + int i; + for (i = 0; i < _dircount && sel; ++i) { + if (!strcmp (_dirlist[i].name, sel)) { + _fsel = i; + break; + } + } +} + +static void fib_select (Display *dpy, int item) { + if (_fsel >= 0) { + _dirlist[_fsel].flags &= ~2; + } + _fsel = item; + if (_fsel >= 0 && _fsel < _dircount) { + _dirlist[_fsel].flags |= 2; + const int llen = (_fib_height - LISTBOT * _fib_font_vsep) / _fib_font_vsep; + if (_fsel < _scrl_f) { + _scrl_f = _fsel; + } + else if (_fsel >= _scrl_f + llen) { + _scrl_f = 1 + _fsel - llen; + } + } else { + _fsel = -1; + } + + fib_expose (dpy, _fib_win); +} + +static inline int fib_filter (const char *name) { + if (_fib_filter_function) { + return _fib_filter_function (name); + } else { + return 1; + } +} + +static void fib_pre_opendir (Display *dpy) { + if (_dirlist) free (_dirlist); + if (_pathbtn) free (_pathbtn); + _dirlist = NULL; + _pathbtn = NULL; + _dircount = 0; + _pathparts = 0; + query_font_geometry (dpy, _fib_gc, "Size ", &_fib_font_size_width, NULL, NULL, NULL); + fib_reset (); + _fsel = -1; +} + +static void fib_post_opendir (Display *dpy, const char *sel) { + if (_dircount > 0) + _fsel = 0; // select first + else + _fsel = -1; + fib_resort (sel); + + if (_dircount > 0 && _fsel >= 0) { + fib_select (dpy, _fsel); + } else { + fib_expose (dpy, _fib_win); + } +} + +static int fib_dirlistadd (Display *dpy, const int i, const char* path, const char *name, time_t mtime) { + char tp[1024]; + struct stat fs; + if (!_fib_hidden_fn && name[0] == '.') return -1; + if (!strcmp (name, ".")) return -1; + if (!strcmp (name, "..")) return -1; + strcpy (tp, path); + strcat (tp, name); + if (access (tp, R_OK)) { + return -1; + } + if (stat (tp, &fs)) { + return -1; + } + assert (i < _dircount); // could happen if dir changes while we're reading. + if (i >= _dircount) return -1; + if (S_ISDIR (fs.st_mode)) { + _dirlist[i].flags |= 4; + } + else if (S_ISREG (fs.st_mode)) { + if (!fib_filter (name)) return -1; + } +#if 0 // only needed with lstat() + else if (S_ISLNK (fs.st_mode)) { + if (!fib_filter (name)) return -1; + } +#endif + else { + return -1; + } + strcpy (_dirlist[i].name, name); + _dirlist[i].mtime = mtime > 0 ? mtime : fs.st_mtime; + _dirlist[i].size = fs.st_size; + if (!(_dirlist[i].flags & 4)) + fmt_size (dpy, &_dirlist[i]); + fmt_time (dpy, &_dirlist[i]); + return 0; +} + +static int fib_openrecent (Display *dpy, const char *sel) { + int i; + unsigned int j; + assert (_recentcnt > 0); + fib_pre_opendir (dpy); + query_font_geometry (dpy, _fib_gc, "Last Used", &_fib_font_time_width, NULL, NULL, NULL); + _dirlist = (FibFileEntry*) calloc (_recentcnt, sizeof(FibFileEntry)); + _dircount = _recentcnt; + for (j = 0, i = 0; j < _recentcnt; ++j) { + char base[1024]; + char *s = strrchr (_recentlist[j].path, '/'); + if (!s || !*++s) continue; + size_t len = (s - _recentlist[j].path); + strncpy (base, _recentlist[j].path, len); + base[len] = '\0'; + if (!fib_dirlistadd (dpy, i, base, s, _recentlist[j].atime)) { + _dirlist[i].rfp = &_recentlist[j]; + _dirlist[i].flags |= 8; + ++i; + } + } + _dircount = i; + fib_post_opendir (dpy, sel); + return _dircount; +} + +static int fib_opendir (Display *dpy, const char* path, const char *sel) { + char *t0, *t1; + int i; + + assert (path); + + if (strlen (path) == 0 && _recentcnt > 0) { // XXX we should use a better indication for this + strcpy (_cur_path, ""); + return fib_openrecent (dpy, sel); + } + + assert (strlen (path) < sizeof(_cur_path) -1); + assert (strlen (path) > 0); + assert (strstr (path, "//") == NULL); + assert (path[0] == '/'); + + fib_pre_opendir (dpy); + + query_font_geometry (dpy, _fib_gc, "Last Modified", &_fib_font_time_width, NULL, NULL, NULL); + DIR *dir = opendir (path); + if (!dir) { + strcpy (_cur_path, "/"); + } else { + int i; + struct dirent *de; + if (path != _cur_path) + strcpy (_cur_path, path); + + if (_cur_path[strlen (_cur_path) -1] != '/') + strcat (_cur_path, "/"); + + while ((de = readdir (dir))) { + if (!_fib_hidden_fn && de->d_name[0] == '.') continue; + ++_dircount; + } + + if (_dircount > 0) + _dirlist = (FibFileEntry*) calloc (_dircount, sizeof(FibFileEntry)); + + rewinddir (dir); + + i = 0; + while ((de = readdir (dir))) { + if (!fib_dirlistadd (dpy, i, _cur_path, de->d_name, 0)) + ++i; + } + _dircount = i; + closedir (dir); + } + + t0 = _cur_path; + while (*t0 && (t0 = strchr (t0, '/'))) { + ++_pathparts; + ++t0; + } + assert (_pathparts > 0); + _pathbtn = (FibPathButton*) calloc (_pathparts + 1, sizeof(FibPathButton)); + + t1 = _cur_path; + i = 0; + while (*t1 && (t0 = strchr (t1, '/'))) { + if (i == 0) { + strcpy (_pathbtn[i].name, "/"); + } else { + *t0 = 0; + strcpy (_pathbtn[i].name, t1); + } + query_font_geometry (dpy, _fib_gc, _pathbtn[i].name, &_pathbtn[i].xw, NULL, NULL, NULL); + _pathbtn[i].xw += BTNPADDING + BTNPADDING; + *t0 = '/'; + t1 = t0 + 1; + ++i; + } + fib_post_opendir (dpy, sel); + return _dircount; +} + +static int fib_open (Display *dpy, int item) { + char tp[1024]; + if (_dirlist[item].flags & 8) { + assert (_dirlist[item].rfp); + strcpy (_rv_open, _dirlist[item].rfp->path); + _status = 1; + return 0; + } + strcpy (tp, _cur_path); + strcat (tp, _dirlist[item].name); + if (_dirlist[item].flags & 4) { + fib_opendir (dpy, tp, NULL); + return 0; + } else { + _status = 1; + strcpy (_rv_open, tp); + } + return 0; +} + +static void cb_cancel (Display *dpy) { + _status = -1; +} + +static void cb_open (Display *dpy) { + if (_fsel >= 0 && _fsel < _dircount) { + fib_open (dpy, _fsel); + } +} + +static void sync_button_states () { + if (_fib_show_places) + _btn_places.flags |= 2; + else + _btn_places.flags &= ~2; + if (_fib_filter_fn) // inverse -> show all + _btn_filter.flags &= ~2; + else + _btn_filter.flags |= 2; + if (_fib_hidden_fn) + _btn_hidden.flags |= 2; + else + _btn_hidden.flags &= ~2; +} + +static void cb_places (Display *dpy) { + _fib_show_places = ! _fib_show_places; + if (_placecnt < 1) + _fib_show_places = 0; + sync_button_states (); + _fib_resized = 1; + fib_expose (dpy, _fib_win); +} + +static void cb_filter (Display *dpy) { + _fib_filter_fn = ! _fib_filter_fn; + sync_button_states (); + char *sel = _fsel >= 0 ? strdup (_dirlist[_fsel].name) : NULL; + fib_opendir (dpy, _cur_path, sel); + free (sel); +} + +static void cb_hidden (Display *dpy) { + _fib_hidden_fn = ! _fib_hidden_fn; + sync_button_states (); + char *sel = _fsel >= 0 ? strdup (_dirlist[_fsel].name) : NULL; + fib_opendir (dpy, _cur_path, sel); + free (sel); +} + +static int fib_widget_at_pos (Display *dpy, int x, int y, int *it) { + const int btop = _fib_height - BTNBTMMARGIN * _fib_font_vsep - _fib_font_ascent - BTNPADDING; + const int bbot = btop + _fib_font_height + BTNPADDING + BTNPADDING; + const int llen = (_fib_height - LISTBOT * _fib_font_vsep) / _fib_font_vsep; + const int ltop = LISTTOP * _fib_font_vsep; + const int fbot = ltop + 4 + llen * _fib_font_vsep; + const int ptop = PATHBTNTOP - _fib_font_ascent; + assert (it); + + // paths at top + if (y > ptop && y < ptop + _fib_font_height && _view_p >= 0 && _pathparts > 0) { + int i = _view_p; + *it = -1; + if (i > 0) { // special case '<' + if (x > FAREAMRGB && x <= FAREAMRGB + _pathbtn[0].xw) { + *it = _view_p - 1; + i = _pathparts; + } + } + while (i < _pathparts) { + if (x >= _pathbtn[i].x0 && x <= _pathbtn[i].x0 + _pathbtn[i].xw) { + *it = i; + break; + } + ++i; + } + assert (*it < _pathparts); + if (*it >= 0) return 1; + else return 0; + } + + // buttons at bottom + if (y > btop && y < bbot) { + size_t i; + *it = -1; + for (i = 0; i < sizeof(_btns) / sizeof(FibButton*); ++i) { + const int bx = _btns[i]->x0; + if (_btns[i]->flags & 8) { continue; } + if (x > bx && x < bx + _btns[i]->xw) { + *it = i; + } + } + if (*it >= 0) return 3; + else return 0; + } + + // main file area + if (y >= ltop - _fib_font_vsep && y < fbot && x > FAREAMRGL && x < _fib_width - FAREAMRGR) { + // scrollbar + if (_scrl_y0 > 0 && x >= _fib_width - (FAREAMRGR + SCROLLBARW) && x <= _fib_width - FAREAMRGR) { + if (y >= _scrl_y0 && y < _scrl_y1) { + *it = 0; + } else if (y >= _scrl_y1) { + *it = 2; + } else { + *it = 1; + } + return 4; + } + // file-list + else if (y >= ltop) { + const int item = (y - ltop) / _fib_font_vsep + _scrl_f; + *it = -1; + if (item >= 0 && item < _dircount) { + *it = item; + } + if (*it >= 0) return 2; + else return 0; + } + else { + *it = -1; + const int fsel_width = _fib_width - FAREAMRGL - FAREAMRGR - (llen < _dircount ? SCROLLBARW : 0); + const int t_s = FAREAMRGL + fsel_width - _fib_font_time_width - TEXTSEP - TEXTSEP; + const int t_t = FAREAMRGL + fsel_width - TEXTSEP - _fib_font_size_width - ((_columns & 2) ? ( _fib_font_time_width + TEXTSEP + TEXTSEP) : 0); + if (x >= fsel_width + FAREAMRGL) ; + else if ((_columns & 2) && x >= t_s) *it = 3; + else if ((_columns & 1) && x >= t_t) *it = 2; + else if (x >= FAREATEXTL + _fib_dir_indent - TEXTSEP) *it = 1; + if (*it >= 0) return 5; + else return 0; + } + } + + // places list + if (_fib_show_places && y >= ltop && y < fbot && x > FAREAMRGB && x < FAREAMRGL - FAREAMRGB) { + const int item = (y - ltop) / _fib_font_vsep; + *it = -1; + if (item >= 0 && item < _placecnt) { + *it = item; + } + if (*it >= 0) return 6; + else return 0; + } + + return 0; +} + +static void fib_update_hover (Display *dpy, int need_expose, const int type, const int item) { + int hov_p = -1; + int hov_b = -1; + int hov_h = -1; + int hov_s = -1; +#ifdef LIST_ENTRY_HOVER + int hov_f = -1; + int hov_l = -1; +#endif + + switch (type) { + case 1: hov_p = item; break; + case 3: hov_b = item; break; + case 4: hov_s = item; break; + case 5: hov_h = item; break; +#ifdef LIST_ENTRY_HOVER + case 6: hov_l = item; break; + case 2: hov_f = item; break; +#endif + default: break; + } +#ifdef LIST_ENTRY_HOVER + if (hov_f != _hov_f) { _hov_f = hov_f; need_expose = 1; } + if (hov_l != _hov_l) { _hov_l = hov_l; need_expose = 1; } +#endif + if (hov_b != _hov_b) { _hov_b = hov_b; need_expose = 1; } + if (hov_p != _hov_p) { _hov_p = hov_p; need_expose = 1; } + if (hov_h != _hov_h) { _hov_h = hov_h; need_expose = 1; } + if (hov_s != _hov_s) { _hov_s = hov_s; need_expose = 1; } + + if (need_expose) { + fib_expose (dpy, _fib_win); + } +} + +static void fib_motion (Display *dpy, int x, int y) { + int it = -1; + + if (_scrl_my >= 0) { + const int sdiff = y - _scrl_my; + const int llen = (_fib_height - LISTBOT * _fib_font_vsep) / _fib_font_vsep; + const int fsel_height = 4 + llen * _fib_font_vsep; + const float sl = (fsel_height + _fib_font_vsep - (SCROLLBOXH + SCROLLBOXH)) / (float) _dircount; + + int news = _scrl_mf + sdiff / sl; + if (news < 0) news = 0; + if (news >= (_dircount - llen)) news = _dircount - llen; + if (news != _scrl_f) { + _scrl_f = news; + fib_expose (dpy, _fib_win); + } + return; + } + + const int type = fib_widget_at_pos (dpy, x, y, &it); + fib_update_hover (dpy, 0, type, it); +} + +static void fib_mousedown (Display *dpy, int x, int y, int btn, unsigned long time) { + int it; + switch (fib_widget_at_pos (dpy, x, y, &it)) { + case 4: // scrollbar + if (btn == 1) { + _dblclk = 0; + if (it == 0) { + _scrl_my = y; + _scrl_mf = _scrl_f; + } else { + int llen = (_fib_height - LISTBOT * _fib_font_vsep) / _fib_font_vsep; + if (llen < 2) llen = 2; + int news = _scrl_f; + if (it == 1) { + news -= llen - 1; + } else { + news += llen - 1; + } + if (news < 0) news = 0; + if (news >= (_dircount - llen)) news = _dircount - llen; + if (news != _scrl_f && _scrl_y0 >= 0) { + assert (news >=0); + _scrl_f = news; + fib_update_hover (dpy, 1, 4, it); + } + } + } + break; + case 2: // file-list + if (btn == 4 || btn == 5) { + const int llen = (_fib_height - LISTBOT * _fib_font_vsep) / _fib_font_vsep; + int news = _scrl_f + ((btn == 4) ? - 1 : 1); + if (news < 0) news = 0; + if (news >= (_dircount - llen)) news = _dircount - llen; + if (news != _scrl_f && _scrl_y0 >= 0) { + assert (news >=0); + _scrl_f = news; + fib_update_hover (dpy, 1, 0, 0); + } + _dblclk = 0; + } + else if (btn == 1 && it >= 0 && it < _dircount) { + if (_fsel == it) { + if (time - _dblclk < DBLCLKTME) { + fib_open (dpy, it); + _dblclk = 0; + } + _dblclk = time; + } else { + fib_select (dpy, it); + _dblclk = time; + } + if (_fsel >= 0) { + if (!(_dirlist[_fsel].flags & 4)) { + } + } + } + break; + case 1: // paths + assert (_fsel < _dircount); + assert (it >= 0 && it < _pathparts); + { + int i = 0; + char path[1024] = "/"; + while (++i <= it) { + strcat (path, _pathbtn[i].name); + strcat (path, "/"); + } + char *sel = NULL; + if (i < _pathparts) + sel = strdup (_pathbtn[i].name); + else if (i == _pathparts && _fsel >= 0) + sel = strdup (_dirlist[_fsel].name); + fib_opendir (dpy, path, sel); + free (sel); + } + break; + case 3: // btn + if (btn == 1 && _btns[it]->callback) { + _btns[it]->callback (dpy); + } + break; + case 5: // sort + if (btn == 1) { + switch (it) { + case 1: if (_sort == 0) _sort = 1; else _sort = 0; break; + case 2: if (_sort == 2) _sort = 3; else _sort = 2; break; + case 3: if (_sort == 4) _sort = 5; else _sort = 4; break; + } + if (_fsel >= 0) { + assert (_dirlist && _dircount >= _fsel); + _dirlist[_fsel].flags &= ~2; + char *sel = strdup (_dirlist[_fsel].name); + fib_resort (sel); + free (sel); + } else { + fib_resort (NULL); + _fsel = -1; + } + fib_reset (); + _hov_h = it; + fib_select (dpy, _fsel); + } + break; + case 6: + if (btn == 1 && it >= 0 && it < _placecnt) { + fib_opendir (dpy, _placelist[it].path, NULL); + } + break; + default: + break; + } +} + +static void fib_mouseup (Display *dpy, int x, int y, int btn, unsigned long time) { + _scrl_my = -1; +} + +static void add_place_raw (Display *dpy, const char *name, const char *path) { + _placelist = (FibPlace*) realloc (_placelist, (_placecnt + 1) * sizeof(FibPlace)); + strcpy (_placelist[_placecnt].path, path); + strcpy (_placelist[_placecnt].name, name); + _placelist[_placecnt].flags = 0; + + int sw; + query_font_geometry (dpy, _fib_gc, name, &sw, NULL, NULL, NULL); + if (sw > _fib_place_width) { + _fib_place_width = sw; + } + ++_placecnt; +} + +static int add_place_places (Display *dpy, const char *name, const char *url) { + char const * path; + struct stat fs; + int i; + if (!url || strlen (url) < 1) return -1; + if (!name || strlen (name) < 1) return -1; + if (url[0] == '/') { + path = url; + } + else if (!strncmp (url, "file:///", 8)) { + path = &url[7]; + } + else { + return -1; + } + + if (access (path, R_OK)) { + return -1; + } + if (stat (path, &fs)) { + return -1; + } + if (!S_ISDIR (fs.st_mode)) { + return -1; + } + + for (i = 0; i < _placecnt; ++i) { + if (!strcmp (path, _placelist[i].path)) { + return -1; + } + } + add_place_raw (dpy, name, path); + return 0; +} + +static int parse_gtk_bookmarks (Display *dpy, const char *fn) { + char tmp[1024]; + if (access (fn, R_OK)) { + return -1; + } + FILE *bm = fopen (fn, "r"); + if (!bm) return -1; + int found = 0; + while (fgets (tmp, sizeof(tmp), bm) + && strlen (tmp) > 1 + && strlen (tmp) < sizeof(tmp)) + { + char *s, *n; + tmp[strlen (tmp) - 1] = '\0'; // strip newline + if ((s = strchr (tmp, ' '))) { + *s = '\0'; + n = strdup (++s); + decode_3986 (tmp); + if (!add_place_places (dpy, n, tmp)) { + ++found; + } + free (n); + } else if ((s = strrchr (tmp, '/'))) { + n = strdup (++s); + decode_3986 (tmp); + if (!add_place_places (dpy, n, tmp)) { + ++found; + } + free (n); + } + } + fclose (bm); + return found; +} + +static const char *ignore_mountpoints[] = { + "/bin", "/boot", "/dev", "/etc", + "/lib", "/live", "/mnt", "/opt", + "/root", "/sbin", "/srv", "/tmp", + "/usr", "/var", "/proc", "/sbin", + "/net", "/sys" +}; + +static const char *ignore_fs[] = { + "auto", "autofs", + "debugfs", "devfs", + "devpts", "ecryptfs", + "fusectl", "kernfs", + "linprocfs", "proc", + "ptyfs", "rootfs", + "selinuxfs", "sysfs", + "tmpfs", "usbfs", + "nfsd", "rpc_pipefs", +}; + +static const char *ignore_devices[] = { + "binfmt_", "devpts", + "gvfs", "none", + "nfsd", "sunrpc", + "/dev/loop", "/dev/vn" +}; + +static int check_mount (const char *mountpoint, const char *fs, const char *device) { + size_t i; + if (!mountpoint || !fs || !device) return -1; + //printf("%s %s %s\n", mountpoint, fs, device); + for (i = 0 ; i < sizeof(ignore_mountpoints) / sizeof(char*); ++i) { + if (!strncmp (mountpoint, ignore_mountpoints[i], strlen (ignore_mountpoints[i]))) { + return 1; + } + } + if (!strncmp (mountpoint, "/home", 5)) { + return 1; + } + for (i = 0 ; i < sizeof(ignore_fs) / sizeof(char*); ++i) { + if (!strncmp (fs, ignore_fs[i], strlen (ignore_fs[i]))) { + return 1; + } + } + for (i = 0 ; i < sizeof(ignore_devices) / sizeof(char*); ++i) { + if (!strncmp (device, ignore_devices[i], strlen (ignore_devices[i]))) { + return 1; + } + } + return 0; +} + +static int read_mtab (Display *dpy, const char *mtab) { + FILE *mt = fopen (mtab, "r"); + if (!mt) return -1; + int found = 0; + struct mntent *mntent; + while ((mntent = getmntent (mt)) != NULL) { + char *s; + if (check_mount (mntent->mnt_dir, mntent->mnt_type, mntent->mnt_fsname)) + continue; + + if ((s = strrchr (mntent->mnt_dir, '/'))) { + ++s; + } else { + s = mntent->mnt_dir; + } + if (!add_place_places (dpy, s, mntent->mnt_dir)) { + ++found; + } + } + fclose (mt); + return found; +} + +static void populate_places (Display *dpy) { + char tmp[1024]; + int spacer = -1; + if (_placecnt > 0) return; + _fib_place_width = 0; + + if (_recentcnt > 0) { + add_place_raw (dpy, "Recently Used", ""); + _placelist[0].flags |= 4; + } + + add_place_places (dpy, "Home", getenv ("HOME")); + + if (getenv ("HOME")) { + strcpy (tmp, getenv ("HOME")); + strcat (tmp, "/Desktop"); + add_place_places (dpy, "Desktop", tmp); + } + + add_place_places (dpy, "Filesystem", "/"); + + if (_placecnt > 0) spacer = _placecnt -1; + + if (strlen (_fib_cfg_custom_places) > 0) { + parse_gtk_bookmarks (dpy, _fib_cfg_custom_places); + } + + if (read_mtab (dpy, "/proc/mounts") < 1) { + read_mtab (dpy, "/etc/mtab"); + } + + int parsed_bookmarks = 0; + if (!parsed_bookmarks && getenv ("HOME")) { + strcpy (tmp, getenv ("HOME")); + strcat (tmp, "/.gtk-bookmarks"); + if (parse_gtk_bookmarks (dpy, tmp) > 0) { + parsed_bookmarks = 1; + } + } + if (!parsed_bookmarks && getenv ("XDG_CONFIG_HOME")) { + strcpy (tmp, getenv ("XDG_CONFIG_HOME")); + strcat (tmp, "/gtk-3.0/bookmarks"); + if (parse_gtk_bookmarks (dpy, tmp) > 0) { + parsed_bookmarks = 1; + } + } + if (!parsed_bookmarks && getenv ("HOME")) { + strcpy (tmp, getenv ("HOME")); + strcat (tmp, "/.config/gtk-3.0/bookmarks"); + if (parse_gtk_bookmarks (dpy, tmp) > 0) { + parsed_bookmarks = 1; + } + } + if (_fib_place_width > 0) { + _fib_place_width = MIN (_fib_place_width + TEXTSEP + _fib_dir_indent /*extra*/ , PLACESWMAX); + } + if (spacer > 0 && spacer < _placecnt -1) { + _placelist[ spacer ].flags |= 4; + } +} + +static uint8_t font_err = 0; +static int x_error_handler (Display *d, XErrorEvent *e) { + font_err = 1; + return 0; +} + +int x_fib_show (Display *dpy, Window parent, int x, int y) { + if (_fib_win) { + XSetInputFocus (dpy, _fib_win, RevertToParent, CurrentTime); + return -1; + } + + _status = 0; + _rv_open[0] = '\0'; + + Colormap colormap = DefaultColormap (dpy, DefaultScreen (dpy)); + _c_gray1.flags= DoRed | DoGreen | DoBlue; + _c_gray0.red = _c_gray0.green = _c_gray0.blue = 61710; // 95% hover prelight + _c_gray1.red = _c_gray1.green = _c_gray1.blue = 60416; // 93% window bg, scrollbar-fg + _c_gray2.red = _c_gray2.green = _c_gray2.blue = 54016; // 83% button & list bg + _c_gray3.red = _c_gray3.green = _c_gray3.blue = 48640; // 75% heading + scrollbar-bg + _c_gray4.red = _c_gray4.green = _c_gray4.blue = 26112; // 40% prelight text, sep lines + _c_gray5.red = _c_gray5.green = _c_gray5.blue = 12800; // 20% 3D border + _c_gray6.red = _c_gray6.green = _c_gray6.blue = 6400; // 10% checkbox cross, sort triangles + + if (!XAllocColor (dpy, colormap, &_c_gray0)) return -1; + if (!XAllocColor (dpy, colormap, &_c_gray1)) return -1; + if (!XAllocColor (dpy, colormap, &_c_gray2)) return -1; + if (!XAllocColor (dpy, colormap, &_c_gray3)) return -1; + if (!XAllocColor (dpy, colormap, &_c_gray4)) return -1; + if (!XAllocColor (dpy, colormap, &_c_gray5)) return -1; + if (!XAllocColor (dpy, colormap, &_c_gray6)) return -1; + + XSetWindowAttributes attr; + memset (&attr, 0, sizeof(XSetWindowAttributes)); + attr.border_pixel = _c_gray2.pixel; + + attr.event_mask = ExposureMask | KeyPressMask + | ButtonPressMask | ButtonReleaseMask + | ConfigureNotify | StructureNotifyMask + | PointerMotionMask | LeaveWindowMask; + + _fib_win = XCreateWindow ( + dpy, DefaultRootWindow (dpy), + x, y, _fib_width, _fib_height, + 1, CopyFromParent, InputOutput, CopyFromParent, + CWEventMask | CWBorderPixel, &attr); + + if (!_fib_win) { return 1; } + + if (parent) + XSetTransientForHint (dpy, _fib_win, parent); + + XStoreName (dpy, _fib_win, "Select File"); + + Atom wmDelete = XInternAtom (dpy, "WM_DELETE_WINDOW", True); + XSetWMProtocols (dpy, _fib_win, &wmDelete, 1); + + _fib_gc = XCreateGC (dpy, _fib_win, 0, NULL); + XSetLineAttributes (dpy, _fib_gc, 1, LineSolid, CapButt, JoinMiter); + const char dl[1] = {1}; + XSetDashes (dpy, _fib_gc, 0, dl, 1); + + int (*handler)(Display *, XErrorEvent *) = XSetErrorHandler (&x_error_handler); + +#define _XTESTFONT(FN) \ + { \ + font_err = 0; \ + _fibfont = XLoadFont (dpy, FN); \ + XSetFont (dpy, _fib_gc, _fibfont); \ + XSync (dpy, False); \ + } + + font_err = 1; + if (getenv ("XJFONT")) _XTESTFONT (getenv ("XJFONT")); + if (font_err && strlen (_fib_cfg_custom_font) > 0) _XTESTFONT (_fib_cfg_custom_font); + if (font_err) _XTESTFONT ("-*-helvetica-medium-r-normal-*-24-*-*-*-*-*-*-*"); + if (font_err) _XTESTFONT ("-*-verdana-medium-r-normal-*-24-*-*-*-*-*-*-*"); + if (font_err) _XTESTFONT ("-misc-fixed-medium-r-normal-*-24-*-*-*-*-*-*-*"); + if (font_err) _XTESTFONT ("-misc-fixed-medium-r-normal-*-20-*-*-*-*-*-*-*"); + if (font_err) _fibfont = None; + XSync (dpy, False); + XSetErrorHandler (handler); + + if (_fib_font_height == 0) { // 1st time only + query_font_geometry (dpy, _fib_gc, "D ", &_fib_dir_indent, NULL, NULL, NULL); + query_font_geometry (dpy, _fib_gc, "_", &_fib_spc_norm, NULL, NULL, NULL); + if (query_font_geometry (dpy, _fib_gc, "|0Yy", NULL, &_fib_font_height, &_fib_font_ascent, NULL)) { + XFreeGC (dpy, _fib_gc); + XDestroyWindow (dpy, _fib_win); + _fib_win = 0; + return -1; + } + _fib_font_height += 3; + _fib_font_ascent += 2; + _fib_font_vsep = _fib_font_height + 2; + } + + populate_places (dpy); + + strcpy (_btn_ok.text, "Open"); + strcpy (_btn_cancel.text, "Cancel"); + strcpy (_btn_filter.text, "List All Files"); + strcpy (_btn_places.text, "Show Places"); + strcpy (_btn_hidden.text, "Show Hidden"); + + _btn_ok.callback = &cb_open; + _btn_cancel.callback = &cb_cancel; + _btn_filter.callback = &cb_filter; + _btn_places.callback = &cb_places; + _btn_hidden.callback = &cb_hidden; + _btn_filter.flags |= 4; + _btn_places.flags |= 4; + _btn_hidden.flags |= 4; + + if (!_fib_filter_function) { + _btn_filter.flags |= 8; + } + + size_t i; + int btncnt = 0; + _btn_w = 0; + _btn_span = 0; + for (i = 0; i < sizeof(_btns) / sizeof(FibButton*); ++i) { + if (_btns[i]->flags & 8) { continue; } + query_font_geometry (dpy, _fib_gc, _btns[i]->text, &_btns[i]->tw, NULL, NULL, NULL); + if (_btns[i]->flags & 4) { + _btn_span += _btns[i]->tw + _fib_font_ascent + TEXTSEP; + } else { + ++btncnt; + if (_btns[i]->tw > _btn_w) + _btn_w = _btns[i]->tw; + } + } + + _btn_w += BTNPADDING + BTNPADDING + TEXTSEP + TEXTSEP + TEXTSEP; + _btn_span += _btn_w * btncnt + DSEP * (i - 1) + FAREAMRGR + FAREAMRGB; + + for (i = 0; i < sizeof(_btns) / sizeof(FibButton*); ++i) { + if (_btns[i]->flags & 8) { continue; } + if (_btns[i]->flags & 4) { + _btns[i]->xw = _btns[i]->tw + _fib_font_ascent + TEXTSEP; + } else { + _btns[i]->xw = _btn_w; + } + } + + sync_button_states () ; + + _fib_height = _fib_font_vsep * (15.8); + _fib_width = MAX (_btn_span, 440); + + XResizeWindow (dpy, _fib_win, _fib_width, _fib_height); + + XTextProperty x_wname, x_iname; + XSizeHints hints; + XWMHints wmhints; + + hints.flags = PSize | PMinSize; + hints.min_width = _btn_span; + hints.min_height = 8 * _fib_font_vsep; + + char *w_name = & _fib_cfg_title[0]; + + wmhints.input = True; + wmhints.flags = InputHint; + if (XStringListToTextProperty (&w_name, 1, &x_wname) && + XStringListToTextProperty (&w_name, 1, &x_iname)) + { + XSetWMProperties (dpy, _fib_win, &x_wname, &x_iname, NULL, 0, &hints, &wmhints, NULL); + XFree (x_wname.value); + XFree (x_iname.value); + } + + XSetWindowBackground (dpy, _fib_win, _c_gray1.pixel); + + _fib_mapped = 0; + XMapRaised (dpy, _fib_win); + + if (!strlen (_cur_path) || !fib_opendir (dpy, _cur_path, NULL)) { + fib_opendir (dpy, getenv ("HOME") ? getenv ("HOME") : "/", NULL); + } + +#if 0 + XGrabPointer (dpy, _fib_win, True, + ButtonReleaseMask | ButtonPressMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask | StructureNotifyMask, + GrabModeAsync, GrabModeAsync, None, None, CurrentTime); + XGrabKeyboard (dpy, _fib_win, True, GrabModeAsync, GrabModeAsync, CurrentTime); + //XSetInputFocus (dpy, parent, RevertToNone, CurrentTime); +#endif + _recentlock = 1; + return 0; +} + +void x_fib_close (Display *dpy) { + if (!_fib_win) return; + XFreeGC (dpy, _fib_gc); + XDestroyWindow (dpy, _fib_win); + _fib_win = 0; + free (_dirlist); + _dirlist = NULL; + free (_pathbtn); + _pathbtn = NULL; + if (_fibfont != None) XUnloadFont (dpy, _fibfont); + _fibfont = None; + free (_placelist); + _placelist = NULL; + _dircount = 0; + _pathparts = 0; + _placecnt = 0; + if (_pixbuffer != None) XFreePixmap (dpy, _pixbuffer); + _pixbuffer = None; + Colormap colormap = DefaultColormap (dpy, DefaultScreen (dpy)); + XFreeColors (dpy, colormap, &_c_gray0.pixel, 1, 0); + XFreeColors (dpy, colormap, &_c_gray1.pixel, 1, 0); + XFreeColors (dpy, colormap, &_c_gray2.pixel, 1, 0); + XFreeColors (dpy, colormap, &_c_gray3.pixel, 1, 0); + XFreeColors (dpy, colormap, &_c_gray4.pixel, 1, 0); + XFreeColors (dpy, colormap, &_c_gray5.pixel, 1, 0); + XFreeColors (dpy, colormap, &_c_gray6.pixel, 1, 0); + _recentlock = 0; +} + +int x_fib_handle_events (Display *dpy, XEvent *event) { + if (!_fib_win) return 0; + if (_status) return 0; + if (event->xany.window != _fib_win) { + return 0; + } + + switch (event->type) { + case MapNotify: + _fib_mapped = 1; + break; + case UnmapNotify: + _fib_mapped = 0; + break; + case LeaveNotify: + fib_update_hover (dpy, 1, 0, 0); + break; + case ClientMessage: + if (!strcmp (XGetAtomName (dpy, event->xclient.message_type), "WM_PROTOCOLS")) { + _status = -1; + } + break; + case ConfigureNotify: + if ( + (event->xconfigure.width > 1 && event->xconfigure.height > 1) + && + (event->xconfigure.width != _fib_width || event->xconfigure.height != _fib_height) + ) + { + _fib_width = event->xconfigure.width; + _fib_height = event->xconfigure.height; + _fib_resized = 1; + } + break; + case Expose: + if (event->xexpose.count == 0) { + fib_expose (dpy, event->xany.window); + } + break; + case MotionNotify: + fib_motion (dpy, event->xmotion.x, event->xmotion.y); + if (event->xmotion.is_hint == NotifyHint) { + XGetMotionEvents (dpy, event->xany.window, CurrentTime, CurrentTime, NULL); + } + break; + case ButtonPress: + fib_mousedown (dpy, event->xbutton.x, event->xbutton.y, event->xbutton.button, event->xbutton.time); + break; + case ButtonRelease: + fib_mouseup (dpy, event->xbutton.x, event->xbutton.y, event->xbutton.button, event->xbutton.time); + break; + case KeyRelease: + break; + case KeyPress: + { + KeySym key; + char buf[100]; + static XComposeStatus stat; + XLookupString (&event->xkey, buf, sizeof(buf), &key, &stat); + switch (key) { + case XK_Escape: + _status = -1; + break; + case XK_Up: + if (_fsel > 0) { + fib_select (dpy, _fsel - 1); + } + break; + case XK_Down: + if (_fsel < _dircount -1) { + fib_select ( dpy, _fsel + 1); + } + break; + case XK_Page_Up: + if (_fsel > 0) { + int llen = (_fib_height - LISTBOT * _fib_font_vsep) / _fib_font_vsep; + if (llen < 1) llen = 1; else --llen; + int fs = MAX (0, _fsel - llen); + fib_select ( dpy, fs); + } + break; + case XK_Page_Down: + if (_fsel < _dircount) { + int llen = (_fib_height - LISTBOT * _fib_font_vsep) / _fib_font_vsep; + if (llen < 1) llen = 1; else --llen; + int fs = MIN (_dircount - 1, _fsel + llen); + fib_select ( dpy, fs); + } + break; + case XK_Left: + if (_pathparts > 1) { + int i = 0; + char path[1024] = "/"; + while (++i < _pathparts - 1) { + strcat (path, _pathbtn[i].name); + strcat (path, "/"); + } + char *sel = strdup (_pathbtn[_pathparts-1].name); + fib_opendir (dpy, path, sel); + free (sel); + } + break; + case XK_Right: + if (_fsel >= 0 && _fsel < _dircount) { + if (_dirlist[_fsel].flags & 4) { + cb_open (dpy); + } + } + break; + case XK_Return: + cb_open (dpy); + break; + default: + if ((key >= XK_a && key <= XK_z) || (key >= XK_0 && key <= XK_9)) { + int i; + for (i = 0; i < _dircount; ++i) { + int j = (_fsel + i + 1) % _dircount; + char kcmp = _dirlist[j].name[0]; + if (kcmp > 0x40 && kcmp <= 0x5A) kcmp |= 0x20; + if (kcmp == (char)key) { + fib_select ( dpy, j); + break; + } + } + } + break; + } + } + break; + } + + if (_status) { + x_fib_close (dpy); + } + return _status; +} + +int x_fib_status () { + return _status; +} + +int x_fib_configure (int k, const char *v) { + if (_fib_win) { return -1; } + switch (k) { + case 0: + if (strlen (v) >= sizeof(_cur_path) -1) return -2; + if (strlen (v) < 1) return -2; + if (v[0] != '/') return -2; + if (strstr (v, "//")) return -2; + strncpy (_cur_path, v, sizeof(_cur_path)); + break; + case 1: + if (strlen (v) >= sizeof(_fib_cfg_title) -1) return -2; + strncpy (_fib_cfg_title, v, sizeof(_fib_cfg_title)); + break; + case 2: + if (strlen (v) >= sizeof(_fib_cfg_custom_font) -1) return -2; + strncpy (_fib_cfg_custom_font, v, sizeof(_fib_cfg_custom_font)); + break; + case 3: + if (strlen (v) >= sizeof(_fib_cfg_custom_places) -1) return -2; + strncpy (_fib_cfg_custom_places, v, sizeof(_fib_cfg_custom_places)); + break; + default: + return -2; + } + return 0; +} + +int x_fib_cfg_buttons (int k, int v) { + if (_fib_win) { return -1; } + switch (k) { + case 1: + if (v < 0) { + _btn_hidden.flags |= 8; + } else { + _btn_hidden.flags &= ~8; + } + if (v == 1) { + _btn_hidden.flags |= 2; + _fib_hidden_fn = 1; + } else if (v == 0) { + _btn_hidden.flags &= 2; + _fib_hidden_fn = 0; + } + break; + case 2: + if (v < 0) { + _btn_places.flags |= 8; + } else { + _btn_places.flags &= ~8; + } + if (v == 1) { + _btn_places.flags |= 2; + _fib_show_places = 1; + } else if (v == 0) { + _btn_places.flags &= ~2; + _fib_show_places = 0; + } + break; + case 3: + // NB. filter button is automatically hidden + // IFF the filter-function is NULL. + if (v < 0) { + _btn_filter.flags |= 8; + } else { + _btn_filter.flags &= ~8; + } + if (v == 1) { + _btn_filter.flags &= ~2; // inverse - 'show all' = !filter + _fib_filter_fn = 1; + } else if (v == 0) { + _btn_filter.flags |= 2; + _fib_filter_fn = 0; + } + break; + default: + return -2; + } + return 0; +} + +int x_fib_cfg_filter_callback (int (*cb)(const char*)) { + if (_fib_win) { return -1; } + _fib_filter_function = cb; + return 0; +} + +char *x_fib_filename () { + if (_status > 0 && !_fib_win) + return strdup (_rv_open); + else + return NULL; +} +#endif // HAVE_X11 + + +/* example usage */ +#ifdef SOFD_TEST + +static int fib_filter_movie_filename (const char *name) { + if (!_fib_filter_fn) return 1; + const int l3 = strlen (name) - 3; + const int l4 = l3 - 1; + const int l5 = l4 - 1; + const int l6 = l5 - 1; + const int l9 = l6 - 3; + if ( + (l4 > 0 && ( + !strcasecmp (&name[l4], ".avi") + || !strcasecmp (&name[l4], ".mov") + || !strcasecmp (&name[l4], ".ogg") + || !strcasecmp (&name[l4], ".ogv") + || !strcasecmp (&name[l4], ".mpg") + || !strcasecmp (&name[l4], ".mov") + || !strcasecmp (&name[l4], ".mp4") + || !strcasecmp (&name[l4], ".mkv") + || !strcasecmp (&name[l4], ".vob") + || !strcasecmp (&name[l4], ".asf") + || !strcasecmp (&name[l4], ".avs") + || !strcasecmp (&name[l4], ".dts") + || !strcasecmp (&name[l4], ".flv") + || !strcasecmp (&name[l4], ".m4v") + )) || + (l5 > 0 && ( + !strcasecmp (&name[l5], ".h264") + || !strcasecmp (&name[l5], ".webm") + )) || + (l6 > 0 && ( + !strcasecmp (&name[l6], ".dirac") + )) || + (l9 > 0 && ( + !strcasecmp (&name[l9], ".matroska") + )) || + (l3 > 0 && ( + !strcasecmp (&name[l3], ".dv") + || !strcasecmp (&name[l3], ".ts") + )) + ) + { + return 1; + } + return 0; +} + +int main (int argc, char **argv) { + Display* dpy = XOpenDisplay (0); + if (!dpy) return -1; + + x_fib_cfg_filter_callback (fib_filter_movie_filename); + x_fib_configure (1, "Open Movie File"); + x_fib_load_recent ("/tmp/sofd.recent"); + x_fib_show (dpy, 0, 300, 300); + + while (1) { + XEvent event; + while (XPending (dpy) > 0) { + XNextEvent (dpy, &event); + if (x_fib_handle_events (dpy, &event)) { + if (x_fib_status () > 0) { + char *fn = x_fib_filename (); + printf ("OPEN '%s'\n", fn); + x_fib_add_recent (fn, time (NULL)); + free (fn); + } + } + } + if (x_fib_status ()) { + break; + } + usleep (80000); + } + x_fib_close (dpy); + + x_fib_save_recent ("/tmp/sofd.recent"); + + x_fib_free_recent (); + XCloseDisplay (dpy); + return 0; +} +#endif diff --git a/contrib/libsofd.h b/contrib/libsofd.h new file mode 100644 index 0000000..2abf788 --- /dev/null +++ b/contrib/libsofd.h @@ -0,0 +1,194 @@ +/* libSOFD - Simple Open File Dialog [for X11 without toolkit] + * + * Copyright (C) 2014 Robin Gareus + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef LIBSOFD_H +#define LIBSOFD_H 1 + +#ifdef HAVE_X11 +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/////////////////////////////////////////////////////////////////////////////// +/* public API */ + +/** open a file select dialog + * @param dpy X Display connection + * @param parent (optional) if not NULL, become transient for given window + * @param x if >0 set explict initial width of the window + * @param y if >0 set explict initial height of the window + * @return 0 on success + */ +int x_fib_show (Display *dpy, Window parent, int x, int y); + +/** force close the dialog. + * This is normally not needed, the dialog closes itself + * when a file is selected or the user cancels selection. + * @param dpy X Display connection + */ +void x_fib_close (Display *dpy); + +/** non-blocking X11 event handler. + * It is safe to run this function even if the dialog is + * closed or was not initialized. + * + * @param dpy X Display connection + * @param event the XEvent to process + * @return status + * 0: the event was not for this window, or file-dialog still + * active, or the dialog window is not displayed. + * >0: file was selected, dialog closed + * <0: file selection was cancelled. + */ +int x_fib_handle_events (Display *dpy, XEvent *event); + +/** last status of the dialog + * @return >0: file was selected, <0: canceled or inactive. 0: active + */ +int x_fib_status (); + +/** query the selected filename + * @return NULL if none set, or allocated string to be free()ed by the called + */ +char *x_fib_filename (); + +/** customize/configure the dialog before calling \ref x_fib_show + * changes only have any effect if the dialog is not visible. + * @param k key to change + * 0: set current dir to display (must end with slash) + * 1: set title of dialog window + * 2: specify a custom X11 font to use + * 3: specify a custom 'places' file to include + * (following gtk-bookmark convention) + * @param v value + * @return 0 on success. + */ +int x_fib_configure (int k, const char *v); + +/** customize/configure the dialog before calling \ref x_fib_show + * changes only have any effect if the dialog is not visible. + * + * @param k button to change: + * 1: show hidden files + * 2: show places + * 3: show filter/list all (automatically hidden if there is no + * filter function) + * @param v <0 to hide the button >=0 show button, + * 0: set button-state to not-checked + * 1: set button-state to checked + * >1: retain current state + * @return 0 on success. + */ +int x_fib_cfg_buttons (int k, int v); + +/** set custom callback to filter file-names. + * NULL will disable the filter and hide the 'show all' button. + * changes only have any effect if the dialog is not visible. + * + * @param cb callback function to check file + * the callback function is called with the file name (basename only) + * and is expected to return 1 if the file passes the filter + * and 0 if the file should not be listed by default. + * @return 0 on success. + */ +int x_fib_cfg_filter_callback (int (*cb)(const char*)); + +#ifdef __cplusplus +} +#endif + +#endif /* END X11 specific functions */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* 'recently used' API. x-platform + * NOTE: all functions use a static cache and are not reentrant. + * It is expected that none of these functions are called in + * parallel from different threads. + */ + +/** release static resources of 'recently used files' + */ +void x_fib_free_recent (); + +/** add an entry to the recently used list + * + * The dialog does not add files automatically on open, + * if the application succeeds to open a selected file, + * this function should be called. + * + * @param path complete path to file + * @param atime time of last use, 0: NOW + * @return -1 on error, number of current entries otherwise + */ +int x_fib_add_recent (const char *path, time_t atime); + +/** get a platform specific path to a good location for + * saving the recently used file list. + * (follows XDG_DATA_HOME on Unix, and CSIDL_LOCAL_APPDATA spec) + * + * @param application-name to use to include in file + * @return pointer to static path or NULL + */ +const char *x_fib_recent_file(const char *appname); + +/** save the current list of recently used files to the given filename + * (the format is one file per line, filename URL encoded and space separated + * with last-used timestamp) + * + * This function tries to creates the containing directory if it does + * not exist. + * + * @param fn file to save the list to + * @return 0: on success + */ +int x_fib_save_recent (const char *fn); + +/** load a recently used file list. + * + * @param fn file to load the list from + * @return 0: on success + */ +int x_fib_load_recent (const char *fn); + +/** get number of entries in the current list + * @return number of entries in the recently used list + */ +unsigned int x_fib_recent_count (); + +/** get recently used entry at given position + * + * @param i entry to query + * @return pointer to static string + */ +const char *x_fib_recent_at (unsigned int i); + +#ifdef __cplusplus +} +#endif + +#endif // header guard diff --git a/contrib/md5.c b/contrib/md5.c new file mode 100644 index 0000000..81e6469 --- /dev/null +++ b/contrib/md5.c @@ -0,0 +1,289 @@ +/* + * This is an OpenSSL-compatible implementation of the RSA Data Security, Inc. + * MD5 Message-Digest Algorithm (RFC 1321). + * + * Homepage: + * http://openwall.info/wiki/people/solar/software/public-domain-source-code/md5 + * + * Author: + * Alexander Peslyak, better known as Solar Designer + * + * This software was written by Alexander Peslyak in 2001. No copyright is + * claimed, and the software is hereby placed in the public domain. + * In case this attempt to disclaim copyright and place the software in the + * public domain is deemed null and void, then the software is + * Copyright (c) 2001 Alexander Peslyak and it is hereby released to the + * general public under the following terms: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted. + * + * There's ABSOLUTELY NO WARRANTY, express or implied. + * + * (This is a heavily cut-down "BSD license".) + * + * This differs from Colin Plumb's older public domain implementation in that + * no exactly 32-bit integer data type is required (any 32-bit or wider + * unsigned integer data type will do), there's no compile-time endianness + * configuration, and the function prototypes match OpenSSL's. No code from + * Colin Plumb's implementation has been reused; this comment merely compares + * the properties of the two independent implementations. + * + * The primary goals of this implementation are portability and ease of use. + * It is meant to be fast, but not as fast as possible. Some known + * optimizations are not included to reduce source code size and avoid + * compile-time configuration. + */ + +#ifndef HAVE_OPENSSL +#include +#include "md5.h" + +/* + * The basic MD5 functions. + * + * F and G are optimized compared to their RFC 1321 definitions for + * architectures that lack an AND-NOT instruction, just like in Colin Plumb's + * implementation. + */ +#define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z)))) +#define G(x, y, z) ((y) ^ ((z) & ((x) ^ (y)))) +#define H(x, y, z) (((x) ^ (y)) ^ (z)) +#define H2(x, y, z) ((x) ^ ((y) ^ (z))) +#define I(x, y, z) ((y) ^ ((x) | ~(z))) + +/* + * The MD5 transformation for all four rounds. + */ +#define STEP(f, a, b, c, d, x, t, s) \ + (a) += f((b), (c), (d)) + (x) + (t); \ + (a) = (((a) << (s)) | (((a) & 0xffffffff) >> (32 - (s)))); \ + (a) += (b); + +/* + * SET reads 4 input bytes in little-endian byte order and stores them in a + * properly aligned word in host byte order. + * + * The check for little-endian architectures that tolerate unaligned memory + * accesses is just an optimization. Nothing will break if it fails to detect + * a suitable architecture. + * + * Unfortunately, this optimization may be a C strict aliasing rules violation + * if the caller's data buffer has effective type that cannot be aliased by + * MD5_u32plus. In practice, this problem may occur if these MD5 routines are + * inlined into a calling function, or with future and dangerously advanced + * link-time optimizations. For the time being, keeping these MD5 routines in + * their own translation unit avoids the problem. + */ +#if defined(__i386__) || defined(__x86_64__) || defined(__vax__) +#define SET(n) \ + (*(MD5_u32plus *)&ptr[(n) * 4]) +#define GET(n) \ + SET(n) +#else +#define SET(n) \ + (ctx->block[(n)] = \ + (MD5_u32plus)ptr[(n) * 4] | \ + ((MD5_u32plus)ptr[(n) * 4 + 1] << 8) | \ + ((MD5_u32plus)ptr[(n) * 4 + 2] << 16) | \ + ((MD5_u32plus)ptr[(n) * 4 + 3] << 24)) +#define GET(n) \ + (ctx->block[(n)]) +#endif + +/* + * This processes one or more 64-byte data blocks, but does NOT update the bit + * counters. There are no alignment requirements. + */ +static const void *body(MD5_CTX *ctx, const void *data, unsigned long size) +{ + const unsigned char *ptr; + MD5_u32plus a, b, c, d; + MD5_u32plus saved_a, saved_b, saved_c, saved_d; + + ptr = (const unsigned char *)data; + + a = ctx->a; + b = ctx->b; + c = ctx->c; + d = ctx->d; + + do { + saved_a = a; + saved_b = b; + saved_c = c; + saved_d = d; + +/* Round 1 */ + STEP(F, a, b, c, d, SET(0), 0xd76aa478, 7) + STEP(F, d, a, b, c, SET(1), 0xe8c7b756, 12) + STEP(F, c, d, a, b, SET(2), 0x242070db, 17) + STEP(F, b, c, d, a, SET(3), 0xc1bdceee, 22) + STEP(F, a, b, c, d, SET(4), 0xf57c0faf, 7) + STEP(F, d, a, b, c, SET(5), 0x4787c62a, 12) + STEP(F, c, d, a, b, SET(6), 0xa8304613, 17) + STEP(F, b, c, d, a, SET(7), 0xfd469501, 22) + STEP(F, a, b, c, d, SET(8), 0x698098d8, 7) + STEP(F, d, a, b, c, SET(9), 0x8b44f7af, 12) + STEP(F, c, d, a, b, SET(10), 0xffff5bb1, 17) + STEP(F, b, c, d, a, SET(11), 0x895cd7be, 22) + STEP(F, a, b, c, d, SET(12), 0x6b901122, 7) + STEP(F, d, a, b, c, SET(13), 0xfd987193, 12) + STEP(F, c, d, a, b, SET(14), 0xa679438e, 17) + STEP(F, b, c, d, a, SET(15), 0x49b40821, 22) + +/* Round 2 */ + STEP(G, a, b, c, d, GET(1), 0xf61e2562, 5) + STEP(G, d, a, b, c, GET(6), 0xc040b340, 9) + STEP(G, c, d, a, b, GET(11), 0x265e5a51, 14) + STEP(G, b, c, d, a, GET(0), 0xe9b6c7aa, 20) + STEP(G, a, b, c, d, GET(5), 0xd62f105d, 5) + STEP(G, d, a, b, c, GET(10), 0x02441453, 9) + STEP(G, c, d, a, b, GET(15), 0xd8a1e681, 14) + STEP(G, b, c, d, a, GET(4), 0xe7d3fbc8, 20) + STEP(G, a, b, c, d, GET(9), 0x21e1cde6, 5) + STEP(G, d, a, b, c, GET(14), 0xc33707d6, 9) + STEP(G, c, d, a, b, GET(3), 0xf4d50d87, 14) + STEP(G, b, c, d, a, GET(8), 0x455a14ed, 20) + STEP(G, a, b, c, d, GET(13), 0xa9e3e905, 5) + STEP(G, d, a, b, c, GET(2), 0xfcefa3f8, 9) + STEP(G, c, d, a, b, GET(7), 0x676f02d9, 14) + STEP(G, b, c, d, a, GET(12), 0x8d2a4c8a, 20) + +/* Round 3 */ + STEP(H, a, b, c, d, GET(5), 0xfffa3942, 4) + STEP(H2, d, a, b, c, GET(8), 0x8771f681, 11) + STEP(H, c, d, a, b, GET(11), 0x6d9d6122, 16) + STEP(H2, b, c, d, a, GET(14), 0xfde5380c, 23) + STEP(H, a, b, c, d, GET(1), 0xa4beea44, 4) + STEP(H2, d, a, b, c, GET(4), 0x4bdecfa9, 11) + STEP(H, c, d, a, b, GET(7), 0xf6bb4b60, 16) + STEP(H2, b, c, d, a, GET(10), 0xbebfbc70, 23) + STEP(H, a, b, c, d, GET(13), 0x289b7ec6, 4) + STEP(H2, d, a, b, c, GET(0), 0xeaa127fa, 11) + STEP(H, c, d, a, b, GET(3), 0xd4ef3085, 16) + STEP(H2, b, c, d, a, GET(6), 0x04881d05, 23) + STEP(H, a, b, c, d, GET(9), 0xd9d4d039, 4) + STEP(H2, d, a, b, c, GET(12), 0xe6db99e5, 11) + STEP(H, c, d, a, b, GET(15), 0x1fa27cf8, 16) + STEP(H2, b, c, d, a, GET(2), 0xc4ac5665, 23) + +/* Round 4 */ + STEP(I, a, b, c, d, GET(0), 0xf4292244, 6) + STEP(I, d, a, b, c, GET(7), 0x432aff97, 10) + STEP(I, c, d, a, b, GET(14), 0xab9423a7, 15) + STEP(I, b, c, d, a, GET(5), 0xfc93a039, 21) + STEP(I, a, b, c, d, GET(12), 0x655b59c3, 6) + STEP(I, d, a, b, c, GET(3), 0x8f0ccc92, 10) + STEP(I, c, d, a, b, GET(10), 0xffeff47d, 15) + STEP(I, b, c, d, a, GET(1), 0x85845dd1, 21) + STEP(I, a, b, c, d, GET(8), 0x6fa87e4f, 6) + STEP(I, d, a, b, c, GET(15), 0xfe2ce6e0, 10) + STEP(I, c, d, a, b, GET(6), 0xa3014314, 15) + STEP(I, b, c, d, a, GET(13), 0x4e0811a1, 21) + STEP(I, a, b, c, d, GET(4), 0xf7537e82, 6) + STEP(I, d, a, b, c, GET(11), 0xbd3af235, 10) + STEP(I, c, d, a, b, GET(2), 0x2ad7d2bb, 15) + STEP(I, b, c, d, a, GET(9), 0xeb86d391, 21) + + a += saved_a; + b += saved_b; + c += saved_c; + d += saved_d; + + ptr += 64; + } while (size -= 64); + + ctx->a = a; + ctx->b = b; + ctx->c = c; + ctx->d = d; + + return ptr; +} + +void MD5_Init(MD5_CTX *ctx) +{ + ctx->a = 0x67452301; + ctx->b = 0xefcdab89; + ctx->c = 0x98badcfe; + ctx->d = 0x10325476; + + ctx->lo = 0; + ctx->hi = 0; +} + +void MD5_Update(MD5_CTX *ctx, const void *data, unsigned long size) +{ + MD5_u32plus saved_lo; + unsigned long used, available; + + saved_lo = ctx->lo; + if ((ctx->lo = (saved_lo + size) & 0x1fffffff) < saved_lo) + ctx->hi++; + ctx->hi += size >> 29; + + used = saved_lo & 0x3f; + + if (used) { + available = 64 - used; + + if (size < available) { + memcpy(&ctx->buffer[used], data, size); + return; + } + + memcpy(&ctx->buffer[used], data, available); + data = (const unsigned char *)data + available; + size -= available; + body(ctx, ctx->buffer, 64); + } + + if (size >= 64) { + data = body(ctx, data, size & ~(unsigned long)0x3f); + size &= 0x3f; + } + + memcpy(ctx->buffer, data, size); +} + +#define OUT(dst, src) \ + (dst)[0] = (unsigned char)(src); \ + (dst)[1] = (unsigned char)((src) >> 8); \ + (dst)[2] = (unsigned char)((src) >> 16); \ + (dst)[3] = (unsigned char)((src) >> 24); + +void MD5_Final(unsigned char *result, MD5_CTX *ctx) +{ + unsigned long used, available; + + used = ctx->lo & 0x3f; + + ctx->buffer[used++] = 0x80; + + available = 64 - used; + + if (available < 8) { + memset(&ctx->buffer[used], 0, available); + body(ctx, ctx->buffer, 64); + used = 0; + available = 64; + } + + memset(&ctx->buffer[used], 0, available - 8); + + ctx->lo <<= 3; + OUT(&ctx->buffer[56], ctx->lo) + OUT(&ctx->buffer[60], ctx->hi) + + body(ctx, ctx->buffer, 64); + + OUT(&result[0], ctx->a) + OUT(&result[4], ctx->b) + OUT(&result[8], ctx->c) + OUT(&result[12], ctx->d) + + memset(ctx, 0, sizeof(*ctx)); +} + +#endif diff --git a/contrib/md5.h b/contrib/md5.h new file mode 100644 index 0000000..2497255 --- /dev/null +++ b/contrib/md5.h @@ -0,0 +1,43 @@ +/* + * This is an OpenSSL-compatible implementation of the RSA Data Security, Inc. + * MD5 Message-Digest Algorithm (RFC 1321). + * + * Homepage: + * http://openwall.info/wiki/people/solar/software/public-domain-source-code/md5 + * + * Author: + * Alexander Peslyak, better known as Solar Designer + * + * This software was written by Alexander Peslyak in 2001. No copyright is + * claimed, and the software is hereby placed in the public domain. + * In case this attempt to disclaim copyright and place the software in the + * public domain is deemed null and void, then the software is + * Copyright (c) 2001 Alexander Peslyak and it is hereby released to the + * general public under the following terms: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted. + * + * There's ABSOLUTELY NO WARRANTY, express or implied. + * + * See md5.c for more information. + */ + +#ifndef _MD5_H +#define _MD5_H + +/* Any 32-bit or wider unsigned integer data type will do */ +typedef unsigned int MD5_u32plus; + +typedef struct { + MD5_u32plus lo, hi; + MD5_u32plus a, b, c, d; + unsigned char buffer[64]; + MD5_u32plus block[16]; +} MD5_CTX; + +void MD5_Init(MD5_CTX *ctx); +void MD5_Update(MD5_CTX *ctx, const void *data, unsigned long size); +void MD5_Final(unsigned char *result, MD5_CTX *ctx); + +#endif /* _MD5_H */ diff --git a/contrib/stb_image_write.h b/contrib/stb_image_write.h new file mode 100644 index 0000000..e4b32ed --- /dev/null +++ b/contrib/stb_image_write.h @@ -0,0 +1,1724 @@ +/* stb_image_write - v1.16 - public domain - http://nothings.org/stb + writes out PNG/BMP/TGA/JPEG/HDR images to C stdio - Sean Barrett 2010-2015 + no warranty implied; use at your own risk + + Before #including, + + #define STB_IMAGE_WRITE_IMPLEMENTATION + + in the file that you want to have the implementation. + + Will probably not work correctly with strict-aliasing optimizations. + +ABOUT: + + This header file is a library for writing images to C stdio or a callback. + + The PNG output is not optimal; it is 20-50% larger than the file + written by a decent optimizing implementation; though providing a custom + zlib compress function (see STBIW_ZLIB_COMPRESS) can mitigate that. + This library is designed for source code compactness and simplicity, + not optimal image file size or run-time performance. + +BUILDING: + + You can #define STBIW_ASSERT(x) before the #include to avoid using assert.h. + You can #define STBIW_MALLOC(), STBIW_REALLOC(), and STBIW_FREE() to replace + malloc,realloc,free. + You can #define STBIW_MEMMOVE() to replace memmove() + You can #define STBIW_ZLIB_COMPRESS to use a custom zlib-style compress function + for PNG compression (instead of the builtin one), it must have the following signature: + unsigned char * my_compress(unsigned char *data, int data_len, int *out_len, int quality); + The returned data will be freed with STBIW_FREE() (free() by default), + so it must be heap allocated with STBIW_MALLOC() (malloc() by default), + +UNICODE: + + If compiling for Windows and you wish to use Unicode filenames, compile + with + #define STBIW_WINDOWS_UTF8 + and pass utf8-encoded filenames. Call stbiw_convert_wchar_to_utf8 to convert + Windows wchar_t filenames to utf8. + +USAGE: + + There are five functions, one for each image file format: + + int stbi_write_png(char const *filename, int w, int h, int comp, const void *data, int stride_in_bytes); + int stbi_write_bmp(char const *filename, int w, int h, int comp, const void *data); + int stbi_write_tga(char const *filename, int w, int h, int comp, const void *data); + int stbi_write_jpg(char const *filename, int w, int h, int comp, const void *data, int quality); + int stbi_write_hdr(char const *filename, int w, int h, int comp, const float *data); + + void stbi_flip_vertically_on_write(int flag); // flag is non-zero to flip data vertically + + There are also five equivalent functions that use an arbitrary write function. You are + expected to open/close your file-equivalent before and after calling these: + + int stbi_write_png_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const void *data, int stride_in_bytes); + int stbi_write_bmp_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const void *data); + int stbi_write_tga_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const void *data); + int stbi_write_hdr_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const float *data); + int stbi_write_jpg_to_func(stbi_write_func *func, void *context, int x, int y, int comp, const void *data, int quality); + + where the callback is: + void stbi_write_func(void *context, void *data, int size); + + You can configure it with these global variables: + int stbi_write_tga_with_rle; // defaults to true; set to 0 to disable RLE + int stbi_write_png_compression_level; // defaults to 8; set to higher for more compression + int stbi_write_force_png_filter; // defaults to -1; set to 0..5 to force a filter mode + + + You can define STBI_WRITE_NO_STDIO to disable the file variant of these + functions, so the library will not use stdio.h at all. However, this will + also disable HDR writing, because it requires stdio for formatted output. + + Each function returns 0 on failure and non-0 on success. + + The functions create an image file defined by the parameters. The image + is a rectangle of pixels stored from left-to-right, top-to-bottom. + Each pixel contains 'comp' channels of data stored interleaved with 8-bits + per channel, in the following order: 1=Y, 2=YA, 3=RGB, 4=RGBA. (Y is + monochrome color.) The rectangle is 'w' pixels wide and 'h' pixels tall. + The *data pointer points to the first byte of the top-left-most pixel. + For PNG, "stride_in_bytes" is the distance in bytes from the first byte of + a row of pixels to the first byte of the next row of pixels. + + PNG creates output files with the same number of components as the input. + The BMP format expands Y to RGB in the file format and does not + output alpha. + + PNG supports writing rectangles of data even when the bytes storing rows of + data are not consecutive in memory (e.g. sub-rectangles of a larger image), + by supplying the stride between the beginning of adjacent rows. The other + formats do not. (Thus you cannot write a native-format BMP through the BMP + writer, both because it is in BGR order and because it may have padding + at the end of the line.) + + PNG allows you to set the deflate compression level by setting the global + variable 'stbi_write_png_compression_level' (it defaults to 8). + + HDR expects linear float data. Since the format is always 32-bit rgb(e) + data, alpha (if provided) is discarded, and for monochrome data it is + replicated across all three channels. + + TGA supports RLE or non-RLE compressed data. To use non-RLE-compressed + data, set the global variable 'stbi_write_tga_with_rle' to 0. + + JPEG does ignore alpha channels in input data; quality is between 1 and 100. + Higher quality looks better but results in a bigger image. + JPEG baseline (no JPEG progressive). + +CREDITS: + + + Sean Barrett - PNG/BMP/TGA + Baldur Karlsson - HDR + Jean-Sebastien Guay - TGA monochrome + Tim Kelsey - misc enhancements + Alan Hickman - TGA RLE + Emmanuel Julien - initial file IO callback implementation + Jon Olick - original jo_jpeg.cpp code + Daniel Gibson - integrate JPEG, allow external zlib + Aarni Koskela - allow choosing PNG filter + + bugfixes: + github:Chribba + Guillaume Chereau + github:jry2 + github:romigrou + Sergio Gonzalez + Jonas Karlsson + Filip Wasil + Thatcher Ulrich + github:poppolopoppo + Patrick Boettcher + github:xeekworx + Cap Petschulat + Simon Rodriguez + Ivan Tikhonov + github:ignotion + Adam Schackart + Andrew Kensler + +LICENSE + + See end of file for license information. + +*/ + +#ifndef INCLUDE_STB_IMAGE_WRITE_H +#define INCLUDE_STB_IMAGE_WRITE_H + +#include + +// if STB_IMAGE_WRITE_STATIC causes problems, try defining STBIWDEF to 'inline' or 'static inline' +#ifndef STBIWDEF +#ifdef STB_IMAGE_WRITE_STATIC +#define STBIWDEF static +#else +#ifdef __cplusplus +#define STBIWDEF extern "C" +#else +#define STBIWDEF extern +#endif +#endif +#endif + +#ifndef STB_IMAGE_WRITE_STATIC // C++ forbids static forward declarations +STBIWDEF int stbi_write_tga_with_rle; +STBIWDEF int stbi_write_png_compression_level; +STBIWDEF int stbi_write_force_png_filter; +#endif + +#ifndef STBI_WRITE_NO_STDIO +STBIWDEF int stbi_write_png(char const *filename, int w, int h, int comp, const void *data, int stride_in_bytes); +STBIWDEF int stbi_write_bmp(char const *filename, int w, int h, int comp, const void *data); +STBIWDEF int stbi_write_tga(char const *filename, int w, int h, int comp, const void *data); +STBIWDEF int stbi_write_hdr(char const *filename, int w, int h, int comp, const float *data); +STBIWDEF int stbi_write_jpg(char const *filename, int x, int y, int comp, const void *data, int quality); + +#ifdef STBIW_WINDOWS_UTF8 +STBIWDEF int stbiw_convert_wchar_to_utf8(char *buffer, size_t bufferlen, const wchar_t* input); +#endif +#endif + +typedef void stbi_write_func(void *context, void *data, int size); + +STBIWDEF int stbi_write_png_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const void *data, int stride_in_bytes); +STBIWDEF int stbi_write_bmp_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const void *data); +STBIWDEF int stbi_write_tga_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const void *data); +STBIWDEF int stbi_write_hdr_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const float *data); +STBIWDEF int stbi_write_jpg_to_func(stbi_write_func *func, void *context, int x, int y, int comp, const void *data, int quality); + +STBIWDEF void stbi_flip_vertically_on_write(int flip_boolean); + +#endif//INCLUDE_STB_IMAGE_WRITE_H + +#ifdef STB_IMAGE_WRITE_IMPLEMENTATION + +#ifdef _WIN32 + #ifndef _CRT_SECURE_NO_WARNINGS + #define _CRT_SECURE_NO_WARNINGS + #endif + #ifndef _CRT_NONSTDC_NO_DEPRECATE + #define _CRT_NONSTDC_NO_DEPRECATE + #endif +#endif + +#ifndef STBI_WRITE_NO_STDIO +#include +#endif // STBI_WRITE_NO_STDIO + +#include +#include +#include +#include + +#if defined(STBIW_MALLOC) && defined(STBIW_FREE) && (defined(STBIW_REALLOC) || defined(STBIW_REALLOC_SIZED)) +// ok +#elif !defined(STBIW_MALLOC) && !defined(STBIW_FREE) && !defined(STBIW_REALLOC) && !defined(STBIW_REALLOC_SIZED) +// ok +#else +#error "Must define all or none of STBIW_MALLOC, STBIW_FREE, and STBIW_REALLOC (or STBIW_REALLOC_SIZED)." +#endif + +#ifndef STBIW_MALLOC +#define STBIW_MALLOC(sz) malloc(sz) +#define STBIW_REALLOC(p,newsz) realloc(p,newsz) +#define STBIW_FREE(p) free(p) +#endif + +#ifndef STBIW_REALLOC_SIZED +#define STBIW_REALLOC_SIZED(p,oldsz,newsz) STBIW_REALLOC(p,newsz) +#endif + + +#ifndef STBIW_MEMMOVE +#define STBIW_MEMMOVE(a,b,sz) memmove(a,b,sz) +#endif + + +#ifndef STBIW_ASSERT +#include +#define STBIW_ASSERT(x) assert(x) +#endif + +#define STBIW_UCHAR(x) (unsigned char) ((x) & 0xff) + +#ifdef STB_IMAGE_WRITE_STATIC +static int stbi_write_png_compression_level = 8; +static int stbi_write_tga_with_rle = 1; +static int stbi_write_force_png_filter = -1; +#else +int stbi_write_png_compression_level = 8; +int stbi_write_tga_with_rle = 1; +int stbi_write_force_png_filter = -1; +#endif + +static int stbi__flip_vertically_on_write = 0; + +STBIWDEF void stbi_flip_vertically_on_write(int flag) +{ + stbi__flip_vertically_on_write = flag; +} + +typedef struct +{ + stbi_write_func *func; + void *context; + unsigned char buffer[64]; + int buf_used; +} stbi__write_context; + +// initialize a callback-based context +static void stbi__start_write_callbacks(stbi__write_context *s, stbi_write_func *c, void *context) +{ + s->func = c; + s->context = context; +} + +#ifndef STBI_WRITE_NO_STDIO + +static void stbi__stdio_write(void *context, void *data, int size) +{ + fwrite(data,1,size,(FILE*) context); +} + +#if defined(_WIN32) && defined(STBIW_WINDOWS_UTF8) +#ifdef __cplusplus +#define STBIW_EXTERN extern "C" +#else +#define STBIW_EXTERN extern +#endif +STBIW_EXTERN __declspec(dllimport) int __stdcall MultiByteToWideChar(unsigned int cp, unsigned long flags, const char *str, int cbmb, wchar_t *widestr, int cchwide); +STBIW_EXTERN __declspec(dllimport) int __stdcall WideCharToMultiByte(unsigned int cp, unsigned long flags, const wchar_t *widestr, int cchwide, char *str, int cbmb, const char *defchar, int *used_default); + +STBIWDEF int stbiw_convert_wchar_to_utf8(char *buffer, size_t bufferlen, const wchar_t* input) +{ + return WideCharToMultiByte(65001 /* UTF8 */, 0, input, -1, buffer, (int) bufferlen, NULL, NULL); +} +#endif + +static FILE *stbiw__fopen(char const *filename, char const *mode) +{ + FILE *f; +#if defined(_WIN32) && defined(STBIW_WINDOWS_UTF8) + wchar_t wMode[64]; + wchar_t wFilename[1024]; + if (0 == MultiByteToWideChar(65001 /* UTF8 */, 0, filename, -1, wFilename, sizeof(wFilename)/sizeof(*wFilename))) + return 0; + + if (0 == MultiByteToWideChar(65001 /* UTF8 */, 0, mode, -1, wMode, sizeof(wMode)/sizeof(*wMode))) + return 0; + +#if defined(_MSC_VER) && _MSC_VER >= 1400 + if (0 != _wfopen_s(&f, wFilename, wMode)) + f = 0; +#else + f = _wfopen(wFilename, wMode); +#endif + +#elif defined(_MSC_VER) && _MSC_VER >= 1400 + if (0 != fopen_s(&f, filename, mode)) + f=0; +#else + f = fopen(filename, mode); +#endif + return f; +} + +static int stbi__start_write_file(stbi__write_context *s, const char *filename) +{ + FILE *f = stbiw__fopen(filename, "wb"); + stbi__start_write_callbacks(s, stbi__stdio_write, (void *) f); + return f != NULL; +} + +static void stbi__end_write_file(stbi__write_context *s) +{ + fclose((FILE *)s->context); +} + +#endif // !STBI_WRITE_NO_STDIO + +typedef unsigned int stbiw_uint32; +typedef int stb_image_write_test[sizeof(stbiw_uint32)==4 ? 1 : -1]; + +static void stbiw__writefv(stbi__write_context *s, const char *fmt, va_list v) +{ + while (*fmt) { + switch (*fmt++) { + case ' ': break; + case '1': { unsigned char x = STBIW_UCHAR(va_arg(v, int)); + s->func(s->context,&x,1); + break; } + case '2': { int x = va_arg(v,int); + unsigned char b[2]; + b[0] = STBIW_UCHAR(x); + b[1] = STBIW_UCHAR(x>>8); + s->func(s->context,b,2); + break; } + case '4': { stbiw_uint32 x = va_arg(v,int); + unsigned char b[4]; + b[0]=STBIW_UCHAR(x); + b[1]=STBIW_UCHAR(x>>8); + b[2]=STBIW_UCHAR(x>>16); + b[3]=STBIW_UCHAR(x>>24); + s->func(s->context,b,4); + break; } + default: + STBIW_ASSERT(0); + return; + } + } +} + +static void stbiw__writef(stbi__write_context *s, const char *fmt, ...) +{ + va_list v; + va_start(v, fmt); + stbiw__writefv(s, fmt, v); + va_end(v); +} + +static void stbiw__write_flush(stbi__write_context *s) +{ + if (s->buf_used) { + s->func(s->context, &s->buffer, s->buf_used); + s->buf_used = 0; + } +} + +static void stbiw__putc(stbi__write_context *s, unsigned char c) +{ + s->func(s->context, &c, 1); +} + +static void stbiw__write1(stbi__write_context *s, unsigned char a) +{ + if ((size_t)s->buf_used + 1 > sizeof(s->buffer)) + stbiw__write_flush(s); + s->buffer[s->buf_used++] = a; +} + +static void stbiw__write3(stbi__write_context *s, unsigned char a, unsigned char b, unsigned char c) +{ + int n; + if ((size_t)s->buf_used + 3 > sizeof(s->buffer)) + stbiw__write_flush(s); + n = s->buf_used; + s->buf_used = n+3; + s->buffer[n+0] = a; + s->buffer[n+1] = b; + s->buffer[n+2] = c; +} + +static void stbiw__write_pixel(stbi__write_context *s, int rgb_dir, int comp, int write_alpha, int expand_mono, unsigned char *d) +{ + unsigned char bg[3] = { 255, 0, 255}, px[3]; + int k; + + if (write_alpha < 0) + stbiw__write1(s, d[comp - 1]); + + switch (comp) { + case 2: // 2 pixels = mono + alpha, alpha is written separately, so same as 1-channel case + case 1: + if (expand_mono) + stbiw__write3(s, d[0], d[0], d[0]); // monochrome bmp + else + stbiw__write1(s, d[0]); // monochrome TGA + break; + case 4: + if (!write_alpha) { + // composite against pink background + for (k = 0; k < 3; ++k) + px[k] = bg[k] + ((d[k] - bg[k]) * d[3]) / 255; + stbiw__write3(s, px[1 - rgb_dir], px[1], px[1 + rgb_dir]); + break; + } + /* FALLTHROUGH */ + case 3: + stbiw__write3(s, d[1 - rgb_dir], d[1], d[1 + rgb_dir]); + break; + } + if (write_alpha > 0) + stbiw__write1(s, d[comp - 1]); +} + +static void stbiw__write_pixels(stbi__write_context *s, int rgb_dir, int vdir, int x, int y, int comp, void *data, int write_alpha, int scanline_pad, int expand_mono) +{ + stbiw_uint32 zero = 0; + int i,j, j_end; + + if (y <= 0) + return; + + if (stbi__flip_vertically_on_write) + vdir *= -1; + + if (vdir < 0) { + j_end = -1; j = y-1; + } else { + j_end = y; j = 0; + } + + for (; j != j_end; j += vdir) { + for (i=0; i < x; ++i) { + unsigned char *d = (unsigned char *) data + (j*x+i)*comp; + stbiw__write_pixel(s, rgb_dir, comp, write_alpha, expand_mono, d); + } + stbiw__write_flush(s); + s->func(s->context, &zero, scanline_pad); + } +} + +static int stbiw__outfile(stbi__write_context *s, int rgb_dir, int vdir, int x, int y, int comp, int expand_mono, void *data, int alpha, int pad, const char *fmt, ...) +{ + if (y < 0 || x < 0) { + return 0; + } else { + va_list v; + va_start(v, fmt); + stbiw__writefv(s, fmt, v); + va_end(v); + stbiw__write_pixels(s,rgb_dir,vdir,x,y,comp,data,alpha,pad, expand_mono); + return 1; + } +} + +static int stbi_write_bmp_core(stbi__write_context *s, int x, int y, int comp, const void *data) +{ + if (comp != 4) { + // write RGB bitmap + int pad = (-x*3) & 3; + return stbiw__outfile(s,-1,-1,x,y,comp,1,(void *) data,0,pad, + "11 4 22 4" "4 44 22 444444", + 'B', 'M', 14+40+(x*3+pad)*y, 0,0, 14+40, // file header + 40, x,y, 1,24, 0,0,0,0,0,0); // bitmap header + } else { + // RGBA bitmaps need a v4 header + // use BI_BITFIELDS mode with 32bpp and alpha mask + // (straight BI_RGB with alpha mask doesn't work in most readers) + return stbiw__outfile(s,-1,-1,x,y,comp,1,(void *)data,1,0, + "11 4 22 4" "4 44 22 444444 4444 4 444 444 444 444", + 'B', 'M', 14+108+x*y*4, 0, 0, 14+108, // file header + 108, x,y, 1,32, 3,0,0,0,0,0, 0xff0000,0xff00,0xff,0xff000000u, 0, 0,0,0, 0,0,0, 0,0,0, 0,0,0); // bitmap V4 header + } +} + +STBIWDEF int stbi_write_bmp_to_func(stbi_write_func *func, void *context, int x, int y, int comp, const void *data) +{ + stbi__write_context s = { 0 }; + stbi__start_write_callbacks(&s, func, context); + return stbi_write_bmp_core(&s, x, y, comp, data); +} + +#ifndef STBI_WRITE_NO_STDIO +STBIWDEF int stbi_write_bmp(char const *filename, int x, int y, int comp, const void *data) +{ + stbi__write_context s = { 0 }; + if (stbi__start_write_file(&s,filename)) { + int r = stbi_write_bmp_core(&s, x, y, comp, data); + stbi__end_write_file(&s); + return r; + } else + return 0; +} +#endif //!STBI_WRITE_NO_STDIO + +static int stbi_write_tga_core(stbi__write_context *s, int x, int y, int comp, void *data) +{ + int has_alpha = (comp == 2 || comp == 4); + int colorbytes = has_alpha ? comp-1 : comp; + int format = colorbytes < 2 ? 3 : 2; // 3 color channels (RGB/RGBA) = 2, 1 color channel (Y/YA) = 3 + + if (y < 0 || x < 0) + return 0; + + if (!stbi_write_tga_with_rle) { + return stbiw__outfile(s, -1, -1, x, y, comp, 0, (void *) data, has_alpha, 0, + "111 221 2222 11", 0, 0, format, 0, 0, 0, 0, 0, x, y, (colorbytes + has_alpha) * 8, has_alpha * 8); + } else { + int i,j,k; + int jend, jdir; + + stbiw__writef(s, "111 221 2222 11", 0,0,format+8, 0,0,0, 0,0,x,y, (colorbytes + has_alpha) * 8, has_alpha * 8); + + if (stbi__flip_vertically_on_write) { + j = 0; + jend = y; + jdir = 1; + } else { + j = y-1; + jend = -1; + jdir = -1; + } + for (; j != jend; j += jdir) { + unsigned char *row = (unsigned char *) data + j * x * comp; + int len; + + for (i = 0; i < x; i += len) { + unsigned char *begin = row + i * comp; + int diff = 1; + len = 1; + + if (i < x - 1) { + ++len; + diff = memcmp(begin, row + (i + 1) * comp, comp); + if (diff) { + const unsigned char *prev = begin; + for (k = i + 2; k < x && len < 128; ++k) { + if (memcmp(prev, row + k * comp, comp)) { + prev += comp; + ++len; + } else { + --len; + break; + } + } + } else { + for (k = i + 2; k < x && len < 128; ++k) { + if (!memcmp(begin, row + k * comp, comp)) { + ++len; + } else { + break; + } + } + } + } + + if (diff) { + unsigned char header = STBIW_UCHAR(len - 1); + stbiw__write1(s, header); + for (k = 0; k < len; ++k) { + stbiw__write_pixel(s, -1, comp, has_alpha, 0, begin + k * comp); + } + } else { + unsigned char header = STBIW_UCHAR(len - 129); + stbiw__write1(s, header); + stbiw__write_pixel(s, -1, comp, has_alpha, 0, begin); + } + } + } + stbiw__write_flush(s); + } + return 1; +} + +STBIWDEF int stbi_write_tga_to_func(stbi_write_func *func, void *context, int x, int y, int comp, const void *data) +{ + stbi__write_context s = { 0 }; + stbi__start_write_callbacks(&s, func, context); + return stbi_write_tga_core(&s, x, y, comp, (void *) data); +} + +#ifndef STBI_WRITE_NO_STDIO +STBIWDEF int stbi_write_tga(char const *filename, int x, int y, int comp, const void *data) +{ + stbi__write_context s = { 0 }; + if (stbi__start_write_file(&s,filename)) { + int r = stbi_write_tga_core(&s, x, y, comp, (void *) data); + stbi__end_write_file(&s); + return r; + } else + return 0; +} +#endif + +// ************************************************************************************************* +// Radiance RGBE HDR writer +// by Baldur Karlsson + +#define stbiw__max(a, b) ((a) > (b) ? (a) : (b)) + +#ifndef STBI_WRITE_NO_STDIO + +static void stbiw__linear_to_rgbe(unsigned char *rgbe, float *linear) +{ + int exponent; + float maxcomp = stbiw__max(linear[0], stbiw__max(linear[1], linear[2])); + + if (maxcomp < 1e-32f) { + rgbe[0] = rgbe[1] = rgbe[2] = rgbe[3] = 0; + } else { + float normalize = (float) frexp(maxcomp, &exponent) * 256.0f/maxcomp; + + rgbe[0] = (unsigned char)(linear[0] * normalize); + rgbe[1] = (unsigned char)(linear[1] * normalize); + rgbe[2] = (unsigned char)(linear[2] * normalize); + rgbe[3] = (unsigned char)(exponent + 128); + } +} + +static void stbiw__write_run_data(stbi__write_context *s, int length, unsigned char databyte) +{ + unsigned char lengthbyte = STBIW_UCHAR(length+128); + STBIW_ASSERT(length+128 <= 255); + s->func(s->context, &lengthbyte, 1); + s->func(s->context, &databyte, 1); +} + +static void stbiw__write_dump_data(stbi__write_context *s, int length, unsigned char *data) +{ + unsigned char lengthbyte = STBIW_UCHAR(length); + STBIW_ASSERT(length <= 128); // inconsistent with spec but consistent with official code + s->func(s->context, &lengthbyte, 1); + s->func(s->context, data, length); +} + +static void stbiw__write_hdr_scanline(stbi__write_context *s, int width, int ncomp, unsigned char *scratch, float *scanline) +{ + unsigned char scanlineheader[4] = { 2, 2, 0, 0 }; + unsigned char rgbe[4]; + float linear[3]; + int x; + + scanlineheader[2] = (width&0xff00)>>8; + scanlineheader[3] = (width&0x00ff); + + /* skip RLE for images too small or large */ + if (width < 8 || width >= 32768) { + for (x=0; x < width; x++) { + switch (ncomp) { + case 4: /* fallthrough */ + case 3: linear[2] = scanline[x*ncomp + 2]; + linear[1] = scanline[x*ncomp + 1]; + linear[0] = scanline[x*ncomp + 0]; + break; + default: + linear[0] = linear[1] = linear[2] = scanline[x*ncomp + 0]; + break; + } + stbiw__linear_to_rgbe(rgbe, linear); + s->func(s->context, rgbe, 4); + } + } else { + int c,r; + /* encode into scratch buffer */ + for (x=0; x < width; x++) { + switch(ncomp) { + case 4: /* fallthrough */ + case 3: linear[2] = scanline[x*ncomp + 2]; + linear[1] = scanline[x*ncomp + 1]; + linear[0] = scanline[x*ncomp + 0]; + break; + default: + linear[0] = linear[1] = linear[2] = scanline[x*ncomp + 0]; + break; + } + stbiw__linear_to_rgbe(rgbe, linear); + scratch[x + width*0] = rgbe[0]; + scratch[x + width*1] = rgbe[1]; + scratch[x + width*2] = rgbe[2]; + scratch[x + width*3] = rgbe[3]; + } + + s->func(s->context, scanlineheader, 4); + + /* RLE each component separately */ + for (c=0; c < 4; c++) { + unsigned char *comp = &scratch[width*c]; + + x = 0; + while (x < width) { + // find first run + r = x; + while (r+2 < width) { + if (comp[r] == comp[r+1] && comp[r] == comp[r+2]) + break; + ++r; + } + if (r+2 >= width) + r = width; + // dump up to first run + while (x < r) { + int len = r-x; + if (len > 128) len = 128; + stbiw__write_dump_data(s, len, &comp[x]); + x += len; + } + // if there's a run, output it + if (r+2 < width) { // same test as what we break out of in search loop, so only true if we break'd + // find next byte after run + while (r < width && comp[r] == comp[x]) + ++r; + // output run up to r + while (x < r) { + int len = r-x; + if (len > 127) len = 127; + stbiw__write_run_data(s, len, comp[x]); + x += len; + } + } + } + } + } +} + +static int stbi_write_hdr_core(stbi__write_context *s, int x, int y, int comp, float *data) +{ + if (y <= 0 || x <= 0 || data == NULL) + return 0; + else { + // Each component is stored separately. Allocate scratch space for full output scanline. + unsigned char *scratch = (unsigned char *) STBIW_MALLOC(x*4); + int i, len; + char buffer[128]; + char header[] = "#?RADIANCE\n# Written by stb_image_write.h\nFORMAT=32-bit_rle_rgbe\n"; + s->func(s->context, header, sizeof(header)-1); + +#ifdef __STDC_LIB_EXT1__ + len = sprintf_s(buffer, sizeof(buffer), "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x); +#else + len = sprintf(buffer, "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x); +#endif + s->func(s->context, buffer, len); + + for(i=0; i < y; i++) + stbiw__write_hdr_scanline(s, x, comp, scratch, data + comp*x*(stbi__flip_vertically_on_write ? y-1-i : i)); + STBIW_FREE(scratch); + return 1; + } +} + +STBIWDEF int stbi_write_hdr_to_func(stbi_write_func *func, void *context, int x, int y, int comp, const float *data) +{ + stbi__write_context s = { 0 }; + stbi__start_write_callbacks(&s, func, context); + return stbi_write_hdr_core(&s, x, y, comp, (float *) data); +} + +STBIWDEF int stbi_write_hdr(char const *filename, int x, int y, int comp, const float *data) +{ + stbi__write_context s = { 0 }; + if (stbi__start_write_file(&s,filename)) { + int r = stbi_write_hdr_core(&s, x, y, comp, (float *) data); + stbi__end_write_file(&s); + return r; + } else + return 0; +} +#endif // STBI_WRITE_NO_STDIO + + +////////////////////////////////////////////////////////////////////////////// +// +// PNG writer +// + +#ifndef STBIW_ZLIB_COMPRESS +// stretchy buffer; stbiw__sbpush() == vector<>::push_back() -- stbiw__sbcount() == vector<>::size() +#define stbiw__sbraw(a) ((int *) (void *) (a) - 2) +#define stbiw__sbm(a) stbiw__sbraw(a)[0] +#define stbiw__sbn(a) stbiw__sbraw(a)[1] + +#define stbiw__sbneedgrow(a,n) ((a)==0 || stbiw__sbn(a)+n >= stbiw__sbm(a)) +#define stbiw__sbmaybegrow(a,n) (stbiw__sbneedgrow(a,(n)) ? stbiw__sbgrow(a,n) : 0) +#define stbiw__sbgrow(a,n) stbiw__sbgrowf((void **) &(a), (n), sizeof(*(a))) + +#define stbiw__sbpush(a, v) (stbiw__sbmaybegrow(a,1), (a)[stbiw__sbn(a)++] = (v)) +#define stbiw__sbcount(a) ((a) ? stbiw__sbn(a) : 0) +#define stbiw__sbfree(a) ((a) ? STBIW_FREE(stbiw__sbraw(a)),0 : 0) + +static void *stbiw__sbgrowf(void **arr, int increment, int itemsize) +{ + int m = *arr ? 2*stbiw__sbm(*arr)+increment : increment+1; + void *p = STBIW_REALLOC_SIZED(*arr ? stbiw__sbraw(*arr) : 0, *arr ? (stbiw__sbm(*arr)*itemsize + sizeof(int)*2) : 0, itemsize * m + sizeof(int)*2); + STBIW_ASSERT(p); + if (p) { + if (!*arr) ((int *) p)[1] = 0; + *arr = (void *) ((int *) p + 2); + stbiw__sbm(*arr) = m; + } + return *arr; +} + +static unsigned char *stbiw__zlib_flushf(unsigned char *data, unsigned int *bitbuffer, int *bitcount) +{ + while (*bitcount >= 8) { + stbiw__sbpush(data, STBIW_UCHAR(*bitbuffer)); + *bitbuffer >>= 8; + *bitcount -= 8; + } + return data; +} + +static int stbiw__zlib_bitrev(int code, int codebits) +{ + int res=0; + while (codebits--) { + res = (res << 1) | (code & 1); + code >>= 1; + } + return res; +} + +static unsigned int stbiw__zlib_countm(unsigned char *a, unsigned char *b, int limit) +{ + int i; + for (i=0; i < limit && i < 258; ++i) + if (a[i] != b[i]) break; + return i; +} + +static unsigned int stbiw__zhash(unsigned char *data) +{ + stbiw_uint32 hash = data[0] + (data[1] << 8) + (data[2] << 16); + hash ^= hash << 3; + hash += hash >> 5; + hash ^= hash << 4; + hash += hash >> 17; + hash ^= hash << 25; + hash += hash >> 6; + return hash; +} + +#define stbiw__zlib_flush() (out = stbiw__zlib_flushf(out, &bitbuf, &bitcount)) +#define stbiw__zlib_add(code,codebits) \ + (bitbuf |= (code) << bitcount, bitcount += (codebits), stbiw__zlib_flush()) +#define stbiw__zlib_huffa(b,c) stbiw__zlib_add(stbiw__zlib_bitrev(b,c),c) +// default huffman tables +#define stbiw__zlib_huff1(n) stbiw__zlib_huffa(0x30 + (n), 8) +#define stbiw__zlib_huff2(n) stbiw__zlib_huffa(0x190 + (n)-144, 9) +#define stbiw__zlib_huff3(n) stbiw__zlib_huffa(0 + (n)-256,7) +#define stbiw__zlib_huff4(n) stbiw__zlib_huffa(0xc0 + (n)-280,8) +#define stbiw__zlib_huff(n) ((n) <= 143 ? stbiw__zlib_huff1(n) : (n) <= 255 ? stbiw__zlib_huff2(n) : (n) <= 279 ? stbiw__zlib_huff3(n) : stbiw__zlib_huff4(n)) +#define stbiw__zlib_huffb(n) ((n) <= 143 ? stbiw__zlib_huff1(n) : stbiw__zlib_huff2(n)) + +#define stbiw__ZHASH 16384 + +#endif // STBIW_ZLIB_COMPRESS + +STBIWDEF unsigned char * stbi_zlib_compress(unsigned char *data, int data_len, int *out_len, int quality) +{ +#ifdef STBIW_ZLIB_COMPRESS + // user provided a zlib compress implementation, use that + return STBIW_ZLIB_COMPRESS(data, data_len, out_len, quality); +#else // use builtin + static unsigned short lengthc[] = { 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, 259 }; + static unsigned char lengtheb[]= { 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 unsigned short distc[] = { 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, 32768 }; + static unsigned char disteb[] = { 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 }; + unsigned int bitbuf=0; + int i,j, bitcount=0; + unsigned char *out = NULL; + unsigned char ***hash_table = (unsigned char***) STBIW_MALLOC(stbiw__ZHASH * sizeof(unsigned char**)); + if (hash_table == NULL) + return NULL; + if (quality < 5) quality = 5; + + stbiw__sbpush(out, 0x78); // DEFLATE 32K window + stbiw__sbpush(out, 0x5e); // FLEVEL = 1 + stbiw__zlib_add(1,1); // BFINAL = 1 + stbiw__zlib_add(1,2); // BTYPE = 1 -- fixed huffman + + for (i=0; i < stbiw__ZHASH; ++i) + hash_table[i] = NULL; + + i=0; + while (i < data_len-3) { + // hash next 3 bytes of data to be compressed + int h = stbiw__zhash(data+i)&(stbiw__ZHASH-1), best=3; + unsigned char *bestloc = 0; + unsigned char **hlist = hash_table[h]; + int n = stbiw__sbcount(hlist); + for (j=0; j < n; ++j) { + if (hlist[j]-data > i-32768) { // if entry lies within window + int d = stbiw__zlib_countm(hlist[j], data+i, data_len-i); + if (d >= best) { best=d; bestloc=hlist[j]; } + } + } + // when hash table entry is too long, delete half the entries + if (hash_table[h] && stbiw__sbn(hash_table[h]) == 2*quality) { + STBIW_MEMMOVE(hash_table[h], hash_table[h]+quality, sizeof(hash_table[h][0])*quality); + stbiw__sbn(hash_table[h]) = quality; + } + stbiw__sbpush(hash_table[h],data+i); + + if (bestloc) { + // "lazy matching" - check match at *next* byte, and if it's better, do cur byte as literal + h = stbiw__zhash(data+i+1)&(stbiw__ZHASH-1); + hlist = hash_table[h]; + n = stbiw__sbcount(hlist); + for (j=0; j < n; ++j) { + if (hlist[j]-data > i-32767) { + int e = stbiw__zlib_countm(hlist[j], data+i+1, data_len-i-1); + if (e > best) { // if next match is better, bail on current match + bestloc = NULL; + break; + } + } + } + } + + if (bestloc) { + int d = (int) (data+i - bestloc); // distance back + STBIW_ASSERT(d <= 32767 && best <= 258); + for (j=0; best > lengthc[j+1]-1; ++j); + stbiw__zlib_huff(j+257); + if (lengtheb[j]) stbiw__zlib_add(best - lengthc[j], lengtheb[j]); + for (j=0; d > distc[j+1]-1; ++j); + stbiw__zlib_add(stbiw__zlib_bitrev(j,5),5); + if (disteb[j]) stbiw__zlib_add(d - distc[j], disteb[j]); + i += best; + } else { + stbiw__zlib_huffb(data[i]); + ++i; + } + } + // write out final bytes + for (;i < data_len; ++i) + stbiw__zlib_huffb(data[i]); + stbiw__zlib_huff(256); // end of block + // pad with 0 bits to byte boundary + while (bitcount) + stbiw__zlib_add(0,1); + + for (i=0; i < stbiw__ZHASH; ++i) + (void) stbiw__sbfree(hash_table[i]); + STBIW_FREE(hash_table); + + // store uncompressed instead if compression was worse + if (stbiw__sbn(out) > data_len + 2 + ((data_len+32766)/32767)*5) { + stbiw__sbn(out) = 2; // truncate to DEFLATE 32K window and FLEVEL = 1 + for (j = 0; j < data_len;) { + int blocklen = data_len - j; + if (blocklen > 32767) blocklen = 32767; + stbiw__sbpush(out, data_len - j == blocklen); // BFINAL = ?, BTYPE = 0 -- no compression + stbiw__sbpush(out, STBIW_UCHAR(blocklen)); // LEN + stbiw__sbpush(out, STBIW_UCHAR(blocklen >> 8)); + stbiw__sbpush(out, STBIW_UCHAR(~blocklen)); // NLEN + stbiw__sbpush(out, STBIW_UCHAR(~blocklen >> 8)); + memcpy(out+stbiw__sbn(out), data+j, blocklen); + stbiw__sbn(out) += blocklen; + j += blocklen; + } + } + + { + // compute adler32 on input + unsigned int s1=1, s2=0; + int blocklen = (int) (data_len % 5552); + j=0; + while (j < data_len) { + for (i=0; i < blocklen; ++i) { s1 += data[j+i]; s2 += s1; } + s1 %= 65521; s2 %= 65521; + j += blocklen; + blocklen = 5552; + } + stbiw__sbpush(out, STBIW_UCHAR(s2 >> 8)); + stbiw__sbpush(out, STBIW_UCHAR(s2)); + stbiw__sbpush(out, STBIW_UCHAR(s1 >> 8)); + stbiw__sbpush(out, STBIW_UCHAR(s1)); + } + *out_len = stbiw__sbn(out); + // make returned pointer freeable + STBIW_MEMMOVE(stbiw__sbraw(out), out, *out_len); + return (unsigned char *) stbiw__sbraw(out); +#endif // STBIW_ZLIB_COMPRESS +} + +static unsigned int stbiw__crc32(unsigned char *buffer, int len) +{ +#ifdef STBIW_CRC32 + return STBIW_CRC32(buffer, len); +#else + static unsigned int crc_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 + }; + + unsigned int crc = ~0u; + int i; + for (i=0; i < len; ++i) + crc = (crc >> 8) ^ crc_table[buffer[i] ^ (crc & 0xff)]; + return ~crc; +#endif +} + +#define stbiw__wpng4(o,a,b,c,d) ((o)[0]=STBIW_UCHAR(a),(o)[1]=STBIW_UCHAR(b),(o)[2]=STBIW_UCHAR(c),(o)[3]=STBIW_UCHAR(d),(o)+=4) +#define stbiw__wp32(data,v) stbiw__wpng4(data, (v)>>24,(v)>>16,(v)>>8,(v)); +#define stbiw__wptag(data,s) stbiw__wpng4(data, s[0],s[1],s[2],s[3]) + +static void stbiw__wpcrc(unsigned char **data, int len) +{ + unsigned int crc = stbiw__crc32(*data - len - 4, len+4); + stbiw__wp32(*data, crc); +} + +static unsigned char stbiw__paeth(int a, int b, int c) +{ + int p = a + b - c, pa = abs(p-a), pb = abs(p-b), pc = abs(p-c); + if (pa <= pb && pa <= pc) return STBIW_UCHAR(a); + if (pb <= pc) return STBIW_UCHAR(b); + return STBIW_UCHAR(c); +} + +// @OPTIMIZE: provide an option that always forces left-predict or paeth predict +static void stbiw__encode_png_line(unsigned char *pixels, int stride_bytes, int width, int height, int y, int n, int filter_type, signed char *line_buffer) +{ + static int mapping[] = { 0,1,2,3,4 }; + static int firstmap[] = { 0,1,0,5,6 }; + int *mymap = (y != 0) ? mapping : firstmap; + int i; + int type = mymap[filter_type]; + unsigned char *z = pixels + stride_bytes * (stbi__flip_vertically_on_write ? height-1-y : y); + int signed_stride = stbi__flip_vertically_on_write ? -stride_bytes : stride_bytes; + + if (type==0) { + memcpy(line_buffer, z, width*n); + return; + } + + // first loop isn't optimized since it's just one pixel + for (i = 0; i < n; ++i) { + switch (type) { + case 1: line_buffer[i] = z[i]; break; + case 2: line_buffer[i] = z[i] - z[i-signed_stride]; break; + case 3: line_buffer[i] = z[i] - (z[i-signed_stride]>>1); break; + case 4: line_buffer[i] = (signed char) (z[i] - stbiw__paeth(0,z[i-signed_stride],0)); break; + case 5: line_buffer[i] = z[i]; break; + case 6: line_buffer[i] = z[i]; break; + } + } + switch (type) { + case 1: for (i=n; i < width*n; ++i) line_buffer[i] = z[i] - z[i-n]; break; + case 2: for (i=n; i < width*n; ++i) line_buffer[i] = z[i] - z[i-signed_stride]; break; + case 3: for (i=n; i < width*n; ++i) line_buffer[i] = z[i] - ((z[i-n] + z[i-signed_stride])>>1); break; + case 4: for (i=n; i < width*n; ++i) line_buffer[i] = z[i] - stbiw__paeth(z[i-n], z[i-signed_stride], z[i-signed_stride-n]); break; + case 5: for (i=n; i < width*n; ++i) line_buffer[i] = z[i] - (z[i-n]>>1); break; + case 6: for (i=n; i < width*n; ++i) line_buffer[i] = z[i] - stbiw__paeth(z[i-n], 0,0); break; + } +} + +STBIWDEF unsigned char *stbi_write_png_to_mem(const unsigned char *pixels, int stride_bytes, int x, int y, int n, int *out_len) +{ + int force_filter = stbi_write_force_png_filter; + int ctype[5] = { -1, 0, 4, 2, 6 }; + unsigned char sig[8] = { 137,80,78,71,13,10,26,10 }; + unsigned char *out,*o, *filt, *zlib; + signed char *line_buffer; + int j,zlen; + + if (stride_bytes == 0) + stride_bytes = x * n; + + if (force_filter >= 5) { + force_filter = -1; + } + + filt = (unsigned char *) STBIW_MALLOC((x*n+1) * y); if (!filt) return 0; + line_buffer = (signed char *) STBIW_MALLOC(x * n); if (!line_buffer) { STBIW_FREE(filt); return 0; } + for (j=0; j < y; ++j) { + int filter_type; + if (force_filter > -1) { + filter_type = force_filter; + stbiw__encode_png_line((unsigned char*)(pixels), stride_bytes, x, y, j, n, force_filter, line_buffer); + } else { // Estimate the best filter by running through all of them: + int best_filter = 0, best_filter_val = 0x7fffffff, est, i; + for (filter_type = 0; filter_type < 5; filter_type++) { + stbiw__encode_png_line((unsigned char*)(pixels), stride_bytes, x, y, j, n, filter_type, line_buffer); + + // Estimate the entropy of the line using this filter; the less, the better. + est = 0; + for (i = 0; i < x*n; ++i) { + est += abs((signed char) line_buffer[i]); + } + if (est < best_filter_val) { + best_filter_val = est; + best_filter = filter_type; + } + } + if (filter_type != best_filter) { // If the last iteration already got us the best filter, don't redo it + stbiw__encode_png_line((unsigned char*)(pixels), stride_bytes, x, y, j, n, best_filter, line_buffer); + filter_type = best_filter; + } + } + // when we get here, filter_type contains the filter type, and line_buffer contains the data + filt[j*(x*n+1)] = (unsigned char) filter_type; + STBIW_MEMMOVE(filt+j*(x*n+1)+1, line_buffer, x*n); + } + STBIW_FREE(line_buffer); + zlib = stbi_zlib_compress(filt, y*( x*n+1), &zlen, stbi_write_png_compression_level); + STBIW_FREE(filt); + if (!zlib) return 0; + + // each tag requires 12 bytes of overhead + out = (unsigned char *) STBIW_MALLOC(8 + 12+13 + 12+zlen + 12); + if (!out) return 0; + *out_len = 8 + 12+13 + 12+zlen + 12; + + o=out; + STBIW_MEMMOVE(o,sig,8); o+= 8; + stbiw__wp32(o, 13); // header length + stbiw__wptag(o, "IHDR"); + stbiw__wp32(o, x); + stbiw__wp32(o, y); + *o++ = 8; + *o++ = STBIW_UCHAR(ctype[n]); + *o++ = 0; + *o++ = 0; + *o++ = 0; + stbiw__wpcrc(&o,13); + + stbiw__wp32(o, zlen); + stbiw__wptag(o, "IDAT"); + STBIW_MEMMOVE(o, zlib, zlen); + o += zlen; + STBIW_FREE(zlib); + stbiw__wpcrc(&o, zlen); + + stbiw__wp32(o,0); + stbiw__wptag(o, "IEND"); + stbiw__wpcrc(&o,0); + + STBIW_ASSERT(o == out + *out_len); + + return out; +} + +#ifndef STBI_WRITE_NO_STDIO +STBIWDEF int stbi_write_png(char const *filename, int x, int y, int comp, const void *data, int stride_bytes) +{ + FILE *f; + int len; + unsigned char *png = stbi_write_png_to_mem((const unsigned char *) data, stride_bytes, x, y, comp, &len); + if (png == NULL) return 0; + + f = stbiw__fopen(filename, "wb"); + if (!f) { STBIW_FREE(png); return 0; } + fwrite(png, 1, len, f); + fclose(f); + STBIW_FREE(png); + return 1; +} +#endif + +STBIWDEF int stbi_write_png_to_func(stbi_write_func *func, void *context, int x, int y, int comp, const void *data, int stride_bytes) +{ + int len; + unsigned char *png = stbi_write_png_to_mem((const unsigned char *) data, stride_bytes, x, y, comp, &len); + if (png == NULL) return 0; + func(context, png, len); + STBIW_FREE(png); + return 1; +} + + +/* *************************************************************************** + * + * JPEG writer + * + * This is based on Jon Olick's jo_jpeg.cpp: + * public domain Simple, Minimalistic JPEG writer - http://www.jonolick.com/code.html + */ + +static const unsigned char stbiw__jpg_ZigZag[] = { 0,1,5,6,14,15,27,28,2,4,7,13,16,26,29,42,3,8,12,17,25,30,41,43,9,11,18, + 24,31,40,44,53,10,19,23,32,39,45,52,54,20,22,33,38,46,51,55,60,21,34,37,47,50,56,59,61,35,36,48,49,57,58,62,63 }; + +static void stbiw__jpg_writeBits(stbi__write_context *s, int *bitBufP, int *bitCntP, const unsigned short *bs) { + int bitBuf = *bitBufP, bitCnt = *bitCntP; + bitCnt += bs[1]; + bitBuf |= bs[0] << (24 - bitCnt); + while(bitCnt >= 8) { + unsigned char c = (bitBuf >> 16) & 255; + stbiw__putc(s, c); + if(c == 255) { + stbiw__putc(s, 0); + } + bitBuf <<= 8; + bitCnt -= 8; + } + *bitBufP = bitBuf; + *bitCntP = bitCnt; +} + +static void stbiw__jpg_DCT(float *d0p, float *d1p, float *d2p, float *d3p, float *d4p, float *d5p, float *d6p, float *d7p) { + float d0 = *d0p, d1 = *d1p, d2 = *d2p, d3 = *d3p, d4 = *d4p, d5 = *d5p, d6 = *d6p, d7 = *d7p; + float z1, z2, z3, z4, z5, z11, z13; + + float tmp0 = d0 + d7; + float tmp7 = d0 - d7; + float tmp1 = d1 + d6; + float tmp6 = d1 - d6; + float tmp2 = d2 + d5; + float tmp5 = d2 - d5; + float tmp3 = d3 + d4; + float tmp4 = d3 - d4; + + // Even part + float tmp10 = tmp0 + tmp3; // phase 2 + float tmp13 = tmp0 - tmp3; + float tmp11 = tmp1 + tmp2; + float tmp12 = tmp1 - tmp2; + + d0 = tmp10 + tmp11; // phase 3 + d4 = tmp10 - tmp11; + + z1 = (tmp12 + tmp13) * 0.707106781f; // c4 + d2 = tmp13 + z1; // phase 5 + d6 = tmp13 - z1; + + // Odd part + tmp10 = tmp4 + tmp5; // phase 2 + tmp11 = tmp5 + tmp6; + tmp12 = tmp6 + tmp7; + + // The rotator is modified from fig 4-8 to avoid extra negations. + z5 = (tmp10 - tmp12) * 0.382683433f; // c6 + z2 = tmp10 * 0.541196100f + z5; // c2-c6 + z4 = tmp12 * 1.306562965f + z5; // c2+c6 + z3 = tmp11 * 0.707106781f; // c4 + + z11 = tmp7 + z3; // phase 5 + z13 = tmp7 - z3; + + *d5p = z13 + z2; // phase 6 + *d3p = z13 - z2; + *d1p = z11 + z4; + *d7p = z11 - z4; + + *d0p = d0; *d2p = d2; *d4p = d4; *d6p = d6; +} + +static void stbiw__jpg_calcBits(int val, unsigned short bits[2]) { + int tmp1 = val < 0 ? -val : val; + val = val < 0 ? val-1 : val; + bits[1] = 1; + while(tmp1 >>= 1) { + ++bits[1]; + } + bits[0] = val & ((1<0)&&(DU[end0pos]==0); --end0pos) { + } + // end0pos = first element in reverse order !=0 + if(end0pos == 0) { + stbiw__jpg_writeBits(s, bitBuf, bitCnt, EOB); + return DU[0]; + } + for(i = 1; i <= end0pos; ++i) { + int startpos = i; + int nrzeroes; + unsigned short bits[2]; + for (; DU[i]==0 && i<=end0pos; ++i) { + } + nrzeroes = i-startpos; + if ( nrzeroes >= 16 ) { + int lng = nrzeroes>>4; + int nrmarker; + for (nrmarker=1; nrmarker <= lng; ++nrmarker) + stbiw__jpg_writeBits(s, bitBuf, bitCnt, M16zeroes); + nrzeroes &= 15; + } + stbiw__jpg_calcBits(DU[i], bits); + stbiw__jpg_writeBits(s, bitBuf, bitCnt, HTAC[(nrzeroes<<4)+bits[1]]); + stbiw__jpg_writeBits(s, bitBuf, bitCnt, bits); + } + if(end0pos != 63) { + stbiw__jpg_writeBits(s, bitBuf, bitCnt, EOB); + } + return DU[0]; +} + +static int stbi_write_jpg_core(stbi__write_context *s, int width, int height, int comp, const void* data, int quality) { + // Constants that don't pollute global namespace + static const unsigned char std_dc_luminance_nrcodes[] = {0,0,1,5,1,1,1,1,1,1,0,0,0,0,0,0,0}; + static const unsigned char std_dc_luminance_values[] = {0,1,2,3,4,5,6,7,8,9,10,11}; + static const unsigned char std_ac_luminance_nrcodes[] = {0,0,2,1,3,3,2,4,3,5,5,4,4,0,0,1,0x7d}; + static const unsigned char std_ac_luminance_values[] = { + 0x01,0x02,0x03,0x00,0x04,0x11,0x05,0x12,0x21,0x31,0x41,0x06,0x13,0x51,0x61,0x07,0x22,0x71,0x14,0x32,0x81,0x91,0xa1,0x08, + 0x23,0x42,0xb1,0xc1,0x15,0x52,0xd1,0xf0,0x24,0x33,0x62,0x72,0x82,0x09,0x0a,0x16,0x17,0x18,0x19,0x1a,0x25,0x26,0x27,0x28, + 0x29,0x2a,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x53,0x54,0x55,0x56,0x57,0x58,0x59, + 0x5a,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6a,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7a,0x83,0x84,0x85,0x86,0x87,0x88,0x89, + 0x8a,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9a,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xb2,0xb3,0xb4,0xb5,0xb6, + 0xb7,0xb8,0xb9,0xba,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,0xd8,0xd9,0xda,0xe1,0xe2, + 0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xea,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa + }; + static const unsigned char std_dc_chrominance_nrcodes[] = {0,0,3,1,1,1,1,1,1,1,1,1,0,0,0,0,0}; + static const unsigned char std_dc_chrominance_values[] = {0,1,2,3,4,5,6,7,8,9,10,11}; + static const unsigned char std_ac_chrominance_nrcodes[] = {0,0,2,1,2,4,4,3,4,7,5,4,4,0,1,2,0x77}; + static const unsigned char std_ac_chrominance_values[] = { + 0x00,0x01,0x02,0x03,0x11,0x04,0x05,0x21,0x31,0x06,0x12,0x41,0x51,0x07,0x61,0x71,0x13,0x22,0x32,0x81,0x08,0x14,0x42,0x91, + 0xa1,0xb1,0xc1,0x09,0x23,0x33,0x52,0xf0,0x15,0x62,0x72,0xd1,0x0a,0x16,0x24,0x34,0xe1,0x25,0xf1,0x17,0x18,0x19,0x1a,0x26, + 0x27,0x28,0x29,0x2a,0x35,0x36,0x37,0x38,0x39,0x3a,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x53,0x54,0x55,0x56,0x57,0x58, + 0x59,0x5a,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6a,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7a,0x82,0x83,0x84,0x85,0x86,0x87, + 0x88,0x89,0x8a,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9a,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xb2,0xb3,0xb4, + 0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,0xd8,0xd9,0xda, + 0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xea,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa + }; + // Huffman tables + static const unsigned short YDC_HT[256][2] = { {0,2},{2,3},{3,3},{4,3},{5,3},{6,3},{14,4},{30,5},{62,6},{126,7},{254,8},{510,9}}; + static const unsigned short UVDC_HT[256][2] = { {0,2},{1,2},{2,2},{6,3},{14,4},{30,5},{62,6},{126,7},{254,8},{510,9},{1022,10},{2046,11}}; + static const unsigned short YAC_HT[256][2] = { + {10,4},{0,2},{1,2},{4,3},{11,4},{26,5},{120,7},{248,8},{1014,10},{65410,16},{65411,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {12,4},{27,5},{121,7},{502,9},{2038,11},{65412,16},{65413,16},{65414,16},{65415,16},{65416,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {28,5},{249,8},{1015,10},{4084,12},{65417,16},{65418,16},{65419,16},{65420,16},{65421,16},{65422,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {58,6},{503,9},{4085,12},{65423,16},{65424,16},{65425,16},{65426,16},{65427,16},{65428,16},{65429,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {59,6},{1016,10},{65430,16},{65431,16},{65432,16},{65433,16},{65434,16},{65435,16},{65436,16},{65437,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {122,7},{2039,11},{65438,16},{65439,16},{65440,16},{65441,16},{65442,16},{65443,16},{65444,16},{65445,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {123,7},{4086,12},{65446,16},{65447,16},{65448,16},{65449,16},{65450,16},{65451,16},{65452,16},{65453,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {250,8},{4087,12},{65454,16},{65455,16},{65456,16},{65457,16},{65458,16},{65459,16},{65460,16},{65461,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {504,9},{32704,15},{65462,16},{65463,16},{65464,16},{65465,16},{65466,16},{65467,16},{65468,16},{65469,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {505,9},{65470,16},{65471,16},{65472,16},{65473,16},{65474,16},{65475,16},{65476,16},{65477,16},{65478,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {506,9},{65479,16},{65480,16},{65481,16},{65482,16},{65483,16},{65484,16},{65485,16},{65486,16},{65487,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {1017,10},{65488,16},{65489,16},{65490,16},{65491,16},{65492,16},{65493,16},{65494,16},{65495,16},{65496,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {1018,10},{65497,16},{65498,16},{65499,16},{65500,16},{65501,16},{65502,16},{65503,16},{65504,16},{65505,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {2040,11},{65506,16},{65507,16},{65508,16},{65509,16},{65510,16},{65511,16},{65512,16},{65513,16},{65514,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {65515,16},{65516,16},{65517,16},{65518,16},{65519,16},{65520,16},{65521,16},{65522,16},{65523,16},{65524,16},{0,0},{0,0},{0,0},{0,0},{0,0}, + {2041,11},{65525,16},{65526,16},{65527,16},{65528,16},{65529,16},{65530,16},{65531,16},{65532,16},{65533,16},{65534,16},{0,0},{0,0},{0,0},{0,0},{0,0} + }; + static const unsigned short UVAC_HT[256][2] = { + {0,2},{1,2},{4,3},{10,4},{24,5},{25,5},{56,6},{120,7},{500,9},{1014,10},{4084,12},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {11,4},{57,6},{246,8},{501,9},{2038,11},{4085,12},{65416,16},{65417,16},{65418,16},{65419,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {26,5},{247,8},{1015,10},{4086,12},{32706,15},{65420,16},{65421,16},{65422,16},{65423,16},{65424,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {27,5},{248,8},{1016,10},{4087,12},{65425,16},{65426,16},{65427,16},{65428,16},{65429,16},{65430,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {58,6},{502,9},{65431,16},{65432,16},{65433,16},{65434,16},{65435,16},{65436,16},{65437,16},{65438,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {59,6},{1017,10},{65439,16},{65440,16},{65441,16},{65442,16},{65443,16},{65444,16},{65445,16},{65446,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {121,7},{2039,11},{65447,16},{65448,16},{65449,16},{65450,16},{65451,16},{65452,16},{65453,16},{65454,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {122,7},{2040,11},{65455,16},{65456,16},{65457,16},{65458,16},{65459,16},{65460,16},{65461,16},{65462,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {249,8},{65463,16},{65464,16},{65465,16},{65466,16},{65467,16},{65468,16},{65469,16},{65470,16},{65471,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {503,9},{65472,16},{65473,16},{65474,16},{65475,16},{65476,16},{65477,16},{65478,16},{65479,16},{65480,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {504,9},{65481,16},{65482,16},{65483,16},{65484,16},{65485,16},{65486,16},{65487,16},{65488,16},{65489,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {505,9},{65490,16},{65491,16},{65492,16},{65493,16},{65494,16},{65495,16},{65496,16},{65497,16},{65498,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {506,9},{65499,16},{65500,16},{65501,16},{65502,16},{65503,16},{65504,16},{65505,16},{65506,16},{65507,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {2041,11},{65508,16},{65509,16},{65510,16},{65511,16},{65512,16},{65513,16},{65514,16},{65515,16},{65516,16},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}, + {16352,14},{65517,16},{65518,16},{65519,16},{65520,16},{65521,16},{65522,16},{65523,16},{65524,16},{65525,16},{0,0},{0,0},{0,0},{0,0},{0,0}, + {1018,10},{32707,15},{65526,16},{65527,16},{65528,16},{65529,16},{65530,16},{65531,16},{65532,16},{65533,16},{65534,16},{0,0},{0,0},{0,0},{0,0},{0,0} + }; + static const int YQT[] = {16,11,10,16,24,40,51,61,12,12,14,19,26,58,60,55,14,13,16,24,40,57,69,56,14,17,22,29,51,87,80,62,18,22, + 37,56,68,109,103,77,24,35,55,64,81,104,113,92,49,64,78,87,103,121,120,101,72,92,95,98,112,100,103,99}; + static const int UVQT[] = {17,18,24,47,99,99,99,99,18,21,26,66,99,99,99,99,24,26,56,99,99,99,99,99,47,66,99,99,99,99,99,99, + 99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99}; + static const float aasf[] = { 1.0f * 2.828427125f, 1.387039845f * 2.828427125f, 1.306562965f * 2.828427125f, 1.175875602f * 2.828427125f, + 1.0f * 2.828427125f, 0.785694958f * 2.828427125f, 0.541196100f * 2.828427125f, 0.275899379f * 2.828427125f }; + + int row, col, i, k, subsample; + float fdtbl_Y[64], fdtbl_UV[64]; + unsigned char YTable[64], UVTable[64]; + + if(!data || !width || !height || comp > 4 || comp < 1) { + return 0; + } + + quality = quality ? quality : 90; + subsample = quality <= 90 ? 1 : 0; + quality = quality < 1 ? 1 : quality > 100 ? 100 : quality; + quality = quality < 50 ? 5000 / quality : 200 - quality * 2; + + for(i = 0; i < 64; ++i) { + int uvti, yti = (YQT[i]*quality+50)/100; + YTable[stbiw__jpg_ZigZag[i]] = (unsigned char) (yti < 1 ? 1 : yti > 255 ? 255 : yti); + uvti = (UVQT[i]*quality+50)/100; + UVTable[stbiw__jpg_ZigZag[i]] = (unsigned char) (uvti < 1 ? 1 : uvti > 255 ? 255 : uvti); + } + + for(row = 0, k = 0; row < 8; ++row) { + for(col = 0; col < 8; ++col, ++k) { + fdtbl_Y[k] = 1 / (YTable [stbiw__jpg_ZigZag[k]] * aasf[row] * aasf[col]); + fdtbl_UV[k] = 1 / (UVTable[stbiw__jpg_ZigZag[k]] * aasf[row] * aasf[col]); + } + } + + // Write Headers + { + static const unsigned char head0[] = { 0xFF,0xD8,0xFF,0xE0,0,0x10,'J','F','I','F',0,1,1,0,0,1,0,1,0,0,0xFF,0xDB,0,0x84,0 }; + static const unsigned char head2[] = { 0xFF,0xDA,0,0xC,3,1,0,2,0x11,3,0x11,0,0x3F,0 }; + const unsigned char head1[] = { 0xFF,0xC0,0,0x11,8,(unsigned char)(height>>8),STBIW_UCHAR(height),(unsigned char)(width>>8),STBIW_UCHAR(width), + 3,1,(unsigned char)(subsample?0x22:0x11),0,2,0x11,1,3,0x11,1,0xFF,0xC4,0x01,0xA2,0 }; + s->func(s->context, (void*)head0, sizeof(head0)); + s->func(s->context, (void*)YTable, sizeof(YTable)); + stbiw__putc(s, 1); + s->func(s->context, UVTable, sizeof(UVTable)); + s->func(s->context, (void*)head1, sizeof(head1)); + s->func(s->context, (void*)(std_dc_luminance_nrcodes+1), sizeof(std_dc_luminance_nrcodes)-1); + s->func(s->context, (void*)std_dc_luminance_values, sizeof(std_dc_luminance_values)); + stbiw__putc(s, 0x10); // HTYACinfo + s->func(s->context, (void*)(std_ac_luminance_nrcodes+1), sizeof(std_ac_luminance_nrcodes)-1); + s->func(s->context, (void*)std_ac_luminance_values, sizeof(std_ac_luminance_values)); + stbiw__putc(s, 1); // HTUDCinfo + s->func(s->context, (void*)(std_dc_chrominance_nrcodes+1), sizeof(std_dc_chrominance_nrcodes)-1); + s->func(s->context, (void*)std_dc_chrominance_values, sizeof(std_dc_chrominance_values)); + stbiw__putc(s, 0x11); // HTUACinfo + s->func(s->context, (void*)(std_ac_chrominance_nrcodes+1), sizeof(std_ac_chrominance_nrcodes)-1); + s->func(s->context, (void*)std_ac_chrominance_values, sizeof(std_ac_chrominance_values)); + s->func(s->context, (void*)head2, sizeof(head2)); + } + + // Encode 8x8 macroblocks + { + static const unsigned short fillBits[] = {0x7F, 7}; + int DCY=0, DCU=0, DCV=0; + int bitBuf=0, bitCnt=0; + // comp == 2 is grey+alpha (alpha is ignored) + int ofsG = comp > 2 ? 1 : 0, ofsB = comp > 2 ? 2 : 0; + const unsigned char *dataR = (const unsigned char *)data; + const unsigned char *dataG = dataR + ofsG; + const unsigned char *dataB = dataR + ofsB; + int x, y, pos; + if(subsample) { + for(y = 0; y < height; y += 16) { + for(x = 0; x < width; x += 16) { + float Y[256], U[256], V[256]; + for(row = y, pos = 0; row < y+16; ++row) { + // row >= height => use last input row + int clamped_row = (row < height) ? row : height - 1; + int base_p = (stbi__flip_vertically_on_write ? (height-1-clamped_row) : clamped_row)*width*comp; + for(col = x; col < x+16; ++col, ++pos) { + // if col >= width => use pixel from last input column + int p = base_p + ((col < width) ? col : (width-1))*comp; + float r = dataR[p], g = dataG[p], b = dataB[p]; + Y[pos]= +0.29900f*r + 0.58700f*g + 0.11400f*b - 128; + U[pos]= -0.16874f*r - 0.33126f*g + 0.50000f*b; + V[pos]= +0.50000f*r - 0.41869f*g - 0.08131f*b; + } + } + DCY = stbiw__jpg_processDU(s, &bitBuf, &bitCnt, Y+0, 16, fdtbl_Y, DCY, YDC_HT, YAC_HT); + DCY = stbiw__jpg_processDU(s, &bitBuf, &bitCnt, Y+8, 16, fdtbl_Y, DCY, YDC_HT, YAC_HT); + DCY = stbiw__jpg_processDU(s, &bitBuf, &bitCnt, Y+128, 16, fdtbl_Y, DCY, YDC_HT, YAC_HT); + DCY = stbiw__jpg_processDU(s, &bitBuf, &bitCnt, Y+136, 16, fdtbl_Y, DCY, YDC_HT, YAC_HT); + + // subsample U,V + { + float subU[64], subV[64]; + int yy, xx; + for(yy = 0, pos = 0; yy < 8; ++yy) { + for(xx = 0; xx < 8; ++xx, ++pos) { + int j = yy*32+xx*2; + subU[pos] = (U[j+0] + U[j+1] + U[j+16] + U[j+17]) * 0.25f; + subV[pos] = (V[j+0] + V[j+1] + V[j+16] + V[j+17]) * 0.25f; + } + } + DCU = stbiw__jpg_processDU(s, &bitBuf, &bitCnt, subU, 8, fdtbl_UV, DCU, UVDC_HT, UVAC_HT); + DCV = stbiw__jpg_processDU(s, &bitBuf, &bitCnt, subV, 8, fdtbl_UV, DCV, UVDC_HT, UVAC_HT); + } + } + } + } else { + for(y = 0; y < height; y += 8) { + for(x = 0; x < width; x += 8) { + float Y[64], U[64], V[64]; + for(row = y, pos = 0; row < y+8; ++row) { + // row >= height => use last input row + int clamped_row = (row < height) ? row : height - 1; + int base_p = (stbi__flip_vertically_on_write ? (height-1-clamped_row) : clamped_row)*width*comp; + for(col = x; col < x+8; ++col, ++pos) { + // if col >= width => use pixel from last input column + int p = base_p + ((col < width) ? col : (width-1))*comp; + float r = dataR[p], g = dataG[p], b = dataB[p]; + Y[pos]= +0.29900f*r + 0.58700f*g + 0.11400f*b - 128; + U[pos]= -0.16874f*r - 0.33126f*g + 0.50000f*b; + V[pos]= +0.50000f*r - 0.41869f*g - 0.08131f*b; + } + } + + DCY = stbiw__jpg_processDU(s, &bitBuf, &bitCnt, Y, 8, fdtbl_Y, DCY, YDC_HT, YAC_HT); + DCU = stbiw__jpg_processDU(s, &bitBuf, &bitCnt, U, 8, fdtbl_UV, DCU, UVDC_HT, UVAC_HT); + DCV = stbiw__jpg_processDU(s, &bitBuf, &bitCnt, V, 8, fdtbl_UV, DCV, UVDC_HT, UVAC_HT); + } + } + } + + // Do the bit alignment of the EOI marker + stbiw__jpg_writeBits(s, &bitBuf, &bitCnt, fillBits); + } + + // EOI + stbiw__putc(s, 0xFF); + stbiw__putc(s, 0xD9); + + return 1; +} + +STBIWDEF int stbi_write_jpg_to_func(stbi_write_func *func, void *context, int x, int y, int comp, const void *data, int quality) +{ + stbi__write_context s = { 0 }; + stbi__start_write_callbacks(&s, func, context); + return stbi_write_jpg_core(&s, x, y, comp, (void *) data, quality); +} + + +#ifndef STBI_WRITE_NO_STDIO +STBIWDEF int stbi_write_jpg(char const *filename, int x, int y, int comp, const void *data, int quality) +{ + stbi__write_context s = { 0 }; + if (stbi__start_write_file(&s,filename)) { + int r = stbi_write_jpg_core(&s, x, y, comp, data, quality); + stbi__end_write_file(&s); + return r; + } else + return 0; +} +#endif + +#endif // STB_IMAGE_WRITE_IMPLEMENTATION + +/* Revision history + 1.16 (2021-07-11) + make Deflate code emit uncompressed blocks when it would otherwise expand + support writing BMPs with alpha channel + 1.15 (2020-07-13) unknown + 1.14 (2020-02-02) updated JPEG writer to downsample chroma channels + 1.13 + 1.12 + 1.11 (2019-08-11) + + 1.10 (2019-02-07) + support utf8 filenames in Windows; fix warnings and platform ifdefs + 1.09 (2018-02-11) + fix typo in zlib quality API, improve STB_I_W_STATIC in C++ + 1.08 (2018-01-29) + add stbi__flip_vertically_on_write, external zlib, zlib quality, choose PNG filter + 1.07 (2017-07-24) + doc fix + 1.06 (2017-07-23) + writing JPEG (using Jon Olick's code) + 1.05 ??? + 1.04 (2017-03-03) + monochrome BMP expansion + 1.03 ??? + 1.02 (2016-04-02) + avoid allocating large structures on the stack + 1.01 (2016-01-16) + STBIW_REALLOC_SIZED: support allocators with no realloc support + avoid race-condition in crc initialization + minor compile issues + 1.00 (2015-09-14) + installable file IO function + 0.99 (2015-09-13) + warning fixes; TGA rle support + 0.98 (2015-04-08) + added STBIW_MALLOC, STBIW_ASSERT etc + 0.97 (2015-01-18) + fixed HDR asserts, rewrote HDR rle logic + 0.96 (2015-01-17) + add HDR output + fix monochrome BMP + 0.95 (2014-08-17) + add monochrome TGA output + 0.94 (2014-05-31) + rename private functions to avoid conflicts with stb_image.h + 0.93 (2014-05-27) + warning fixes + 0.92 (2010-08-01) + casts to unsigned char to fix warnings + 0.91 (2010-07-17) + first public release + 0.90 first internal release +*/ + +/* +------------------------------------------------------------------------------ +This software is available under 2 licenses -- choose whichever you prefer. +------------------------------------------------------------------------------ +ALTERNATIVE A - MIT License +Copyright (c) 2017 Sean Barrett +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +------------------------------------------------------------------------------ +ALTERNATIVE B - Public Domain (www.unlicense.org) +This is free and unencumbered software released into the public domain. +Anyone is free to copy, modify, publish, use, compile, sell, or distribute this +software, either in source code form or as a compiled binary, for any purpose, +commercial or non-commercial, and by any means. +In jurisdictions that recognize copyright laws, the author or authors of this +software dedicate any and all copyright interest in the software to the public +domain. We make this dedication for the benefit of the public at large and to +the detriment of our heirs and successors. We intend this dedication to be an +overt act of relinquishment in perpetuity of all present and future rights to +this software under copyright law. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +------------------------------------------------------------------------------ +*/ diff --git a/disks/Games1MB.po b/disks/Games1MB.po new file mode 100644 index 0000000..108ce68 Binary files /dev/null and b/disks/Games1MB.po differ diff --git a/disks/dos33master.nib b/disks/dos33master.nib new file mode 100644 index 0000000..1b07a38 --- /dev/null +++ b/disks/dos33master.nib @@ -0,0 +1 @@ +ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþªªªªÿþÞªëÿÿÿÿÿÿÕª­¶ÛÜôó»½Ï—š®®–­¬š«—²²­«š›«Ÿ—³š³ž—Ÿ³–¬®§š²–­¬›²¦—Ÿ¯¬§«—Ÿ¦ž—ž§¯ž®ž®Ÿ›—›²¯³®¬š³²¬§¬—««ºôê­žåÖûíõïìÚ½–––´ïµëÜýõë«ê¹ý¾Ûý×Íýå¹ý²«æüµÚëü®ýå¹ýÚßú®ýçÚµ¹³ûýùý¬æÎöéËö›ô¼ÚµÛýš›—–›–—–›–—–›–—››§µ´Üëßææ«ó¿åóû¿üÏÞýÙü¿îþù¹Ùùóû¹ÙÞæÚó¿Ïïìê®ÙžÙÚ—ïïË®¼ÖéßüÛîöšôëæüõ³Ûÿšöò«ëýÞ×¼Íó¿ù«ý––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––¯³šÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþªªª«ÿÿÞªëÿÿÿÿÿÿÕª­§éÝ–¶ôܞι§÷󮟮¬——çù¶Ûì¬×ÙšµºÛæïÏÞ—®ÛݲÛþ¬´´Î¯ééÖܦÚÜš»§½–¿¬´ÖÛ´¾«²®¬ßÛ¦›§¯×õÍ¿½¯³²×òòòúßÚÎÿååÙÎÿåßéþ÷šçöÝëúÛíþþ÷í§õõý®·½æê®·¦¹·«Ó»¬Ûíž®·Ó®·½æê®·Ù§§§ùÎÿõ¹·óÙ»³ù꯶½åêþóç¯ïšïõ«ºßéÚëíùßéþúéíÝëýÜõ½Ùßš½þÜ믶Íé쯶幦§õõæ嫧²é»¬ººÿååêþ¿Ï¾žþíê÷º¦çéÝ»­ŸßÜ«ßܧ¹çìþëæÛòý殽ë駧²ÝÛìýÓæºÿ«¾ÓæêúêÓž÷¼ôÓ·÷ï´êæü¯ÿýõÖçÙÎÿçæ§Ï¾º¶Ï¾ÍüÖÝÙ÷êÓýûéôÓ·óëêæºå¯ÿ—ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþªª«ªþþÞªëÿÿÿÿÿÿÕª­¾´íé–¦¦´Üæ¼óü–óß·Óó糦Ÿµ—žË·ç§ëÙ»úîù÷Ý¿¦¾«–Öק˟êê´óö®¶Úåºïô¼›×¯½¶Ü²«·¼Î½«®–ž®®Ü毫¹»¬æßÚöÏùÓÝþïóµöÏ÷µóÎ×üÎêÞ–ú¾óÎ÷µ¼å²Öóôµ¼çößÚöϾúëìßÚöÏ÷µÓýæ¦ÝõÜêÚžÍܦÝþó§ÓÏ·þÓ´ý;»šôµ¼ôççÙöÏš­¬¿ô×óÓÝõη´Ï–¹åÙöÏþ®¶æÚöÏõôÚæÚ²ÞšÍϾÛþÙç–òÓÝõþß«–Ú–ßßÚôÍÖúÛôçëíóæÙ›ÍÎõÿ­Ýå³ùõÛóÎåôÍåôÍšÍÏ×ýÍé¯üÎ×ýÍ×ýÍ»›»¯æ«íÙõì¼ÍóÎ÷µû¶îéÎÙßšêì–òÓÝþóú¾óΚ×ךº«öç÷íþü¿½Ý½õõóݳçþ—ôÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþªª««þÿÞªëÿÿÿÿÿÿÕª­–ßí½ßéÛí¹éÛÛ¹üßß–Öí´éé–®®½í÷÷§ÖÛÛ––½–§÷÷§®¹§ß§éÛߧ§–§––§§–––§®––§––§§®®®®–§§§––§®–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––²×®·Ó®·üËýº½·¦¹·Ù§¶÷ÿ¦÷ÿß·¦¹·¬½»§»ÓýýúÜ–ÙýúܳêýúÝù½ùþÝ÷¾ùþÝݦùþÝù—––ÏΖ·²ß·Ó®·æ½ßÙýúÜÎÿýúÜ–ÙýúÜ´ïýú«å®·Ó®·ß¬–·²ß·¦¹·æÖ––÷ß´–ߧý·¦¹·ß½–––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþªªª®ÿúÞªëÿÿÿÿÿÿÕª­¿ßûÍžûܹ¦¦«»ý§û¯—Ÿåþõí¬­ží¬ëÛçÛê×ëνÜ뾦¦Ïû믷¯ºúû«ßºÍßïò¯Ó›¼ÝêËîú§ûßùôËžëÎóÙ²¹öýïÞú¼÷õù»¦ÝåõÓšýüÙ¦Ýõþ´¿ìë·ïßÛó½ÏÓÙüÎþüÖÚÛû·Ö·óïõù»ÿ·ÛÓü¶û¬Ïýçÿ·ÛÓüæçôôæò¶õýÙóξòß´­üß¹ïݹéô¾þÖÝßéßÓòËú×Ëú¶­¦Ïí–åžßê¬Ýéžåé¬Ýé¬ÝÝÝöüòéÿÏõù¼ùüÎëë´»®·¿–—ïýëÖÚïüëצÝõü§ßåÚæÚöÏšÝå³ÝåÛóÎåô;ÿçͺ²§üòéÿϧߞ盺ý盺ùüζûóÎåôÍåôÍÛ¹–¾ôÍÙßìûÏìßÿõúÝòŸÞõü·¯¾éÿÏõþíη×éýíô«ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþªªª¯ÿûÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþªª«®þúÞªëÿÿÿÿÿÿÕª­ÞÞæû³›ÓÚÏÏ——žö½ùÿ–Óîþ²¶š××­çò·Ù›Þžºþ쮦ì×ßå×ôžûòË´í—ýÏïÿÍúÝ«Üÿ½Ú§ù—«µì·µ—³–í´ïÚÿ¦Îê·«ýòÞÞßß¿¼ë붶¬ŸßÚöý››³³®®··ÓÓË˹¿¯¯éêüýïïµ´¹¹ººïï²³÷÷¬¬þþ×Öêêßß·¶ž¦¦šš››ÍÍ»¼ëëžÓÓçç¼¼žö›íî–÷÷÷÷÷–¯ö›íî–÷÷÷÷¦õõõ´ìõ÷öú««ó§§§´ÎÜݧ®ÿÿßµöÓ–––îù´×µöëù´×ç÷æ¿üíÞ²ÞÙæêöÓÖï¶ôŸ«ëüßêúò²ÞÙçéôÎÖï¶ôŸ«òÙßìŸÞþôçÙüô›ŸžçùËÛܳ¬ÍÏÖæÚóÎåöÏ–´ùöÏŸ®Ë®´Í®´žŸšÜ²ÞÙçéï¿Öï¶ôŸ«ºìß­ë¬ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþªª«¯þûÞªëÿÿÿÿÿÿÕª­ºçÿåëç÷åýßþçõ®æüßþæ÷½ßôÚïßüÛóéüÜ÷ŸÝöÏß÷Ö÷êÝÙëµÞïÙïéÿšìþëïçïìþ—ìïÚúçúÍåÓïßþÝù³æÿæöëîçþ¯ÙéõŸ­ŸßÜóùßÓóúó§Û½®Ÿ›—³––––––˼š—³–––––––Ù–›–—––²–›—–––¦–—–––›––—–––Η––¦—–›––—–––²––›––—–––¦–—–––›––—–––¹üÎïÿûýåßÚó¿ºïºÍÎÿÙÖò·ÖòÚ½ôºÙë¿óë¾öÚ¯žæÓ®·®–––Ý–Ý–ÞÝ––å–––—–ߛߖ–ß––—–ì–ì–¦–––æç–––›––õ–––—–––›––óôó––ò––òï–ý–þþ–—–––›ï–––—ò––íî–––¦––í–í—–––›íí––—–––³ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþªª®ªûþÞªëÿÿÿÿÿÿÕª­´›—µ×½úš¬Í½ÚܲŸÏ¿Þ겚Ùçê®ë¦žÛ§åÍÓ³¶·žå–×ýéÏÿûšÙççú¶›ÞÙõõ»Ù¬²»ìÓ¬¿–·Ó³ÎӼ˶š·¼³¹§½´Ö–ߧ۳—Üëîûó½Ü›îúæ×îîîúŸüóóÙŸ¬¯·Þûýí×××۳ߟ¶²«¦¶¶µµµµÏÏÏÏÍÍË˾¾½½½½ÞÞöúôôòóööõõî––––––––––§åÝÝçôôìåË¿ôô½¿÷÷³²¬¬¹¹çç²³ÜÜýýíí§¼´–§§§ö––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÿÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþªª®«ûÿÞªëÿÿÿÿÿÿÕª­´íÛ¯å´íéöÎõôôμ洖¯Ü¯ô®¹§çô»¾îîÿæ³ìé«—´ü³ý¿—¾öÎï®é›¯¦ùµ–ÓŸ®¹öî³¾´Öéé¹×î´ÛùÛ¯Óåï–®¦«§¬Ù›ßÝ®·óúß»²ÞÖìݳû³¿ßÝ®·óúß»²ÞÖìݲüŸ³¹®·óú§õ²úíç®·óú®ž›õ÷º®·óú®½»ç¾»í¼ÏßûŸô÷íô–·®·óú®¦—§Ÿº®·óú®½Ï§¹ßì®·óú®¼µ¯·æ×ßÝ®·óúóçßÝ®·óúö–ìê­µ½çÝý·Ï¾š®·óú®ž›Óµº®·óú®½ÏÎìÏùçççùêÓýßþæ×ßÙôÓÖߦöòõíÖê·êÜÓÜÜËÜ®êÓí÷êÛåÖûîìéæÛŸòôÖ欟§²ÞÖ³²óïÖå«Ÿ§²öíý÷§²§êôÓ­¬¬­­Öž³´¾Ú¶½–––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþªª¯ªúþÞªëÿÿÿÿÿÿÕª­–§þÛ¾¾´ò¾ýºÖßÙ»þç¯õËÚÚ—¶¶šõõ˾æ²ßÞö¹«·ú·ù®Û«µùëֳ羿ÞêæçÚÚžš²ú·ö·¯ÙšÖ­ÚÚ쮬º³¶ç껿ßÝŸ–·ïÝêž²î÷ß×î÷ßß÷îßìö½ßßìõ–íí×÷ýôòŸ³¦ýí×Û®µù¿ý»îîî÷÷šòßìö½ßßìõ–íí×÷ýõퟳ¶ù¬«¦¶ÍúíùùÙµü½«ßÎÛ½Ûü½«ôܾûËü½éô¾ÛÖêêÛîÓÞ­šîÓÜß×îÿܯêžÜ¯Ýî›öÙ–æü­½ÚóÙŸóùåÙŸóùåùùÞü®ÚÎÓµý¯ÚÍ¿ÛÍËçµî¯Ú»¿ßÚçÚùµÝîÿùµÝî÷ßß÷½çμÙûíóíßüÚê¾ÚÝîê¾ç꿽ÚóÏÞÙ¶«îîú澫îîû®çûÖ´Ú¼¿ùÞÖ´Úº·ÛÍËçµêµ¦ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþªª¯«úÿÞªëÿÿÿÿÿÿÕª­×¾üž—Ùû´ß×–—–žëŸçÚßž—¬³µ®–½ô·ßú߶—µ²¹¯µþúͫ϶ýšç«ß–¬úͲڦµý׳šúÍü;ιíÖ§²õ´–ßõÍÙ–ßßßßÙ²ÚÎγ³Îγ³åݲóšêîÓ·ßݶ²¶ýú쳞žßÞ³ýõùÜ»ìßæýÓë®·Ó®·ü·óç³ëßÚº½·ö۷٧ֶ巧¶ÝÖ黬¹ÓýÝÖÛ–ÙÝÖÛ—ÚÝÖß²ý×óëë³¾åîÛžÜÞÖë·Ó®·¶»²·Öò黲۞ÜÜôÓÝ·Ó®·Ïë²üŸ²´žÜÞÖ—ÝÖÛÎÿÝÖÛ–ÙÝÖÛ´ïÝÖÛºöÝÖ×®·Ó®·ßϹ§ý·öÛ·ßíßßýÞþï´ë²¾¼³žÎ¼³žëçý›÷ý²ÙíÖæÏÛö®·óúéÞ—«¦º®·óú®½Ï§¹ýú®·óú®¾Ó¯·æÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþªª®®ûúÞªëÿÿÿÿÿÿÕª­­›–ššš–š§¬¬––Ù¿¿¾Ë´´îµ»»¾¾½çòùåüžÖÙžêåæÖÖ–›¼¦¾¬þ϶ÖúÚËü¯ù¶Ÿö§ÿûßӦͭ–ܯֶ¿Öæ²ì¯Í¬ÙÖ¶ï–õïÙÜåçÞõÍׯ¶ßïæ×ëÞ§¹óå÷¾Î¿Úõ¶šÙôÖõÝÝýõÖÓ·çÙëÜÝìýÓÞ®ÜêÝú¼÷¾åë¦åë¦åëΧֽ»§ó¾ÓÙÛ×ÙöùìëôÖ÷÷çú×íÚòê߬»´¾ÓÙê«ÿùæÚóêÓô§ó¾ÓÙëçÙùîöô«ÿù榴êÓô²ó»îÙÜÜ›ûκ¾®Üþþ­õË÷Üõç÷ÚõÖΧÖÖּϽ––––––––––––––––›—–›–—–›–—–›–—›­é˹­´Ë­´¿æÚÚ÷íº·ÎšÍëû¶åÿ»åÿ»¶´ÏÓæ²Þ¶´¼¹Ö¯ææ믯ݯžæÝßµïê®ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþªª®¯ûûÞªëÿÿÿÿÿÿÕª­ÎöµÝúÍôóü²­¯¦æåïöž®¯«³ìëÚžŸ¶¹êÚÞ÷·–šžºÍÍšöëß–Öó½³ïõ²üïÏÖíòí¶ïæÖÝ®›ü³ûŸ³åÞ®—¯é쬖׺ü¯«žé¾öëÏíÞæÚÎòë¾öÝ·ôëËôÞæÚ½õÞçÙ½õݶóì—ÓîÞæÚÏíìí–––÷–æÞ¾ÿÝùÓ«éåܼ¾ž¾öÏ×ý¦æÎé·Ÿê¶ó›ô¦îëËôݶóëÓîþ³îÞæÚ½õÞçÙ½õÞæÚÏížéåݶóëÍï­Í½×ÓîÞß×Ëô›óúÚÍïë½õžé庽–––––ç¶óݶóžÜÖÝ´õìÝžåçù–«§õë½õþ³îþ­ôù›ì¿Í»§³Ú鬮϶»òÙëÓîÞæÚÓîݺòÓê;öºïææ²óÙŸ¬Ý½ŸŸšüö¯¯¯½½–––þò¯––––––½½––––û¯õ–ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþªª¯®úúÞªëÿÿÿÿÿÿÕª­§¬šžô¶æÖ§ôîﻼþåÚÜÙ´¬ý¦ºòë÷í–¿ùìæï÷æÙ¬®Ý§¿¬·å´¶ì¦§ÖÖÖßéÖµµ×Ü×Ö—ÜêåžšëßÛ–ŸŸ¿¿ßÖßµî®ü¯ž²ßíú¿¾—ÎòïÎ÷ÛÞßéþ–ûÙÚçÞõ§ÝþòúöýçÙü®´åêþ÷–×þúÿµìëÚ³ÿù®ë³åÙß×ß—÷þܺÿ¦³¦ÝçÞõý¯¶ß´šæ½»ëß¼åúßéÚº–þÝ–¬¶ºÍ¯Ó¾ùçšçé×íÓ§—®ë´ÿÙýÓßÚ›—¯Þ½ÿžÝ÷Ó¶ûÝéí–––÷ï¬úßéþ§›¹žç麽­—¯Þ½ÿžÝ÷Ó¾íßéþòîú–­ëÞýÿæ×íö¾î黬½Ý²é»¬¹þÍêæÜÖçí÷÷¾Ï¾¦­®ÜßëÜÚÝìýÓ³ýêÓýú²¾ÓÙµ¹Ùÿ§óÿùÙ¼šß÷÷ÚúéÛÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþªª¯¯úûÞªëÿÿÿÿÿÿÕª­ææùò›üôÚÚíÿýéöçé²—êÓÍ­²¾Ëí×½šÙô¼¶¯º¾üæÚ³óíëÏ÷î³ýé¾ý«ùµ›ù»ŸüÍšÙÙ￧ß÷ÝÝ×óžúïÿÿ§÷î×úëÍ­Öç–òÓÝõü·úëéç–ïµ¼ô«ÏÓ¿õÙ¹Ù÷¬¹Î×üΚÓÏêÞåæ²®§õýçå´Þýùîôó×êÝÙŸ®§õÛ´êꬬ××óûžÝܯ®··§¶«žÏ–ééóÿÜû¼÷šÿç½óééü¬óþößüÎÖ묮§õÿçìžõŸ¾³ë÷¿¹÷ìõ¼÷¿ÍÝùüÎÖ¿þ®§õü­Í·§ÖÞÜš²û¼ß»¬Ýûþ¼Ö寮§õô—ÝÝÛçêÏîýüßßìüÎÖß®®§õýùúëÓ¼ÝÖ»õßæ·Þý¿Ù÷ÚæÚú·åþ¼åú·å÷µå÷µšÿ÷ÛüΚ××üòôµ¼«»üÎ×ï·¯ž§Îº§þ´³çÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª«ªªÿÿÞªëÿÿÿÿÿÿÕª­òú×צ¾þ÷ûì—¹µÖÚæææšì¯ÖéÜ禦¬¦Î÷Þ¦ßç´–µå«ë–²êڲܮíºæÖÏõæ¿üéæ–Ý®Íþæ»ÿòûÜÝݯ겫—Ùüô¬ºÍ§—¾¶õ×þû¶åóÎþ›ÓæôÞ¿õýòŸ¬šµšý½ŸÎ¶¿·åú·÷µú·šÝÝۛ﷧–ß›÷Üõç÷ÞÚÓ리÷ÞÖÍëÝõ¹«÷ÞÚÓëÛó«»ò¶þµ›ó÷›÷öÿ·Ú÷öÿ·¾åï¿÷¬Ú¿·åú·´´ºÍϼåþ¼þ²ŸËìßßËòÞ³ÏÓ—ÚÚÚüÎÖžß–ºýß–º¬òüÎÜì–ïµÓýû¾óÎ÷¾ò´éé󚮿¹—ÜïæßêÚ§Ú컬Ýïæ×ííí¾×׬í˺òž¾Öû–××üôß÷÷÷¼Ï»ó»Öúíëç³ööµ§û–澧ûÙöö–ööæû§ííöÿ§ííô¼ý»¾´µÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª«ª«ÿþÞªëÿÿÿÿÿÿÕª­Ùõý¯Ùëåßµ®éþëÖåûŸºÙÙµÞÝîÖúöê¬ÝüÎÓõ÷þ¬¬´ÏëÙÖïžÓ¿ë®æ¶ÍÝ¿ÏÞÍýìÓ²æÏúÖëºå¾ç÷¿½éµòõþ»ÿµÙ´®Î—æóï´»óú½ß§Ö»óÙ´ŸóÚç¶õùìí¹óòû»óší½úï»óîî¬ûî›æíË÷æï»óÙ»óûŸÞõþ½ûüüýŸûýýú›šûïï·ßûïï·æîÞýò¦û÷ÞõÓÚÞêõÓ×ç¦ÝìÜç¦ÝìÞÛþïŸû÷ÞõÓÚÛëöÏ×æŸÝéÝæŸÝ麬——ÞÝ–›×ÜžÛÜ—ÝÚššš×Ù–ššÛÙ–›ÙÞŸ––›ÙÙ›–¦ÜÜž—×Ö¦¦×Ü—Ÿ¦Ûܦ¦Ÿ¦¦—ÖÖ¦žÙÚ–žšÙÜžš››Ù×–žž›–ÙÙ–ÖÖ–––ÖÞ–üú—ûû›Ÿ¦›—šÜÜÜÝ—ÝÜžÛ×›–›××¹ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª««ªþÿÞªëÿÿÿÿÿÿÕª­Î¿Ëº¬Úû½¶î–ýéÍׯÖêϵ«é³òúÝéåçóþ§ïþÝÖóö«³žµ¾ŸººÛ–§–ó»šÖ´»ŸõͳÛ×ç—îµ²º×÷éó½ëæ–éÍïÿºûÞ¹–úýž¿ÓÏ®·ÛßüýåßóóßåëÏüéîÿÎÿéþ÷µÍ½´îï×æ§Í½ÝžÛþ÷ë»÷ºòÏ÷—®½´¿¾×æ§Í½Ýô¹þ÷ë»÷ºò¾ÿëÓîݾÿëÓîÝÓùÝÏ÷º¿¬žŸ›¿¾›­§—ÝëåÓùÝÓùÏþÝÚßéüéþß½ÏüúùþÝÖžÚÿòýü²»´¾ÎÛßÛóší«¼îåóš¿Ÿž›ý÷ÜåæÍúåóÙ¾Íúåó¬ííí–æóóææÚ¼ùë»÷žÍ½Ûåêüò¹ú­Îêûë¹úÿÏüò¹ú»êûë¹ú­Ï´îï×æ·¦½Þ¾ÿݽþëÓîëÓîÝÏ÷ÝÏ÷ºïæóóææçËú¬ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª«««þþÞªëÿÿÿÿÿÿÕª­×Þִܻ¶úì¹óÙŸ¬ß¬îúŸæêü´ëõúì½ûºùͻέ¿¬½·–ÚßÖ–çÚ§«—®žÎéï»Û¶š—æç§ÍÏ×åÛŸ§Ö­Ú¬®Û§ßÛΛ¿Ÿ–š¼´ßÖžÖ«û¶Üò»½´Ùßùõéò¶íÖÏÿÚòï·å®ÙÝî´å·ýÝî´å·ýÝæŸÛ·ýÝæŸÛ¶üÛùòí¾Úùòö϶íìåò¼ëóïÝúÝíìçüõ®Þÿšùý«ÜíßÚöÏåö϶ïæ×í¾é꿳º—ëìôû³ÙÚýõçùîí÷ùîíܳ·ìçüÝç¼þ®¿ÝùûÏ»»òç¦éç¦òõæ×Üüéþߧ²üîîîîïúíßéü§ò¦ÝõÿߟÞû×ÛõåŸÞû×éüïæ­Úýîþ§ºÚý«ïïËÞýµ»Üç¦Ýîûç¦ÝîûþÓåû¶ÙßÝšó÷ì«Þùæîìóšûùæúï»óú½ß§ÖïÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª«ª®ÿûÞªëÿÿÿÿÿÿÕª­Ù½—û¬¿š¶®¬¬«íËÙ÷¶Í²í–®Ï´›«–¶Í²––ù—翺óµî›³ÎµçÖ×–ëŸíû­ÜÞí´éŸ§ÖÖ–«Ú´µö»–ŸŸÙÙ¦›ÜÚš­¯¿»§§ý´»óéíþºöéí¾½ËךÖòž––¶ìßÏüžòž½Ýùô›–›–߯ž­ó®·Ý«çò®¹ç÷õ¬­üºìÝç¹íßææ¶û÷ÞÓÜßÖú¼Üêí÷÷çú×í­–¿¶—š¿µ½ëÛòÎÝïë´¬«ÚßÚ¶ü×üõ¶ùÿšûÿ«ûÏ´¬«Úßë¿ùåóÙšûÿ«Ü´ÿýÖç«Ï¿ÞºòÓêÍ·üÝëÞ¾õÝæÚ½öÛÝÛæÞ«Ùõ²¬»çûËÓùêßëŸÛçËíõ½Ýùžåܳ·úݲïõôÚßÙž«Úö²¬õ¾ÎÝëì¼íë–—½õë®Ùë®Ùÿµ½õÞæ§Ï¿ÞÙìë¯ô³Î¿žî§ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª«ª¯ÿúÞªëÿÿÿÿÿÿÕª­¾÷«§žžéïü¿³·»Ÿ–µÛî«Ó¿êËåêÍï¶ùק½÷ﶶ힞ê´ÎÎÚÓû³¹žßÜžÓ­´ž¼ÜÜ·´µ¾ç÷šôüÞݧ¾›¯Î¶î½óüù¶òÞ¬¯¿µšçæôïüµ¼«—ž×´ÓÏÜôïüÎå·ýÞçÙ¯ÚÞæÚ®ÙÏùÚ—ÓÏÜÿùçÙöÏšçæýö­ööÙæòÞÏõ³¾ç¶Þýû¬ÍÛ¬ºüóÎ×ýÍõþíÎì–šÙ¦Þ–·ÿçºùŸÞõÿæóÞŸÿæÜó³­ýËÍÏîÓúïÛ¹»´öö–ÏÓ¿ÿç³ìë—Ë¿ÚæóÍšæÚ¯ÚÞæÚ®ÙžÙÚÙËýºòŸÞçîûŸÞç«­ë×ë¿üÿòýü·¿ÏöåöﶹÝßÚ·ýºïßõõßåöôçåöóæåÖóΚîõÛŸÞõýßÓú³çߧ§«ÙüΚ§«—úô³ÍÏšÓÏÙüÎÖæéé˯µÍËÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª««®þûÞªëÿÿÿÿÿÿÕª­ÿêŸÛ¶Î¯òÙ—þ¹üÞÿ®ûß·ß³¼›´ûÖËòêΖÚëžÝõ¾´Ë÷¿ò¾š÷ûϵ³êÙ®–ËÓÓ½Ÿê›«ç¯Ý¹óíÚ¯»ôô›µ÷Ó›ó곚޳éßž¯ÚÎÿ¦ºÍÛççºÿžž—Ó®·§®Ó®·š–šÜ×Ö¼–šóù«ŸšóϺ¯›š–×®çÚÎÿ«·¯¶Þ®çÚÏüë¼ùæÏóÞº½»üÙÏüë¼ùžž—¬²ÓÍÞÝš­§ÚçÖçÖüͲþþ´ÖÏüúí¶æåÖ®çþ–Ÿ¯¶ÓùÝÏ÷žæåžÙ½üõô½®·šŸÿûÝæßåÝËîÿõúÝ´ÿýÖºÍÎòžôõ×ìÝç›–››–ÚæêÞò¯õùÍíú»íéí¾½Ë››–››–¯²®§ÖûÿßÚçÚÏüîß½Ïú–¦Îÿ«ßš®ëò´Îÿ¦ºöå›–ëéÙ»¬´¦ÜòºšÖòûÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª««¯þúÞªëÿÿÿÿÿÿÕª­çÎÙ¹«Ù³ë³›ÎîÙ–ß盞Óó–ÛìÖž³ö×ÿ¹Ûíé·ôç½òÿûžýû¿ê´»»žþý¹ÓòÞ¾ÿ¿ÝµÞͦ÷÷Ú¯ö¾û­¾—»éå¾Ùïæۛά²ê¼ÜÞ—ýµ¿Ùêê¼ÜÝõ­—–ÚçÙöϾòÞ³—–ÚæÚöϾòÞ³µ´êÜ«ÖÖËÏ—Ë¿Ùï·–­ý÷éßìóµê§Ùÿõù¼ßׯڞÙÚµïú˶·õýæï·þôçºÍú·×ßÛ®ÙÞ߬ÙÙËõêÙç«ÙÙÚÙëú·¶ïùËÛÜôö×æÚ²ÞÙì³êêÖæêšÞêú¼÷Ÿ«¼¿·öϾÞýÚÙ–ÛÜôýçæ·ÞýÚæÚ²Þ¾ïÝóò÷ÿÖ›´›ò÷ýÙ›´›ò÷Ö´ÖÖÚ÷¾å²Þ×ÿÏå²Þ×õ¼å³Ýþö­µ´êÜ«ÖÖËåò—Ë¿Ùï·–­ýúêíµþõåíµõ÷ößµùòÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª«®ªûÿÞªëÿÿÿÿÿÿÕª­þ´óË­ï´æ¯çÖ³³òŸû›ÿ¹´¶ë¶Ó®îŸü®úï½ùåšÙû»·´®ì›Û¾·²žµ´šéüòÚߦ­®›êòÓë­×§ÖÖòÚöì§×Ùùìöô×¼¦–æëÞÎòº´³®›žŸ›÷üÝæ­þ÷îó–ôõ×柲®§šýžûù«»ÎûÝ´õæÏóÝ´õæÎöžž—Ó®·š–׻헟×ÙéîûÙéîû®ç³­ž—Ó®·ÞÙÿòêë–ßž»ò½ý»ò½¬­¬ºÓ¯¶Þ»í—ïºÙÿòê¼ùßž·õ½ý·õ½¬´§®Ù×ß·ýÏ®·§®Ü×Ù×¾¿ÖÛÛß¿þó›õë›Ü×Öëëüš¿Ï¿ê廚­§¼§®ÞËýžþý½®·§®ÖÛÛßéü½þý›Ü×Ó×ù¾¿Ü×»þóúú·õ÷ë»÷žÏ¿Óõåݬ›ç÷ôçæÚçš–×®ÞÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª«®«ûþÞªëÿÿÿÿÿÿÕª­¼ž´¬¿÷ûô×Í—Öׯž§«´ýýµïöó¯­îîËÞ¬´úû¼óçéý–»öµ»Ý´ùù–¬ùþêÙ²²Ù–íõÝݼ´²ëËûæ·¹®šþüë맽úÛéïïæ–íýë¶üÞæ·ïéžÙÚ¿åïËÞý—¯¯–ÙÙÙÙ›ûýî–Ó·ýÝŸÞõõÖæ§ÛÜ—»¼³Ó–ò®ÿ›çéîíý¯¯ûû¬¬ûòííò¶¹º—Íϵ›Óêæ§ÛÜ—»¼¦ÞúßÚ¶Ö›úßÚ¶ëôûËÚõóéòë···µ·ýë¶üϵ­ÙåžÛ·ýÝåžÛ¶üÞæÚ·ýÞæÚ·ýÞæÚ¯ÚÞæÚ®ÙžÙÚÙò¶å·ýÞ—ò¶å·ýº´ïïËÖúú›ýîúêüÎåû¶½ëü·óë×ìßï¼ê›ë÷õù민µòŸÞõüÚ²Þš®¯—úô³Íϵ¯µëûò¶¿ûò¶ß²¶³¯®—úô³Íϵ²¶³µé¹×ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª«¯ªúÿÞªëÿÿÿÿÿÿÕª­å´íéþú–é²éòý®òô«½÷Ùûï–Þ³ÛºÏüòž–¹ÓÛÞ®­³³íç½òîÖ–ÎÜËÖ·íÙ²ë֧ٶϲ¶·³®ŸæéŸåßž³Ÿþ²›––³ÜËÙ—§ßßÚóÎÛ¯žæ¶µÖžÚÿîìë–ßžÎ÷½ýÎ÷½¬­­¹š–¾®·ÿýÖæÚËôÝÙÝÙùôù÷óóú¾¾öë¾öžúþßòóçÞüÎÜê§×®çÏþìßÿÏ÷šó·ËÓ³´ÝæÞÎöÞæÞÏóëç¾ÎÞ®çç»üë¼ùë»÷ݼîæ»üë¼ùë¼ùÝËýæºÿžž—­§›ý÷žŸžÖ®çÝçÙ¶üÙÏüë¼ùÙÏüë¼ùÙÎÿë·ýëÏíÙ»óë½õÙºöë½õëºûÞºÍËôëËôÝ·óìºû­ºÍ×æ毷ùöšòÿ¬ºÙÓêÍÎòÝËýëÎòÝËý³–––ß«Ïí¯ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª«¯«úþÞªëÿÿÿÿÿÿÕª­õóÝÙÜë—®í»ëôþý›Ë—êë´ôêåÙû»ëžŸ¼ü–ÿÍ·ùºµï›»þ÷Üžž»·šü÷Þ­ßï˦ü÷¬Ù۶ί—Ÿ×åéžÍÿîó³Î¹åžÍËžž¬çæÚ³ÝÙßÝšó½Ë¿ÚæÚ¯ÚÏùÚ—éêýô«ëìô÷®ÚÙô—ôÙÚô–óööË»¯´ïß«¶·÷íþü··§Ùç«ýýÚö»×ö»šííÚíµ×íµšííÚö»×ö»¾éö–ÙÙÙô¹ûýÿòýü·ÞýÚç«ýý–»¼Ú—ï·–¬óôÙÿ»åÿ»š»¼Ùö»×ö»¾³º—ÓÓ–Íϵ¦»×ŸÞõó×Íî·ÖúÚæ§ýýŸÞš¶Öò›žºÚ¶íí×òòí¬éöÙæ§ýýŸÞúæ­½›úæ­úíí×ËËË×éöç·ýÓ¿ÙÙ¶«Ù÷æ·ýë·ýë·ýÞçÙ¯ÚÞæÚ®ÙžÙÚÙËýë·ýÏùÚæÚÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª«®®ûûÞªëÿÿÿÿÿÿÕª­š›³®šïò—š››šÙÙ–šÙ¶šÙ´—ù§š›ò–—¶Ö¶Ë½Ùüÿíò´ï·¶î·ÙÚÖÖÙ››îÚ´òÖ×Ö´Ú×Ù¶·µ´¶ÚÙ×·ÚÙÙ´´µ¶·Öí––––´žžš—›–›ÙÖ›—š¾Î›šž¾Ë—Ÿ¦›žžÙÝ–¦šž›ËΟ–ËË›žÖÙ–ŸÎ¾›Ÿž—žÎ½›––››Ù¶Ú–Ÿ–³ž›Íž³šžÿ¦®ë–––––––––––––––––––––––––––––––––––––––Ë––––––––––––––––––––––––––––––––––––––––––––––––––––––ß××––––í–¦šž¦š³öÚÙÙÚ¯´³·š­¬ÏÏ´´——ëëííõõžž³³ßß²²¹···ëåëëææìì¹···ÚÛùùÜÜúú¹·ó÷üüÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª«®¯ûúÞªëÿÿÿÿÿÿÕª­¾ûÙ´¹½þ¬õ¿Ýš®žÚËôֻ›š÷ùíùÛΦÿ«×öïŸ»í®«ÚÝé¬û›ï´Úï·ÚÍÓÙߞ´óžôòÞ®çÜšõõÎÓ­ÍÓË–¾õŸï—Ÿ½«¶š××ó¯ÿó»Öö«íÝÝ÷û¯ô­õß¹´å«ööúŸ¬ÿ´í횶«×÷šõ¿»÷šîιüΫϼåóζ·»¼Ï¹§úôêõ³²¼—ÍÎåóζïæÚ³ÝÚ÷›¿¯¯¶ùõÓ¾ÝüÚç«ÙÙ–µ´×ßÝšó§ïçôóæ߬ÙÙËåïÙåö«»åžÛ®ÙÝåžÛ®ÙÞß×û¶šúúËåï–ÖÖ–çæý¬ê³µÞæ·ÝýÙæÚû¶×íµþõåíµþôçæÚ÷µ×íµå®ÙÝíµå®Ùžïï×÷Üó·×ûßîù÷íî½½¾—Ë¿—²³Ùò¶å¯ÚÏùÚÙõ¼÷¿¹ô—µ´ÜÙŸööËåï–ÚÙýóÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª«¯®úûÞªëÿÿÿÿÿÿÕª­ÙÞÛûûÞÞç¿ëþ§½ë¶ü´ÍÖüÖ®–éÖ®´ºÜ÷ù齞òÞô«ÛßÍÖ½®ü´÷ß®¹÷ééé§ó¬§ÏÙú¿ú½êå­çîçê«Üÿ½÷÷®ôòë÷–ºÝÝžŸ›Þõ§¹óóóóóó¹¹¹¹¹¹¹¹½§««ºº««««»»¹´´®®®íííÙššš——´®®´§»»¹¹¹¹¹åž¦¦––š—Ú½®Ÿ›—–í½®Û–ÿÿ––––––——––ÿÖÓ–ÿÖÓ–ÿÖÓ–ÿ–üšÙí››šž—–¾Ë–ŸÎ½žžš—›–›ÙÜ›š–¾¾ž–¦Þ×—Ÿ¦¾Í–¦Ÿ—žÖÖšš¾Ëš¾¾—žÜ×›—š¾Ë–ŸÎ¾šŸŸÙÛŸ–ŸŸš¾Ë—Ÿ¦›žžÙÖ¾½Ë¾ž–¦ÞÜ›ŸŸ¿¾ŸÖÙ›—š¾Ë–›š›ÖÜšžŸžŸÏ¾ž–¦Þޖ˽ž––ž–ͧުëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª«¯¯úúÞªëÿÿÿÿÿÿÕª­ßÛ¦ËÍž¯ŸÜÏ´ÚÙ–Ö××–ÖŸŸ–Û»µÙº¼­«–¯§Û¯¯–éæÝžÝÖÞ´ö—–¬ÎÎß®®²ÙÜæöü纼º×ôõó›ìæç«ÚÛÿüÜ­——››ÚÓîÝ¿ûåÓîݺòÜß·¦½²¬¾ÎŸÝëåÚÞÚ÷õåÙùó²»òÙëŸåìžæÝæ§Í½¬Ï´¾ÎÞ²åÞ¯æÝæ·¦½Þ¿ûåÓîÝ¿ûåÓîºû½õë½õëÏíÿïóôšõ÷ë»÷ݺòÓê;öÝ»íë¾öݺòë¾öÝ·ôëÓîÝ·ôëÓîÞæÚ¾öÝËú×ËúšÜÖÝ»íë®Ù޺;ö×é½ò»íÜåòúóþæåòõ÷üßæÛôïêÞ¶óþ­ôùõå¶óþ­ôîܵ³®Ö¶óþúåÚòõå¶óþúåÖì¶óþúåÖíõå¶óþúåÜ«ÓÍìµê»Ü¶óõ®ú³½¾åÙ­›ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«ªªªþþÞªëÿÿÿÿÿÿÕª­Ë×·×ûܵêé²Ö¯åÍ–þëóæ§ûòþ¬Þ­î«úí­¾¶¿–úúßÖ§½´Ÿ–·¼×ìæéß¿ºìÛåå¬×û»·Óùµõ»§÷üËÓ›­š®Þÿôú¾Ÿš§žÞüÛößžÚÿòýü²»´ž—ÓËì»÷ÿÏüò»÷žÿüÖ¶óëËôݶóëËôž®³Ö¶ó­Ïûç¾ÎÞ®çþ»óò»÷쫼îåóò»÷ž®³›ý÷Þ¿òõ÷ë»÷ºòµöë®Ùݵöë®ÙÝ´õÝ´õë®Ùë·ýö²óï—«öùíÿ—öùöçßßßû—öùóû—öë½õë½õºÚšóùõùšóùóûšóºòËýÝ¿üéîîîç­ýùóû¬üºòËýùõåËýîýï›ýþ›ýº­®·ôõÖËýéîû¿üéîúæÚçÝæÚºû­ý¯ûž®§Ö÷üßÚçÚÏüîû­Ößú––»üÞŸüùóÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«ªª«þÿÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«ª«ªÿþÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«ª««ÿÿÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«ªª®þúÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«ªª¯þûÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«ª«®ÿúÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«ª«¯ÿûÞªëÿÿÿÿÿÿÕª­ÍêÙ·¬«¦ÞÙ­­ÜÛÝõú­—ߧÛÓµæÚ›–´÷¦›®§ïú–ŸŸ—þþ—ó®ç¼–¹½¬ïü¹´¹Ï›®³çìôò¯®ýý›ëë´­æõêËò·òÖææÛò·³ó–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÿÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«ª®ªúþÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«ª®«úÿÞªëÿÿÿÿÿÿÕª­—¶òúûêôÎ߬êçÚÍîÎòç­–ææۮ묛öí­Ö姬µËï÷žý§Í½«Úں߾·²®§¹²¬½ÖæÏ»·Ï²ÿý¦§êÖê«ÚšúüÙ›·Íþ¶ÜžÖšý––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÿÿ–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÿÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«ª¯ªûþÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«ª¯«ûÿÞªëÿÿÿÿÿÿÕª­¿÷ü½ì›§Úòß·ûÏëÜÎó²ŸÍ½¶¹¯·Ë¦ìÎöõô«Üæüé¹Ýþ´–ßÚû÷–û–Ú´­¾¿›ÚÝË·æž×–ïï–Ú·´Ú›ÖëšÛ®ÛÖú¶®¬ÞÙë¿óë¾öÝÙë¿óë¾öÞæÚ¿óÜéë—¶óÓþéÙŸÞžê¶ó»×öë¿óìù×ö¼—Ùó»Ùó»Ùó컚íêÙë½õ»Ùóë¿óÝËýë½õ»Ùóë¿óåÛûšóº½–ææóüÙæóòêæóïéçôîìçôíëçôö´ßóô´ßõôæ¿ü­ÙÛ²®×¶üÞæ×ò¿¼¹—ׯææþ½––––––––––ÿ–ÿšË馚–––½¾šŸŸ–ŸÎ¿ŸŸ›íž¦š—–ÿ––––––––––––––––––––––––––––––––××–––––––û––§®–ÿ––––––––––––ÿÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«ª®®úúÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«ª®¯úûÞªëÿÿÿÿÿÿÕª­ÜôÖôµÓ¿Îççó–½åùËççÚÙ×û¬Ï¬¯ìÚì§íú³ìç—ÖýîæÞ¯¦ìü§ëϼ—µ²«»¿²²÷ﵦ›¼›íå¹ÖŸŸ¦îæÏûÞîµ¾öó­«šíšöò§¼®ç¬Ï´–߶¿Ó½®ç÷Ë®ç÷³·ßú––»üö»üÿšöò«»®çš»Ïê®ç»¶Ù¶žÜïæç®ç÷µõ²µÞ¼îîóû³î—«›ëå²òîÿŸ¬¿½¦–õùóû–õݼîºïæÚÓîÞæÚçôõ¯êµõ¼Ööíþî§öß×캭õå®ç÷ùÞæÚçì½ö¬ÍÏÞ¾õìÓîÞß–ßšå¦ß·îçËîîý³ÛæÝËîë´Ÿ³Ó­ÞõôÖ¼íìÓîù»î²µÞ¼îù󽬿ôõÖ¼î¼Í²ÿûÝæÚÓîÏêôÚ¼ÖÙíö²¬®—³í÷§þ–ß»ÿçåë·î­ûîæËîë´Ÿ§Û½ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«ª¯®ûúÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«ª¯¯ûûÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ««ªªþÿÞªëÿÿÿÿÿÿÕª­¿¾ûùòúÜÿË«¬¾çíúï­æÚ׵֧¯î¶žÿÍææ´÷ϼÎï²ÙµïüýεíÏÙÖ¶Þ½·´Ö®Í–¹½šÝ¦§²ÞÖ¿òù쯷·ôµÞ·›ÿÖŸë¾ÿôç×ù¹¾ÿ׬š«šíêô欿ùýÏ›šžµÿÙ´þíš®ùöüï½ÖÚ³¿ö³Ÿßæ²öÓ®–×êÝ–æûöÝ–Ù¬Úžó–÷ë¶Û¹ßÝ–ÙÝ–ææÝÞ—üþÛ¾ÿææÝÝ–ææßß½÷Ö–––þüž¦–Ý›žÓ›·Óí–׫¼–«¬ü––úž––½Þ––šý–––ö´Ù´òî·òõŸÖô–Îó·¦ë¶¬¬ß§ší·›ë¦­–òµ§¬ß§Û»²óݳæ­ÎìÍó¿½æ´§¬ß§¼Üï¬ùקõÝç²Ëýß—úêÏ«í÷ëÛۭε˾¿§½¿òæ˻훾ÿ¾Ýݯº¦²–¹ÎšÎÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ««ª«þþÞªëÿÿÿÿÿÿÕª­÷¶›î÷¹ºöúöû´½«×ç·ù««—§šû·Ýùüí§å´¶­›ú«¬Ù­»Ïݫ矖¿¿ÖÙ»¿¿üÓ¼Ö¯¯–Í®ïë«›Ÿ—§å§ëþíç׶ùæòºÛô÷¯›úµ—ͧº—ûþê§ÿ²¯ó·–å·¦¦¦³¬¬¬šþõ³ßÓ²õùîþõ³¬ÛúËùíßéó¬÷æÛü´Ü꧿å×ïßÛüîššš¬³³³õ´µëÿÍêîÞ½Ûꦴ²º»§¬ëóŸ·———«ôôô®îýŸûýŸ¿Íêµßé÷þíûô²ûô¦·÷í¾ßˬßÛí®´¾ß½–«ß§Üêüü§Ëæ½–«ßé÷žíßßΚÝïòî·ßü»îíš·—úêÏ«ùû­­›²óÚ«îóŸÏç¦íš²ó·¦ë·š¬ž®—––›»³ýöÏËôêÖÜŸ²›­«úêÜ¿ßßמ®³·ôåß׬¾®ïýË›šþº§«ûòÚæÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«««ªÿÿÞªëÿÿÿÿÿÿÕª­×ù·ÿíÛ¶õÛßÛéšÙÖúŸÏÝ®ÚÙÜÏ麟¦æŸ®µòÙ÷ô¼ºê§æ´ï߶ûå¶óêËïæ··½óéÿ˲¯êÙëºüž²Ý¶Ùí›­ºÿš§Ûê×ç—¬Ÿš¼¶ùç¾õìÍúô§ÛéÛÜ«¼ÞÍÝßÙÛéÛ¿õ¼Þ¹µ³ûýôçºÏÜííõûýíêé«ýˬ—Üž×——šÖÙ¬ÙÛé×—ë³ÿíþó·¹ÿ®Í×¼æ×ÛéòòòïßןŸ¦ÓÙìôíçÝó׫¹¶¶õ競Ÿ¶¿ÞùÛì³üËÜÍš²›žÙóÜûé½ó·îš§Ö¦—öê—ì–ïž›ô箲´Ö½–åòòïú¦¦Ÿ²ïïïúÚÍËÜÛï·êé´Î®®®¼·ûûúòßå«š¹Ë«š®æﻚ¹»š¹»š¹»š¹»š³³ÖÍ¿å²›Ûï·——–ùî旽˽ÿ³²›Ûï·×ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ««««ÿþÞªëÿÿÿÿÿÿÕª­ßÿö¿ÏÏ¿¾µÙÙ¶µ×ç­¬¿¿§ŸÝݹ¹ÜÓϯβõ羬·³ºžéþ»§ËµöÞº¾´÷éž—îí¬Ÿ´ÍùôÙÙ·Ë«žÜ¯ìŸ–¬ÏþÝéë²²¬µý³Óµºüß—ÞÍêÝýž¬žì—ýüÖ«Ÿë–ýý׫Ÿë–ýýן«ë–ýýן­é§ìζßÝÖì²·Ýû²ŸŸ²—«Ÿ²—««—š¬««¬î½íúü¯·æןŸ«í—ýž¬š—îò­«——îò­«—²þí§Ÿ²²þí§Ÿóí¾Ö¿—æÙ××××ëëëÚ÷ïöÏ­ÎÚêܿן›ÞúÏËé«þþþþîîîîïòî—úêÏ«—²ôêÏŸ²²ôêÏŸ²—úêÏ«——úêÏ«—šùêϬ¶¶ÓöúµÍõûµÍô÷Ï·óùÏÿíùš¼îÎíôéÖ¬ŸêÜÛéêÜÜêêÜÜ單ܿ½²õŸž›÷ß›š¦éÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ««ª®þûÞªëÿÿÿÿÿÿÕª­šš®éßß´õŸéÓîÛÞùÙ÷ß®ë󟽼¾ßܬö«¾êŸ×ï§û¯²šËôë÷¶ßóüÍþ¼¯ŸúÎûŸ¬Û¿ÝÞ¾Ö¯­­³Ÿ²ßõ»Ýæ­ÚÍó½´ÚýüÖ–§Û駵ëϗ۳沺»–Ýߺ¼´íÛ»²ç®ìŸ·éîÜ÷êžž»ûê»úßÝóû«ïû«ï¿§÷Ùû—úû—úí—ì–¶ýì–¶û—³Þ–å—³Þ–ïúÜêïùö§ºÙ­Ý¾êûÜÏûܲºþÜêòòïú¦¦Ÿ»æìô÷ÙÞòÞß鬹›µ¹ôß«¹¶¿ùöϬÖÓÿ®½Ï¬ÿþ›µÎïµÚÜϼîÎõöêí«¹éùü²»´ò›µæçåô¶¶®ç—æµéùýåÙ¾¼îýò›íí®Ïææ­¬›åß«šÙï–Ë«šÙï–·¬šæî––»š²æß櫯´»½ÍÍ¿æ햿ﻚ¹´ÙÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ««ª¯þúÞªëÿÿÿÿÿÿÕª­ßî·Ù«ß˦Ëöÿ¼½½õÙ¯žêßß®–Ÿ¬–§ßÚéÝÛ뾿¼½Í·÷ùùû匿¯ÝçÍÏõÿËŸ´ÏËËéü¹ó÷§Ùòú›Öåïòå—çòú´íßíôÿ¶¬¯–žÛÛýýÎÎÎÎÎÎÎÎÎÍËߟ³ýÏ÷Ö––––Ó§šÞéþÛÙÛËùý·æ×ÜëÛÛŸßê®ýîêê®ýîê–Ö––Öé´¾ûõß¿Ÿü·ôϵ²Îܯ÷¬—Ÿ¯×Ú¶ïÞ»·ÝÛ¶ïµÚ´ëé¶ï×´·éë¶ïÓéµÞܶïÞ»Ú¶ý²µÜÞ¶ïíš²ó·çšï­ù´æ×ùùùù÷÷÷íšÚÛ»·—ÖÛ»·—ÖÛ»·²ìÛ»·²ìܼå曲ó·Ü®ß´Ù¬²Ù–ìí–ò­÷íí–ò­÷íî—í§ùîî—í§ù—————––––ï¯óÝ—êùõõõÿåêûõ­§²ûõ­§²ûõ§­²ûõ­æÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«««®ÿûÞªëÿÿÿÿÿÿÕª­¬—ì»òÓ÷·¾×–ÝÓ¹ŸÝÝ®óϯ³»®­·´µ«³Íî÷šºöúÎí꿻ݚݲíìþìûüܲìòþš´½«³¯ìºº›×ÙÝæù—»´î¯ú¾ô꾚šëšëÚ·¾¬¬¬šþÝïö›ëü«ûõ³§ûü—Ûï²ßÍí®ºúúúîæù¶šš¼ýÚŸ—µ¬³¹¹¿Ó«ÍçÞïÙÓ²ßÛš³ïå­Ï›š³êíéæϬ¦Ùåæ׬¬¬¾ßí­«ïû«Í¶šÞöôò´»¶šÜ¶õÎç¼î¦Ëšææêúþ¬Ú·¿ûîš®³þ²î«¬¿ïöŸ·¬›åß«ÛïË«Ûï–·÷òæ§Üº¿ûü—Ÿÿü–­›«÷ùõû¬¦÷û²¬¦÷òëܦ²ßßßÙÖß®éÖŸžßæÙÙ³ÝÛû–ò®ÿ–òŸ§º¼¶®Öîê÷ü§§ùîå½öÞïÙÙî›ôÜÙòß×ÜÜŸŸŸ³®ÛÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«««¯ÿúÞªëÿÿÿÿÿÿÕª­¶··×꛼¿¶¼µ»¼ç®§®Ÿ¬®ÝìÞæÛݹ½»¿´½íïïúó¶›Ó«ôÙž¾›«Ÿ¦¦žòÙ²®Í¯žóÙ¶´Úíïù÷½¿¼ºåßå׬¦žÙ¿·æò¼–®¾ù«­››ßÙ—§­²ûõ§–²ÿî–ºû—Óþ›Ü¯­—¯³—Óú—Ÿ·ó·¦ë·›­«íî—úêò¯Ë–«–ååݳï´Ù´»÷šÍ¿é´¹ß×­Ùû¬–ÏËž×ù姖–§´Ù´þü¶¶ß×­Ùõå«Öï횟׺¹Ý´æ²öÏŸŸì­ù›Ï˶Ÿ¼ºæå–½»·íê–½»·õç›Ë¾Íôߛ˾æ§ëÝ÷ÓüÜí§«Þæ¬ÝìšçÚÚÚÖÖÖžºôÿöü¶››·µ«­››·µ«­›–´ÏŸ§––´ÏŸ§³ôú·´úۦ–––ڬ׾曶«ï¼îÍîùŸ²îùŸ²í÷«—í÷«û½îËõõ×ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ««®ªúÿÞªëÿÿÿÿÿÿÕª­¹Óßçݟ駮Üíº–ÝöÓ¬åý¹«Üü»¯ìý»­¼ú쟬¶÷Ú§ÞÎòšº›¶®Öôµ¬æ߶¾Ó²½ï¿²é´š§ïûý·ýåûÏõúóýëÎò¯³­ËôÍ·ÖÚæ²ï¦¶ó޲͖¯ëÚ´ç¼îý½ßí«ùíݾά—Û¯í³ÿ¶êÿݾÎÏü÷¦Üû§òû«ïû¦üû¦ü¿ê·Ü÷·¶¿÷÷¦ôٗۯﯻ›››î«êÿ½ßµ­íû­í¿ÛËÿ¶êêû›÷û›¬ßé²›—¬½Ï²Ï¿¦–·Ï®ïíÝú¼§åší·¦üû¦üþ²›³Íϲ›³¦§òû«ï¿µëêû›÷û›æÜêüü·×žêû³óû³Ÿß¿þŸ÷ß»Ÿ÷ß»Ÿ÷ß»Ÿ÷ß»Ÿú´¶êÓߧžõ×–íº¼ßü÷ê———«šššçÍ꽟ŸŸŸŸÿíÖåÙÙÙÙ­­¬¬ŸŸŸ³¼¯ÏŸ»ÿ›ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ««®«úþÞªëÿÿÿÿÿÿÕª­ÚçéþÓÚ鶬ËçÝæì¦×ÚŸËË›ìææûº»ËìÛÙ§Öåêßô¶ìéÛÛ×¼õÎÎåÙæß—ÿòé»ÍÛì×æšÝ­Üþξûºú¦ûίÞËÓåæ–´Ëž®Óÿåêûõ«¬²ûõ«¬²ûõŸž²ûõ«æÙ—Ÿž²ûõŸŸ¬òí²êÚ®®ßüýߧ§§å¹ÝËõõõÿåß—®òô­—®òô­²›òô­—æλë›òô­²›òõ¬òî›­«–å鮚ºŸ¬Ó¬ò´¹Ý¶å鬚®ËŸ¬Ó¬òî²Ëšÿæ³¾ôù­²§ìí¾·²Ëþç—ÙÖº·éææ½´ß¿ËŸ¯æן³¬­²ôêôÖæ׫«««ŸŸ¬¬«û¾íçùíùùùùíßéóæ½»¯Îó«ùÛü«Ï·üÛó¿Ùµ»·ïóÏóå»·íõÏóå¾Íõí½ô뿦ó×µ¹õÚ—®Û¶êéî½·²ËëÍó¶××éÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ««¯ªûÿÞªëÿÿÿÿÿÿÕª­õ½Ï½»Ó«ö¯òî¬æퟟ¬åµ÷ÚåéŸÝý´ç¶÷¶¼µ¼ì´õ궶ò´§åûöÍî—ô¬Þú¦åô¬´ÖïϦÚüíêÜçžßîý¬²Ö¬ö뼧§êÛ«îïÿýíïö§²úóüŸÞŸ—ÿò­¬šš³Ûúˬšš¼ýòïóõÛëý¯µ››šÚí—´ýéìÚôå¦ü¼îͲšÜ岚Ü岚Üßß׫««¬›ÜÜôë––Ëô®«º»–êïôíéÙ·æÿÖíôíæÿÝÚúúýýýýýõíšíûúê§ÙÝå½·¬—ÜÏë–Îôôóüúúýóß×›­ïïïú¦¦Ÿ¯ÿýß×õõõÝÜßý«–îž—¼çÖš¬òòòûõõõëÙìôíçÝý«²ÿž–γæך¬®®®ÍÙìôíæìó·­×½õõõÿßéûý½ÏûºíÏû²ü¼Ïû²üì²í»ë÷ŸÏéÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ««¯«ûþÞªëÿÿÿÿÿÿÕª­ëììô—¬´Ûßýíç󮬾姴üÛéŸÓ·¬îíË­òìÜò¾ŸéÖ¬Ûé¬ÖÖ§žþ›í²ûžµûúîò¶ÙíÛé½´úþõ¶Ú¦å¯²²éÝéÛ½—´êõ¼žšß–ºÏ§××·½¬³º®úž«óŸË§îï›—ÙæîõÝÝŸŸì«û˧î¿Û–óŸË¬š—««úïæÖš«Ÿ²—«Ù´¾íËŸŸŸŸ«««šïíßßæÞ›¹õú¿ÞîùÿôÖ«¹ýò÷þô«ÛéÛïÛùööùÚÜ÷ÛéÛ×ö–²ÿîùöþí–²þí÷õýôô½þìÛéÛòÏëÚ¦åæ²öÓôû·ÙÿììïÛ¾³ßöÓ¦¦¿÷–Ÿ¬Îì›Ó¶¬šý«Ÿó­¼¶¬¼—Û®½­Þ³åËìÙùÓëŸóÖ¹óõý²ß­Úå¿´ÙÖ¶éÏ·›ûù«­›²óÚ«´³¹íÝÝßò´ë秼ݳ÷–ÓÿÝÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ««®®úûÞªëÿÿÿÿÿÿÕª­«ž®åÓüéÞ¦Úù¾§Ï¶šÞ¿þ®ÝšÖ«ÜÞ«¶·Îÿž»þ²­«½½»¼žç¦æ­ÛÎú¦çÏß¾å¾ù³·—Óïí«¾ÍÚò÷—櫬š›ÖŸž›ß¿«žÎ§Îÿßš½Ë½²õõòÛùëþþë͵ôí¹¾¶Ý–îž–´ûË—ÿÏû·§þÏûçõ÷Ïûý½ÏûÝê÷ÜôòþÙöæö»›×îô÷ÓšÖܦ¦Ÿ²þþþõ›››­¬šž¯¬ÜÓ²õõòÛùëþþÿß½î­Ï—¹¯ë­·÷­ž§²ûÿ¦®²ý¿×®ïïôýêë¶Î¯»Ë®—Ÿ§·Í®®¼»ŸîîË´—úû—ú¿´ìÿ·éêû­íû¬›ßéŸé¿ó®Üåÿ¼îýý¯íý®´¬¬¬ç«÷îî–´››šÚ«÷îšòæõ¶ÓßéŸ÷ÖÏŸ–½ÏŸ–íûõõõý»þ´í²ûò÷ú¶¬ÛÍÓžýý÷ÛùÜÍÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ««®¯úúÞªëÿÿÿÿÿÿÕª­—îóÛ¬ï½Ù¿úÓº·öÞš×¼ý­ßݧμ۟ìéÝ¿÷¦­ëÛ¹Þóçé·ÍúŸô½Ííÿ­íïï⦬½Í¶´¾«Íæµ¼þöÎõ¬²²žûþìì·þÓõŸëßÍïÖóõê¦ôï¿ÎåÖß÷½ü—·õ½ü—´¬æüþÍüö¶óóóüŸŸŸ³®æŸÖ¶ïžõßÎ÷Ïßæ×åç×éžò¹¾ÿ׫«¬¾½Ýܲ·ó·Ÿëµæ÷½Íüéëßìê·ò¼Ü´¼Í¦®åç·òÛ»Ÿû›–ëßæ·òÛ»Ÿü¦­Ÿó­¼¶³òÎì›Ó¶›ÿÖµîóŸ¶ßå³Öͽ²²ííëêËܺ–æ²óúצ¦¦Ïü–êš—×ù¹¾ÿÙÏýçÝþ¹¾ÿ׬›ßߧ«—뽞ֿ«——õ׿«—²ù׿Ÿ²²ù׿ŸÎ»êžòû®®ú¹ŸÜ·êܽ½µù–––·—«š¾½ÖºÓÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ««¯®ûûÞªëÿÿÿÿÿÿÕª­–½ÍÝ֚ݴ˯ìû¶›×÷÷Ÿ¼µŸÚ§ÜŸ­µ½ßÖ¦Þ––›ç³³³¦¹¶åꗦνܹî߯ö˽÷Û®šžÓ¹Ÿ›­êý¾›ß¹óÞšÛ×ÝúÏ×›½´·éÏ———«õõõÓžóûæßéûžÖÏûý½Ïûýí´þíôêßöúÙìõ´¹ÓšúúÿÛùÜŸûõõõ³åÛ×öïÜÖõÚôëú×ôüß½´õ¦Ëí÷æ§ÿ³ÙïßÛ›ý–«¾òîݼ¯¼žšÜ곫®óíí¿ÿ³µ¬¬¬ç«÷ÚííÍÓ²õõòÛùëîëî–æ¾òîݼÿúÓîêé­×·ºÏ«ÖÜêï÷õý«Þ½ÿõ¦îݼ­´í¹ëßüÓ³šüê²¾®§ž—¦Úݾêííûžþ––ííûšùûš¬¯õóóúßÙÏûÓ´ÿ²æ·÷íöŸµß×Üëï´ÿ²žþæßéûýù·÷çôÏíÛ駵ëÿ§ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ««¯¯ûúÞªëÿÿÿÿÿÿÕª­÷÷²¼µ÷Ö¬¶÷ü²—ÚÖåû¾öëçõëͦöüÍÓþ—çîšô÷并ëôç½ïϲ§µžüíý½·§ûî¹µÛšæÿô§Öß—ùòåí͵öóͬò¦Ï­ºó¹Ù¹Ù§÷çý¾ž¦«Ÿ÷´÷ÙÛé÷­¼é–ݾÿ»åÿÞ½ÿ·éêí›—úû—úíí¿õ¦Úí§í—Í÷ÿÛËêí¾¶ž¬¾¶žééÛ·«êÏ–ßÝ·õç–ºýß²·óßß­Úß··÷í·éËßê›ßλ֧§››—ߧۻ´ùÿËÎæ×Üô·æ§ù½ŸŸŸŸŸ²›››Ù«÷½­­­–ÛöÏËþßæÛÜß²¯ºÏ«–¼ž§–Ÿôß—Û³žÙÞìŸÏ·Ë¦·¼·éßßú½ß›®ùüææ·öÏïõ¦î³ùê·÷íÞ½ÎÙï¯ÿÜêó«ÜíߧÜê×ÜÜ—ßÜꧼ޹é·×žÓß×ÜÜ×ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª®ªªÿúÞªëÿÿÿÿÿÿÕª­ôοúùå–´—åæÓ´Þõ¶·ö»÷¿š´®³›–—ºó¯óÓ¼¼ïóššôô««ÙïüÏï×—îò·û«¿îܳ¬ÜÜêöù¯òΦêå¾òºÏòÓ»ï·û¬»»–ÿòŸ÷··¹óúßß¼º÷–š¹û¯š¹Ûú§Ÿ§Ýí§îêšžžºº–·§Þ–½î˽š¶¯ö–鶶·ôžÎݾšì–éê˺ýóÙÿ—«×íÝþò»¯Ï·ôï¬úóÙò¦­·Ó¾ºÎϲ·ýŸúͲٮ²—Öûö϶¯¿þהּÏêòÛúõžå垲잫»¿òÿ˼³›º¾µþ¯ê­¾þß–ö¼çÏ­óï–·Ï··òêºôåç´ç–¬ïéÍÙû˧ºì–ÛÜò¿¹þíž­ýÖ·ú³þ­´­»··ÎÖŸöÏûö϶¯¿»·ôê·³¿ÎÎοóò϶¾º·óéßÚÓ»ßïÍë–¬«¿ÜëíûÜí­êæÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª®ª«ÿûÞªëÿÿÿÿÿÿÕª­æž«ÖÝëë¿·¾Ëç–¼¼æÍõ¾å÷×¾¶çÜþúêÛ­ŸÎû²éËûíîÛìÙÖÖ—–ŸÞßéÜçŸú›·Öé嚧«š›µ««ïìž·ïë¦õìÓ›–ù¿ç­§ÿ¬¯š®ÿ­Ý·ôÎßôÜêî÷¦ÿÝ·ÍŸ¯§­²ìŸòëµÿôõ¦½ÓÝ´õ¦½½×´õ¦´·ËÞì·ËÞÛ¬ßíõúüéžçÝÛùÿ–éŸæÓÓé½ÏæÓÚËÞÞÞ²Üêõ¬÷¦ÿÝ·ô®ù¹¼Ý´›õë¶üô›õë­Ü¼æ×ëëëÞüôëý·ë¦ö–ùìôõ½·ëõêŸûóö´²óÙ›ëõêÜæÿÛóó·¼î¹üüýýëëËÖûËËýýúúë¦õ—ºæ··ÿùì³ÿ¯ôëݲþ¯ôëÞåê¬ëò›µ®ëÝ®ë¼ïúîÛ¯í³Îæ×Û»ì¬þõ¦­´´÷ëÝ÷í½¿õ§é«ßŸÍß«ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª®«ªþúÞªëÿÿÿÿÿÿÕª­«å­éÿÓ¼õÝæΦîﺚ–üÿß—Þù´ú»­î­ýšíò­¾ºòêÛ«¼Ï´üͺúË–ö›ž¦ü²Ö¹Í즻«×š¬¦å¶×ú÷ô´ü³¹—¯ÓÖóÏ›òï´Ùï–òµæ×­ÙÙ··õó¹ó×´´—ú»¦­Öµ´—Û²çé¼êÏÛ¯ü³µõó¹óÞ»Úϧü³µöô¹ìéò–ï´æ×Û¯ó¦·¬¬ß§îšµ²®ß§õ´æ׫—鯴ۻ§¬ß·¬Úß—ËóÍïµôϧïµôÏöÓ–––—Ö½ÿ¯¯Þç­ÿ–Ó¦ü÷Ù×åžú³¾§þëòæïµôϗΚ¦¦¦š—Ë—ú»§ü³¶²ôÖ¶Üçëé¶ïµÚ´¾Ë¹óÓé×߶Üçòî¹ó×´ÚÏ·Þ³Ú¿ÓËæ¾ú¹¹ÚþÓ·ßËÍÏçêßÚÝšì¿Íž³®ï¼ë¬—¦¹ëý–ûôöß²ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª®««þûÞªëÿÿÿÿÿÿÕª­–›š———––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––½æŸæ®¶–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª®ª®ÿþÞªëÿÿÿÿÿÿÕª­ùý®š«ÏÍÛ»×Ùíͧ¾å´ù¦ó²ýûìîî·ï´ç­ë²éš²ß–Ú½¿×å¬ï¹é¶æûŸ¬§½šµûݹ¬¿­¶Úﶬ¶µ«šþÞËÖ럧º¼–—žË®Ö¼ºëô––ëÛÖ–––ù¼¿óù¼žòÙ§üÙëíúó¦ôóõšó²é÷òÙÜšþ¼Ïüô»½®ÖÙ¹Î××××ÖÖÖ«¹Ö»ùï×××מžÚß®²´¾ÚÚÙçìßêþ¾«¯Î²Ÿ«ÍÎÏ›§§ó¦÷æךçõ§ÍæÚÍÿÚÍÿßýóôþæßæÚôôôüßùê÷÷ŸêËíÖÖÖõ´êËíÖÖߦ¶ýýýÏõÎýýüüúúýóßßæÚ÷÷ûïß×¹·šýÖÖêóùÚòííò¶í®ü¿ÞÓÛÝϼÖÖÖçÜÞι×××ËË–§µëÿÍêÙ³¹§õ¦ËîîÎöõ¦Ëîõ¿öõ¦—óÖßÜλכ÷¦ÿõþÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª®ª¯ÿÿÞªëÿÿÿÿÿÿÕª­÷÷²¼µ÷Ö¬¶÷ü²—ÚÖåû¾öëçõëͦöüÍÓþ—çîšô÷并ëôç½ïϲ§µžüíý½·§ûî¹µÛšæÿô§Öß—ùòåí͵öóͬò¦Ï­ºó¹Ù¹Ù§÷çý¾ž¦«Ÿ÷´÷ÙÛé÷­¼é–ݾÿ»åÿÞ½ÿ·éêí›—úû—úíí¿õ¦Úí§í—Í÷ÿÛËêí¾¶ž¬¾¶žééÛ·«êÏ–ßÝ·õç–ºýß²·óßß­Úß··÷í·éËßê›ßλ֧§››—ߧۻ´ùÿËÎæ×Üô·æ§ù½ŸŸŸŸŸ²›››Ù«÷½­­­–ÛöÏËþßæÛÜß²¯ºÏ«–¼ž§–Ÿôß—Û³žÙÞìŸÏ·Ë¦·¼·éßßú½ß›®ùüææ·öÏïõ¦î³ùê·÷íÞ½ÎÙï¯ÿÜêó«ÜíߧÜê×ÜÜ—ßÜꧼ޹é·×žÓß×ÜÜ×ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª®«®þþÞªëÿÿÿÿÿÿÕª­ÜÜ´Ö¶Úܵ·²§Ù®²éÙë––²õ¿»õéç—š–Ÿíº«¹ýºü¾ôßéÙ篧߹·ç§®óúö÷º÷½íÖ—×ü²Ï´Ù˧«óóó󶶧§ßÖÖ¯ó—óÖêÖæææ·­ôÏíò¦žž´ëçºÎææææλËù÷¦ÿõ¦—óÖ¹Ö´ò¦Ï­º®úݾݷþõ¬þÏ­ÙûúÝÏ˺ìº÷õ¬þϧ¿úÝ›Ÿºì¾óõõ¦Ëî¬Þõõ¦­´´óæžúžßõõ¦Ëí꺴ËÎÛ»æÙÓÜÛﺭóæÜÞß×êêÎÛïôö÷Û«ôµëÿÍê´ýÜæïýêÙöé·¼îÍýôýýúïýôüüý´µëÿÍê´ýÜêôýêÛî¹µýÜçòýêÚþµÍýôûòýôû«§ëÓ–Ù÷¦Ï¦³Í¹¦³Íò¼ìÓóü͹óüÍô×ÓÜô´¼»Ï¼Ó»Ïóü¼Óóü¼Óöÿ»ÏåÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª®«¯þÿÞªëÿÿÿÿÿÿÕª­¯žËûé®´–öþÞº­Ý®¿×·æ§ìýš¶ÝüϽ¹¬¬¬®Ÿ¹šËçšÛÛÝóí®õËí´—ºí»·ÛŸåګڮ쭭¦ž«—››çŸÝÞçšËË·Ë«¯š¼¶ùí§üìÿ¹¾êÓßÞúßšóóÙš«½æߺÙù÷Üìå«­å«òºš¬»¬»ßé¹——®óù—Ö´¯üîºÛ´µ«§´µ—–º¼ò·ÚçÎõµË·¾µË·¾µúï½´úッ›ÿ¯üî·Ù´´½¾µ´½¾¹Î´¼Íš«ÓõšïϦ½îšï¶Ùšïí²ÿî²þ¾Ó¹ëšŸþ·´¯ó§®ü¿æòºÚ—²þ¶Ýîͽ­ïóôßÓÜíÍêò¶Ë·¿¶—ÝíÜíš«ëŸþÓ¾§²ÓöúŸ§Íêù÷®í»íÖúó²òíô®§õž¼Óö–ëÖžë½ÿÍïÖòο§¹Óò­ûÙßÜçºË÷þ»ÏËì§ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª®®ªûúÞªëÿÿÿÿÿÿÕª­×·¹–ëæõïé¹óßçû½–ùùçî·ç¹ôçõ¾Ïô·¼Û׺·³Ùï®ûïÝîÎæÚšËÎÞÝšŸççžž§¯óùÜýí·ýÜæšÙæÛéæóüÎô«Óÿ»Ï¹Í³¦¹Í³¦¹Íüó¹ÍüºÜꧦùÜÞ—ÍÓ¼üóÓ¼üóÏ»³¦Ï»³¦ÏµôÞ—Ýמ˶¼š¬ûòž¯û¶­ôþ²òͳ¦ùùï×›÷¦ÿ­ô³êÖóùêͲòͳ¼åî²Ï×óé½íß鬚ü×Ó¶óùÏÏ×éóù×îòç¼³òÚÏ­º´îîîéóï´›ûûû«ì«ÏþÜËÿÛÚ›ëºþÜÚÎíõþ­ºß鬮§²¬Íúééï·ôôôÍû®öÞ¶ëÖ®öþ­ôö–¼ß鬼ÜÝϬÓê÷é·¼îýÞ¶ëé–óÏÜûÓÛ¿úÛõßÙ›ÏÜûÓÛµ½¶þÜËÿÛ¿æ×Ýë´½Þëß–ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª®®«ûûÞªëÿÿÿÿÿÿÕª­§Ÿõþæ®þ¬·›é웽ùûÏüßí–›ýÏÖööÖÖ«—Ë·Ýß²ÛÙÖŸßúõÛ—çϽóù¾½¶»¬¬úò›³Î횟²———­–¯³¯Þ­¯›Þ­ì¼·×›ŸþÎî×çúÖéÙ¾ç–ížõ²×í¾ôîšÏû¯Ëïïžõ¦žöóú½´²þÎî¶ûÚ¯·÷´êî—ý²þš¼ùô¼ìæ×÷¦òÿ¼ìæ×Ú›­­Ï¹µÓéÜϼͺºò켼Ͽ–žòóöÜ¿—Þþ¶´ºòÙÝù¦ÙÙ¶§¹µ³æ§¬ûµßÜû»¬û½¼Í·ôÍ߯ýë­Ó·ûòùô¶Ïòÿ¶«–ïÞ¼ºþÝßîå÷ëùŸÓÏùܧÎÜ姹¹¶­åíιùõŸ¶ÜËóµùô¼÷óú×½¹òÿ¼®ú×½µßéºÿÿ³¼½×ôùô¶Ïòÿ¶Ïùô¼Ëòÿ¼®––¶ßÜûû¯¿¼îùþÝßÓ´ÿþÝôÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª®¯ªúúÞªëÿÿÿÿÿÿÕª­½¾Úïšò¾¾å§ßê鬫ê¯ÎöîýÝçÛž½š¬úúïòí¦Ó¼Ë¾ú—¿´½²æ´õë§ß¼ž«µ¾ËÞê¬×§´ï¬·î¶íÙîòÚ›¿òÚßï¿š¹ôç¬åÞìëÚÙ²¼Ù³Ÿ«ÿì쮯ò³Úù¾¾¾¾¾æ½úµßË–·§ßß·ûß­––­–­­–­Ë´ÖÖ›¯Ÿ÷½ßç¶íüýåÖ¶Ëò§ûê¶Ó½·ž—·Íêæóû´½Ýçݶ´®ù¹ë·Î–ž½ÎêêµÍ®×ÜÏþê·Ùµê¹úÝß×Ú¿µêê½´ëžíšóžß뺯þÝÓîܲ´ïéûά¶šúëÍ´ßéËîìÎþ­ýôÚô»ž–žýïÿ›´ô»ž§–šìÎþ­ýÿìܽ»²ž÷óù›ëÎêêÖÎêêþ¬ïï¿õ§ß–¬ìܷ֚«ü«§Üæ¯÷²—ýËΫÙß϶¿ûÖ·õ–é¿ÝÎß·õé¿¿ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª®¯«úûÞªëÿÿÿÿÿÿÕª­³›öòí–«®ùü®þÓÿõóü½¼Î¦¦²¹»³¬²·²ûÓòý¿žë›Ö—íÛÛ¿¼æúëòòÞËË­ê××Ü×ÞÖëìÖ´õö÷®žÙ×Þ×Ö›ýôýï—·þé–ÎùÜË´Ý麗®ïŸÓ¶½ÚíÖÝ´´¿¦§¯³Ÿëëëÿ¾ýý¯çÏóîÎêùïúú¼Þžì´Öì¼½´´Öì¼½ËÏþ›÷ííýýæ®Ý´´î¬û´´Í¯å÷Î뾧ٷÿó½îÏ뵿¶¼Ó¿¶¼þ¯ü½½½½´¿öŸíò÷î·Ùî¯üµéÍ´·Ö¦¯²ŸôÛߧû­«ý¹´žõå´¬¾ìõžõµŸÜ›ëÜ·–––½«çߧ¬ûͯ¬›¹êÞ–––öü³òçÍëÞÍžÞ«ù´ß×Óööú¦æ¹¹¹ô²ÿ·šÖò¼¼¾ëû­¾ÎÏ›·¿Ö–éδË߿׾¶ææí¿×¾´´ïõ²Ï´ü·ò¿¶ßééÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª®®®ûþÞªëÿÿÿÿÿÿÕª­çÙßç欫›ßæžý¿–¬®Ÿ›ú۞ͲëÛÛÖæ²å禳Ýõ¶í—û¿¿Ëìöù«›¬ù÷ýÏæ¬ï¶¿úííÿ¯÷÷¬ú®¯ÿÛÖµöξŸêžü»Ý²ëµ¾§žÏ´·ÜÏßµÏìַˬܷ«§ý§êÙÍÙþ¯«ÿ—÷êÖ·²Ÿë–ü¶ëÎßÖ´ÎÛ¿Ù×´ê´Ý÷æ×¾¾¾¾¾Ù§Íö—æíË—¾º½ë½§êÜ¿¶÷æù¯ººº¹ìûºº¹ìû¾¾¾ÏÖÿ—ÍÜ·êÜÜϺº¾×êúö¯Ï–ºŸ¯ºÝ봺ꛬµÛòÞÍé꺹Íͳú×¹¾Ü½»²ž½Îêêò²ô÷þûÛîν¿þü«ûìÍé꺹ÍÍéêÖÙ»–—›Ÿ®½ö÷–—›Ÿ›¯Íž­ýŸ¬Ï¬ù»Ö­çÖ›¬¬­§­––Ú¾µÖË–½­–ù¾¾µ´ûËÖûß½ËÜŸºÜßݭϾ¿ÛÓÖÎÛ–ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª®®¯ûÿÞªëÿÿÿÿÿÿÕª­–æü»´–ÖÖ—ú×Ûó¶šÝüíþþ»¼·ïšÙš×åæúóóÏë²ëÛ¹Ïæ–òÓë¿ËÞº—æõž«¼ÓûÖ´êêüþº¦¼ÓÚåýêçß»»ïË󯿴»Öé²þϺòÙ»¬õ濵ºž­–òý»²ÍµË²¾½´Ë§ú×½´´§š¿´–¬¼ô÷˲¾½´Ë§ú×½ºÏ»Î–­Ÿóù­Ëµ«›Ëµ—­Ï¹º¹Í¼–õú¶¹¶§²¹ÍÎÓ¶¬ööúŸì´ÖÖ½½¦Ÿ—ùËÓ–––ßêîß¹¯ü´µ¾½´µ¾½îºÛ´µ¾½´µ¾½¯ö­¯üî·Ù´´½¾µ´½¾´ßåË›§´Ë­–ºåé´¯ó§´´¯ó§ººÎÎÎ͵´½·Ë´½·æ´ò¯ÍëúõîÿÙòß¾®ÙºÙΧ–εݖ߼ޖíå«ü³ïÿú®·þºçôÍí´ïÓö–óÖ÷·ý²¯Ú²éÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª®¯®úþÞªëÿÿÿÿÿÿÕª­ÜòŸ´«¹¯¼»Û´óÓ¾¶›î¶êºçþÛúºŸê絿Ûåž²Þùµ¦ç즵ίη³ŸÜõó벬»÷–߭˧¶–´·›–¿òò®ü׫²Í÷Ëó¹¾–î—¾¾ÖùÞÞÞé÷–––òº»ß«åž—·ÍºÝµåž—·³·ºÎ´µß×˶ë޺ͧ—¹¹¹Í´´Íû¼êº¹µÜ«ÛµûìÍé꺹µÛ§Ü´³Ÿ¯´ÎÝ––Ý—®ÿïóùÿëëïŸæùÞÞÞé÷–––òº»ß«åž—·ÍºÝµåž—·³·ºÎ´µß×˶ë޺ͧ—¹¹¹Í´´Íû¼êº¹µÜ«ì¿ûìÍé꺹µÛ§ì¿³Ÿ¯´ÎÝ––Ý—®ÿïóùÿëëïŸæ´µëÿÍê´ýýýÛíÛÜôòÿþææÛíóó÷×›÷¦ÿõ¦—§ÍëÚŸýíí훲ÿ­¶ýóõ¦—ú뵶¶–ͽ׽¬Ó¬ÿ¬æÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª®¯¯úÿÞªëÿÿÿÿÿÿÕª­²º¿«Ýÿµ´Ýݽ–ߟܭžÜö¯Íõ¿õ½ööý¶—ÿºîï¾ÛÛõ§öò›õ¯ûçÙíõš–ëÚçÝ뺷´÷ÝŸ§í¬¿û¾š§¼Þõ÷ž¿·ížË²´µµ«õŸ§µé´¿šÛÖ–––æÍÏ·ò¼Ü·šî²íÛ§»ÛËžéµÚ·²º´ŸÛ§šíï–ò¶æžÍúÍ–ïóú¶úå鬚šš®Ëõù¹¯ž¬ÚÙ·îü³µ¶´·ò¹Þµæ×­í¶®þÙù¬¬¬Ú–ï´²é¼ÜïºÝµ²®ß·®Üˬ¬¬Ú³ý»¦¬«—š¾¹¶óù¶¬¬ššÚ¼Ü·šššêÍËÜÛï·¬¬¬ÚÞ»·®²ßî¾Í¯×þçͳ´Ýý¾ß¿´Ý¬é½¿ß§õ½Ïž·›—·ò¼Ü´–š·òÞ»´——²Ÿ««Ÿ¯æ׫—²Ÿ¬—¬—Ÿì›î¶¿¿ß·¾í´òî¹óÞ»î´Ù´íﹺ›ÙÓ¼ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª¯ªªÿûÞªëÿÿÿÿÿÿÕª­éßßÚ´½íòÛÛ¼ËßÖ–Í´¬´Ÿõ›—ÖšÎΧ¿÷ß—Íýß­šºßß—§òüÖÛ–§ÿ×›­¯¶ÓÓ›Ûݬ¬ïÛÛך›——ÍÿååÚ›ûÿ«ýþê¼ûŸ¶½––ÿ–––¿¯ûËï¶ßüý«ò¯Ï¿úﹺϹ괞õ¿¼þæλÓëÏëßê·Úֽˮõùܾýóžíóöúž«×¹žïÝåÛË·´´µ¾½½¾²Ÿ§Ûï«šÓ¼¼®šü³ï³ÿÿöööö¼¼¬³Ú´×¹ô»Ú¹¹®³¬«ô—óåëÝÎܺ½¼üû¦š×ô»ÚÙž²¬Ý´îÛÞõížû²å;ۧ—óÓÝùéê½­×Ýßææý›ËË®Ÿ«—¯ùî¦õížòÝßê´–šêÖõú»¼ÜþÛÜ˲¬ööööööÿüóóóóµçÜ»š¬·²ÓÓÓÓӶ쳯˖þ§þï—Ó»êÎÍùëëý–ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª¯ª«ÿúÞªëÿÿÿÿÿÿÕª­Ùïåû¿öë·¿çê¿þíÙ¼ºÜý½úòÞퟗ¶þûéþ¬–²Ý·ûÖ­§óÿç›í¼ò›µü¾³Ÿ¬éÛ»ùýº¼óï¯ç›·ôü¿íê¿íÓ§¯»®«ö¬ó³Ü·¶šåµù–žïͳޗ›õÍ­Ú—›íï–›–¹º¹·¦ê·ÖæúùùºìÿüüïöûûüÓ¹ºÚßç—µö·«ÎÚÞ¾ÎÙÙÚ«¦íÏÖ¬óÏÖ«ššîúÙ½ýÜÏÎÚúžíŸ–õþþÿõºÚÛߦš¦¼¶ž´¹–·¶žº¶¦»·–ž÷ºÚéë´Ú®Í§­¹ºÚßúòÚôõùùòûš›¦ôòš›¦þ®½¬ëæκÚÖÖΟ¶–¼¼¶¶›Ó–´´´´–´¼¦———ïµö¯šš––ïÿ¯šš—–µ·›òûçÚŸ–ž¹¼›º¹šòûçÚš–¶»—óòŸ—¼´›µ¹žºµ›–ô—ùë–§½½ììÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª¯«ªþûÞªëÿÿÿÿÿÿÕª­÷˛߲²§öµŸÛËÚ¶æÖÙ¶´¬÷ß¿ÖÛùö«­Ëò駟´¶®Ýï÷æ槚þó¶í–æßÙšõõ½úë柖ü³ÎúÍç—Úµûÿóë¿õ»ü«·Î¦¿µ¦í–ÍßïϹóïéšé—ËüË·­êÏ›Î뿶ڛ­­Ï–¯¶åû¶åí–æÙŸ´»Ÿ´»­¿¼´»­¿¼´»§æÛ´»ë嫹®«¹ûûûÝÓ¦½ŸÙü¬›š—ü¿¶­êü¬ûîöŸË»¬½ÿêµû·ÿú­ê–槬ûÍûï½í¦þÚ韫ÿßæ×¹¹¹ÎÖ¿úßé¹üš²×ÜöŸî¬ûîöŸÍ¯×üîïúöŸºº­÷þòëµí¬û´µÎû¼üù²ß槬û·æÜûÚÚ»öŸôﶽýüîžòòê½ÜÛÓ­¹Ë²¿íÓ¼Ú¹ìí²¿íÖ˾ëÛó¿ïŸºÍµ—­ëú˶β¿Ë¶ûöŸæܳùÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª¯««þúÞªëÿÿÿÿÿÿÕª­´òÛò¶ê›¬µôì›åÜž›êêš³Îþé­åšë®¦ÏöܯüþÛ欚š¬¿¶µËŸýêÏ®¦ööÓ»êžÜÿé²³¯Öíºµ§¬²Öﶴ´²æ¹Íó¹——½½ìß³Ûº›–¼þï¼Ëíü¼Ëþô·ßîëë¿þò¯×´÷µºÏ¹êÙ´æÜûû¯ží·òëõî¦Ëïžö¯ü´¿¦þÚ¿ç´žõ¶Ë–þÖÛ÷úÝç¹·þõžõ߬ÞììÝ´Û´²óæëÚß¿Ëö¼ô²ç–´õæ¬õÎêµÓšôßÓšó·®Ý÷ïúúúííí´´§¦Ó´–³¶ÝÚ½´´–³¼½–¬µ»®ÖÞ–––––ö¯üÙßò§žõ¬›»¬³æ·´žõ«þÖ–žË׺÷õžõ¬›»¯§æ·´žõ«÷ݬ®›Ë׾󽮚ò·ù«¿§Ùù«´ó³­Ûó¦òýïúúÿï¶Ë›ôíšÓ¾ê´¯üºÓ»ÜÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª¯ª®ÿÿÞªëÿÿÿÿÿÿÕª­®ýýý꽞–û¹ÝÛÍò¬¯ÞêŸÛé×ê­›éÏúæ˼Ïï¾ýŸÖê³åºìýüï›ÚîìÙ³¾ó¹üêþ³Ýº¼ü÷öý¿ÏÓýž›¯ÞôóÜ®ß׬ڶµÞŸ¾ßòù—®óù—¹¹Öý÷ìþ®Üî®íî¬ç–´ßêùô¶Ïž«¶ÏòÙÿÙ¶ÓÓ×ÖÏÓ¶¶åû¶µ½Ù´¿çî¯üÓë¬ûͯ¾š¦ô횦óýå®´ß¾îÏìî¯üíúÿ¬óæ´¯ü´¿¦ôß¿³–»ºö¬ûͯ×úÿõï¯üÓßö¬û¬ûÓÓ¬ÞÍÖßÖé·Ùî¯ü´¿¶¼Ó¿¶¼þ¯üÿì¿æìþ¬û´¿æìæç¶¯í´žõµÏó·×«¾îë—ºÖ­›ç½Ÿ«³Ÿ«µ¶Ý½–§Ûºî¯ü´¿öŸß—Úòö¹Üêì¾›¹¹¶¿¿û²ÿ´¿ç´¯ü´¿¶Í¹¿¶ÍÓ›Ó®½ßÚÍÍÍÜ´¯ü´åÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª¯ª¯ÿþÞªëÿÿÿÿÿÿÕª­öö–³öÛê›­³²§§ŸôÜŸæò«íóåöËËÞÚ××åÓ´žÎéô—Íݻ۫×ÛÙõúÞêÝÝ»ÓÜÞ¦ëÞ¦šßŸÜ׬½íæú»ìº»šú¼Üí÷››ëÜžêóµûîžõ¶¿¶·æ´¯ü´Ë»¼ç´·Ö¶¿¶½´¿¶½æšåíîšßÏôíîš»òòù²Ü·éÙ›¼¼¼íÓæ»îïÿæ»ûõßêùÖšÓòÙ¬¿®òËïï¯ü´úˬû´úÞôíÙ«¿¬ºþïõ¯–éêúµÍ¬¶­¿¿¿î»§º¿û¬û´¿»¯û¯Ýí¯ü´¿šÚû¿¬çõÚÝïú¿¶ï–÷¶î¯ü´¿šÙú¿¬æÿëÚòû¿¶òõÏå׫–––––––ö¹Ûçü¹ò§ûµºÏ·½¬›Ú–½´žó›ïžó¹ù®ïæ×òòïùßÚò÷ëÜï–÷¶®çæ󟺷÷íܹæÏöïܹæžéš½¹ó–ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª¯«®þÿÞªëÿÿÿÿÿÿÕª­—«ûçµ—Ù¾¾¬æÞÓ¿š«îÚÿìλå·ËÙå–÷÷¬õþæ«ÞËËëé³û·ç÷ÝžÚòî½Íö«§ßßÖ¶Ëå­ç×忽æ欴¾«ùù¿¿¬Ïþß´éÏŸ®ù¿¿ö÷ó¯ü¹ùô¼Ëòÿ¼Ó¿¼¶Ë¿Ö¶ýÛš–·üîž«çÍëÛêí¼Ï¹ê´û§¦ýçÚß¹¼›¹³ÙîËËËŸÙþ÷ù»¯õßûý·Ÿ»µÏÝ–åµÏÙåϵë§åϵ殧¯üî·ÙÎÜåÜùúÞ´´´½»»»îÍ¿ÛÛϼ´¦¾¾¾í›ö¹ß§»ÞíÿﻹëßåÏççÏÏ·Ûï›ÙÞ–žÙÞ¦ËÛÎÞÜç–´úû»›—®²ºå¦×»¾Ü­×»½´ÿëê›æ§î²Þ¶í´ù«´ßéËνÏËÿ²ÿæÿ¹«³»þÿ¼š¯Ë¦ùÙù³ó§µòßÜ·ó²¹ù¼×¼½ôË×¼þ¯ü­ú§ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª¯«¯þþÞªëÿÿÿÿÿÿÕª­¹´ßßßüüüξ§æÙšýê®Ë³óõ»Üôõš¬´÷¬ž¯¬æ¿÷´´¶÷ÏÏÍïºÎÍùººµõíÏü´¼òßÛü®åùÝ–¿»¶ï®üüþÓçç÷û¬—Ù¯ëî´û´ß׫«òòïùßÚòòïææÿÿ—êËöÞÞÞõ´êËöÞÞì¦ß÷¶æ¯Ùóíìüº·µµµ·çí–´¹³í³óµôôôýÏ»ÿöÏ»ÿ¯Ú¬ž–ö¯ü½¼Ï¼îÚ¾µÍ¹þ뫵¶¯²§½õÖÓӼͭ·Í›Ÿ—¾Ýç¿š§´¿¬–ÎÖ¼«Ù¹ºÎΖ–¯óù–––¯óù–´´§Ùú´–æöε¼¶¹Íõþϲ¬¶»«²§ºÓëóÿö¼¿¿¦óîššš¿úÞóîÙÙÙÙ›Ëú死κ½ü¯ü´¿›šË¿¬­Ïž§òû¿¶ò—þ¹½¼þ³ûóö–¼¼îÚþë²»·®Ÿ—¾ž§¿š¦Ó¿¬ùÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª¯®ªûûÞªëÿÿÿÿÿÿÕª­ÿ®Ó»²Îº¦—žžºî——õÛ–÷­¼žšË¬º¼š—›¦ž›«¬ž—š—¦ž«–¬¬——®–›šîí——š›šš›––š—¯š–—–š›šÙÙ²²®š§¯—íšæÎî§ú§Ë¼´ÎòÜš«—ìßߧ¬ûîß¾îÏìî¯ü´¼¼¿³ý¼¯Ë–æîÓ×»¾¯Ú×»½§Þëžçóº´³Ýíýü¼®õ÷¿Ó¦¹¦ùïõ´êò¯îÏÛ´¯ü´¼¼¿º«ì忺ºòææÝî¼ææÝýËåϵùÓåϵžÚåµÏ—ÞåµÏ¯ç½´¯ž––ææ–––––––––––––³–ÿ–ÿ––––––›³ò–³æºæ–æ–ÿ–ææ–æÝ––––®æÛ––Ûå–³–ݺºæ–準–––––––––––––––––––––––––æ溺–––——–––––––––––æºÿ––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª¯®«ûúÞªëÿÿÿÿÿÿÕª­Ë³Ùü­—½ïêÞë§ò¼·ò—¯ý¦½Ý¬Ù³é«§žš­Ÿ¿îºó–´îµ÷–Ÿ²­Ú¬çòúÛÛ§ù´êŸíû—åÖš¬Öå««§êÝ«®Öå¯êö½³ìÜ›¬ï¿¾Í¿¦ôß¿³÷êÓ¼·ËÓ¼·ú›öóö–»Óë´Ÿîé»ù¹Ë¶ëý·ëÞß×ëëë¼ôÓ¼æÙþõæýõù¹Ýûóîþþþ¼ù¼÷ݼ¶þë³¼»«Ÿ—ô³ûóû®¼ß§›ö»é²û®»Óë´ù«çÎî»»­ó·ú·­²ÞïºÏ«í«ùíµ×éšéšÖò¼ßéËνÏËÿ²ÿ·šûß»ÏÏÏìßíÓ禚š–š¼–žŸ–—­›Ö§¦é›¦Ù²Ë¹§Ÿô«»ß§ù§·šûßÿ–––––––åûûû–Ú¦³³¿çÎûºººÍ¼¯Ï½÷ï®Ùé—³–ϽÝí²½Ïíë›êïßé½÷¯·ëþß›åÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª¯¯ªúûÞªëÿÿÿÿÿÿÕª­öóí®§ßå—¬§®ùû®¯ýæù–ÝÛ¼óž·š»æëú¼Ú¦›¦×ü¾¯õ÷š–ÍÛéíÓ—§¦ïò––¹Öõï§Þ×ìÚæ§ÖÖ«šîæ­ííš­Úþ§÷µý›³–––žú–ùîÞ¶þ¦¿úퟺŸçŸ×·—ß®§Ïž¦Ÿ–­šžšÚö¬¹·ßÓ¯–——–õóëžš¿îöÖò»žýﳳܧÙö–ö­¦îù§íÏÖÏ÷Û­ëξšžÛ²¹¬ß–ÓÝíú·Í¬îõžš··³³åžéìÏÛõÚ«õß¿Ó­×–ÜÍ–Îëóüž–žŸ––¦–›–—–––š¦–ž–—›š–ž––žž––›žšš–——ž–¦¦–––š–ž›ž›––›š–›¦–šž–¦–›–š›—šžš–ž››š›—–—–––ŸŸ–––žž––—š›—–––––––––––›š–ž¦––––––üÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª¯¯«úúÞªëÿÿÿÿÿÿÕª­–Ù¬®²Öé²²§ì埫¦–Û毭¦Ü맬¬ŸÛÝŸ§›«ßçž²§Ÿê즳®¦ÞÚܲóþïú§æÙ§Úå§Ù¿´óüæåÙßµý§¬Þí·šå¬Ùòï—–ò¯Ÿ§»žüß˶®¼¬ËíÓÝ«¹Û¯ßÏÏÏÿ¼Úóú²ºÓÜþµŸ–¼¬Ëû¹çí¯ßÏÏÏÿ¼Úóú²ºÓܵÿ¦Ù´¯ü–¬¦óù¬ç´Ïæ§î¯Íߧí®ß¾î·Ù깧߾îÏìé—¦Ïóîú«þ»¼ž«ú«õÏõî´ÿß׫ò¯ü´¼¼¿ºî¼å¿Ö¬ÚÍï¹Ùë½úþ´ô×Ö«·ú¹ôç泬³´þ´Ýõ´ëú¹Ýï¹ëÏíÝ»íë¿óݶóëõ½Ýþ½ëïÍÝúÍë²ÖÝŸÖë¬ÛÝšÛëŸßݲßëšéݬé¿­öÙ´æ¶ÿù¿óú׶ÏòÛú׶åïßÛ¼«Ùæ·¯é–ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª¯®®ûÿÞªëÿÿÿÿÿÿÕª­¦µÎìÜŸú欬³çí¼éûÙ²ÍÎìµú¬ï½ßšÜÚÙ¹íû®·²Íòÿ¶éëÓûÞ¬½òÜìö»²¬›Ÿ›åêÓ¿ß¾½ç›¬³þòÜçé÷ýÓþþöú§îÚݬõ––—¶›–—–Ö÷Ÿ–ËË––ÙÜšžŸžÝÜššË¾ŸÖÝŸ–ËË››žÏÍžšÞÖ——Ÿ—Ùٖ˾šÙ×–—¾½››Ùþ—ž¾š¦—žÛÛ–—¾Íž–—Þÿ—ž¾š¦ÖÛ–—¾Ëš¦Ú×—Ÿ¦–ž–¾½žýÙ––ÙÖ¾ž–öé›—Öù›šÖÖ›×Þ——ÍËŸÙÛóöž›šž¾Ë——š¶éÏÞ¶Û·Ú¬·¿º³¿Ë­¼óß²ëù«¾¶Î³¶ûµÜÎλºÏ·íÚ¼ÏÖÙì¯éΖ³Ó¿¿ËíÚ¶—Íë–ï¶Í§ÝþÏíë´²–··Íë–¶üµÿßߧ¬ûÚÿ¯—¿—þ÷ó§·Ùæ·–ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª¯®¯ûþÞªëÿÿÿÿÿÿÕª­÷´Í¹å«¹®¹²üþ¯Î»ÝÏþŸÛ´ÖóݹõïÏ¿»–ïù¦Ÿ»²´›Þó—β´´çÚ–ÍΫ›«¹Íééìö¹–«´Î²—ú嵚»ýß®ßßÓ¼–––·Ú«µß·—ç›´æóš®·öÿ»Ïöÿ»Ïýýý¦²Þ´æóžÍù×çúÛ·«×µ¦ùô¶Ïòÿ¶ÓÓËßú–ï¬ûæ¶üôžõ¿¼ü¬æÙ³ù¼Ó´²ß§¬ûÍ¯í´ºÙÎíýì–ﶹó··÷¬õ÷Ýíï´ß½Ï®ÙÎåϧﴯü´¿öŸÛ¹ú¬ûͯíùºÎ¿¶ºü¯ü´¿¶ºÎ¿¶ºÏ槬ûͯ—Ζôíž÷ûŸžÎÎÍߧ¬û´Îµ¯Ö–íçô¿óžõýÍÜÞ´ÛºßÛêù¼´ë›öìò¿ïžõ¿¼þê¿»ÓëÞõÿïü¾¼ÿ×û¼÷ôÿïî¹¼ÿ×û½ö¹ß·éŸ·Ùç;ßöîÛµÍß«ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª¯¯®úÿÞªëÿÿÿÿÿÿÕª­®ûÛͳ´ÿö½šïÚîÓŸûî›úšÝÞó³åÿŸüÖßü½¬ë­óêëù¯ËÞß®çóëþßëû—®þýϯýÚêÝÏËÿëÙ·ÿϺܛêÚ»ÿϼÿËæì»Ó³þž––çÍËÚ¯ºµ¶–¼¼¶¶›¹º—¼»»¶›¦úöÖ´§ûûúý½³¼üì®–½½ìçºî­—òù®–ºµ–—òï–žòõ–ž´µ–—Ÿ–ôï–žš–îõ–žš–¼¼¦µµŸ—òûçÜ—Ÿ—ç´ï´ÚõÙÓýܹ§¦î–ž–óóžåÙÙæ——ŸóóžåÙÙæ———òúÙ韖¦ôþ­¦––›îúÙß›—¦µ»—Ÿ–òͬ۟—Ÿ–òÍ«ÞŸ—Ÿ–ô½ß›òšöòšîžÓçšžôîž—¦š¶¼—–žòüêÚ›¦šïôž—ÜÙŸéÝ×榚õϮ֖—¦—ôÏ­Þ–—¦—ôÏ­Þ–—¦çÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª¯¯¯úþÞªëÿÿÿÿÿÿÕª­Ö곿µË·ÖÙçúõžž»¿÷úëÛ´´–š×춻ééÿýÜÝéåܦíšþü÷­­å×–µùÝŸ¬Ùßåê¦ç«åÓ½Ëï篮æ寞ìæ§ê›ß²þúÖ榼糬§ÎÎÎί¯§›ÏË–·Îó³þÚ훺´ŸšßÝ›ÎÎιåÖ·½Ÿ¯Ó¼º­ì×´º›ÜÚÎÞÙκº›Þ׽Ξ¦¬¯´¼§²ÿîÏ´ü×·ûûþ¯ß¼šþ¬òõöúžÞÝ–ï–õóß½šËÚþ–––«ÖË·½´Ë·½›·´½½´´½½§Ùú´–æÿÜ×ß麖¬—Ϻ–¬Óæëßå´Üܽ½ÎÛù–ÿóË¿³ž­Ë¿³žºÏæ«ì¼úï·Ëúï·Ëûò¶¿ûò¶¾æ×ÓÓÏÏϺæ×ÝÓîÎÞ«Ù´¼Ï¼Ï¹ó¯òÙÛëû¼š–§–´½ŸÖݬ¶½ÝÖϽÏíûºººžš¦—šòÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«®ªªþúÞªëÿÿÿÿÿÿÕª­îýæߟ¯žéùµÖßßí¹²½¶××òºÝ§›ëÜšÏÜÜͻϬÚ×éé²ëéšþ–ó—ô§÷íå˷Κ²–¿úÛ–«¯¶Ûþ½½²®ëÖ¾ËÙݳ«Ö´ôž—ò·òòòúßÚÎÿååÙÎÿåßéþ÷šçöÝëúÛíþþ÷í§õõý®·½æê®·¦¹·«Ó»¬Ûíž®·Ó®·Ó®·Ù§ùÎÿõ¹·ï꯶½åêþóç¯ïšïõ«ºßéÚëíùßéþúéíÝëýÜõ½Ùßš½þÜ믶Íé쯶幦§õõæå«»½Û»¬ººÿååêþ¿¿º¯þöçéÝ»­ŸßÜ«ßܧ¹çìþëæÛòý殽ë駧ŸëÛìýÓæºÿ«µÓÙêúêÓž÷¼ôÓ·÷ï´åÝó¯ÿýõÖçÙÎÿç槿ºÎ¶¿º¹÷éëÙ÷êÓýóÚôÓ·óëåÝÎå¯ÿô¯ž²ßíú¿¾Î«ûüÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«®ª«þûÞªëÿÿÿÿÿÿÕª­›µ¿³îý­§§›³¯³þí¬ÎµÏ¿¬½ï·öêê®åì–çÖ¯³Ÿ–ö²÷­ÜÝæ«ÚÙæ§æ´í½½íß½×宦¦š—›–›–¯²––š——š–š———íŸÎΦŸŸ¿ÎŸËÍžž¦›–—¾¿¦Î½›ž›žŸ¾¦ß×–¹Ÿ››¦šŸ–›š¾¾›—š¶Úß–––––––¦ì즖–ßô¦–šš¿ÎŸŸŸš¾ÏžŸÎË—–›Ï¦ßï—Ÿž›—›¾Í¦–Ÿôï—Ÿž›—›¾¾žŸ¦îí›–Ÿž—ξ›—šž¼Ú󗦦»Úßß–––î¾¾ÖºìÓ·Ùž§§«×––––¼¼–§§–««––––––šš–žž–––––––žž–ËËšš–Ë—¯¼ÎΖ¾¾–ßߧÖß–ÏòêΖÎΞ½½½ß–û¯õß¼ÿ–––ßžž––––––––––––––––––––––ßÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«®«ªÿúÞªëÿÿÿÿÿÿÕª­´¦òþ¿ûßù»ê›ò¶›µ›·ÎŸé¿×¹ËÛ®õ´«–³õ—û¿¿ëííšÝ×òôçšßúüó´¶æý¾þÝßüí»ÝŸÙ´›Üöµ¿Ýõ²îò¾ÿ¯§ý÷óö­×»»ÝòüúËéÜßÙ›ëýõõË÷·–›®ÿúÛêßÛîüšÙ—ííéÚë–ïͶýòµ¼¹òæ·ë–ï–¿¹šÝ´¼Ù¹¼ú–õµ¼«óöúŸç¼šý÷¦¬óù¦Ýïæ×ÓÓÓÝÞ–––––––éö¾Íööóóó¼½ûö÷¹–ºì–š–––¿îÿÿüüÿûüÓ¶´¿êÜûÝÎûݳëËëö¾þòóùþê¼ìúßé篫—ß÷Ÿ·ûþÚݺ––÷»žì¬×þòóùþß»ìû뺬š–¶¦íÛͦéçÙÜÙ²çÙÜÝß¼ÏÝÝÚÛùþÓ½þÿÝÛÛëÙëåýÿúÛûùÛÙº»é¿¯õÝÍÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«®««ÿûÞªëÿÿÿÿÿÿÕª­––®®›ÏÍš›–­ç–ÛÝ´þü–ïšš§¬–§­›¬¿¹–§§––´¹–¹Ö÷§´´–ííÓÿÙîÚ¶êÓíÖçþ—ÿϵ¯Î´››®®–ššÖÖéé—¯ý¾§§–šíò¶¼—»¼––é––òšî–í½––ŸŸ¾¾––––––––§§–§§–§§–¼¼Î¹«¾²¼–––½—¾¿ŸÍËË–½½Î½ž½½–¿¿–Í¿ŸÍ½ËË–ŸŸ–––½½–½½ž—––ÎΖ¾¾–¾¾ËË–¿¿–––›ÓÍ–¾¾–––››––ÍÍ–––Ó˾²¼–¼¼–¼¼–§§Í¹§–§§–¼¼–½½–––ËË–½´§–§§Îº§¾²¼Í­¼–´´––––––šš–ŸŸ–––¾¾–ËÓξ–––——›Ë½½Í½Í¾—½Í¿Ÿ¾¾–ŸŸ–ËË–§§–§§¾µÖÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«®ª®þþÞªëÿÿÿÿÿÿÕª­Úþ¶Üµ´½ò¯›²»¬õ§ß§šÏšõ¬ÙÛÖͲõÙÙšÖ§§¿­ùßקÚïﶚúÖߧ¬¶ú¬§½«ùåæ—š´÷×Ù¾¶²»ß»ÝÛÍú»éµÝêþ»§úû®ÚÚþÖÖ––ýõÓê××êê××½îåÜÜååÜܽîåÖÖßß×Ýúýóóýý½íß××ßß××ü¦·ßüý«µÛºßæÙµÛºß××××ßß×ÝÓ´—óºß××·¹úô¯÷¹åÖÖ·¹úôµÛ¹åÖÖ·›ê´êóóôôôô½íß²ÞåýýÝÝ–ååýýÝÝ–Ýü¿×ÝÓîåÎÎ××ååÎÎßßüŸ·ë³²û¹ë³²ûûæììç›ÙûÏÝÝ×ÿÏÝÝÓó¼Ú¿ß¦êþٿߦê®óֿߦꞞü¬ë¿ß¦êžžó¦ç¿ß¦ê¯¯¶ê›¯å¿ß¦ê¯¯¶ê­¿õíë²µÛºß×ݳµÛºß×ÝÓ­ÙîÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«®ª¯þÿÞªëÿÿÿÿÿÿÕª­«½óôóþì·³ÛÛÖ›²–í¶ÿ¦ýÙ–½òùûü»·ò¦ßßÛ¦ì姚³Íóóüúæí´òõ¹þÓí½÷´š¿òúÍŸòÍÞêžšš§¯Ü«×ÜÜ®¦­«—¦ü¾ÛÛßéÚëßË––ôÞ¦ôÏÚëßË––ôç­ôÏÚëç½––ôþÏôÏÚÎË›½Ë–ËË–ë—×ôÏÚÎË›½Ë–Ëô¹óëÖ›–¯ÖÞ¦ëÖ›¯Öç­ëÚ–¯ÖþÏô–õëŸÚÜÖ­Ùž×Üí––îÍ÷Ó»×®·Ó®·ü·þßæýÓæç¦ÝßÚº½·ö۷٧ֶ曧—ôûÛ»¬¹Óýóúé–Ùóúé—ÚóúÖ²²¶óë릵å÷êž«×ëÖë·Ó®·¶»²·Öò黦Ɜ×éôÓÝ·Ó®·Ïë¦ôŸ²´ž«×ëÖ—ôûéÎÿóúé–Ùóúé´ïóúå®·Ó®·ßϹ§ý·öÛ·ßíÖ§ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«®«®ÿþÞªëÿÿÿÿÿÿÕª­—–š–›–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ý–š–ÿ––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«®«¯ÿÿÞªëÿÿÿÿÿÿÕª­÷ÍÝšü½òµÍŸüÜ›ší´òµ¦ž—µž·ŸéÛçî–²öµæíó¯ùÖ–éöÎݼ¼ý¦¬ššêÜ—«ü¹÷çô»çòîÿ¬®®®å×–®óÿÎæòËÞýïÍü›×ÏÛö®·óúéÞ—«¦º®·óú®½Ï§¹²«®·óú®¾Ó¯·æÙ›ßÝ®·óúß»ŸìÖìݦò³¿ßÝ®·óúß»ŸìÖìݦôŸ³¹®·óú§õŸïíç®·óú®ž›õ÷º®·óú®½»ç¾»í»ÓßûŸô÷íô–·®·óú®¦—§Ÿº®·óú®½Ï§¹ßì®·óú®Ó¾¯·æ×ßÝ®·óúóçßÝ®·óúö–ìê­µ½çÝý·Ï¾š®·óú®ž›Óµº®·óú®½ÏÎìÏíÛÛßì즺––òßËòß˺¦¦ÚçýÎÚ­º–––Ë–ËË–²­­ÚçýÎõϺ–––Ë–ËË–²ÏÏÚçýËÖ›­—ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«®®ªúúÞªëÿÿÿÿÿÿÕª­ü×ÿçýé¹®–Öß½Öí§÷¯·õßùûû²Ü¾ëå¿Ÿß–¹ó½–óéüíÖî·š×—ííí–Ö´Öíí–Ö–í´íÖ´Ö–ÖÖÖÖ–í´´ííÖÖü´ü®—Ú¦«ßš««š–––––––––––¾››¾Îž–Ÿ—–ËËË–––––––––––š«Úæš––––––––––––––––––––––––––––––––––––š««š½›¦ššŸ››¦Î½–¦š¾½›–¦—–žÓ¾—›Ë›š››Ÿ–š««––––––––––––––––––––––––––––––––––––––«–·š—–¦ž¾Ë–š¾Ëš¾Î¦›¾¾š–––Ÿ¦—š¾Ë¦—¦—–¦¼–Úó–žž–ͽ›žÏ¿›¦ÏΟ˽›–Ÿ¦—Ÿ¾ßí–››—š–š–¶ÚßÍž—žŸ¦–;žž–¶Ú–ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«®®«úûÞªëÿÿÿÿÿÿÕª­šéÙŸ¦ÎÙý×ô¾²®þ·å—ºÓ¯®íÿß÷Ú¾öæÿÜùë¾òÞúéóÿýÝú³›Ýó¶«ÿú›«Úòçù×ï×¹üæí›–—–šÞîåËÿËš–ï粒˫²³®××ÚçýËÖ›­ŸóóÚçý–õߦ¯×º––µü÷Úç¼ùçççùêÓýßþæ×ßÙôÓÖߦöòõíÖê·êÜÓÜÜËÜ®êÓí÷êÛåÖûîìéæÛŸ·Î߯ܲ»½ìÖ³²·Îߧֲ»½ÿíý÷»½–êôÓ­¬¬­­Öž³´¾Ú¶íéõŸ­ŸßÜóùßÓóúó§Û½®Ÿ›—³––––––˼š—³–––––––¶—ž–ïòŸ»–šŸšŸ–—––«šŸ¯›®Ï¶´Ÿš¹—–––¦––—–––›––—––³––—µš·–ºš¼åšŸë––—–––¦––æ²ÜÞŸšÚ––›–þšŸú—ù²öôŸüÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«®¯ªûúÞªëÿÿÿÿÿÿÕª­í­ôÎòìÙ»ËÙµù»»ßš÷ööõ¯µ¿³µýû÷§ÚÿýìÏ´æý×Ϭ潚·ÞêýÍù³–ÿ½ùÞë½Ëݹûîúúùç¿úÛë½½ÛÛ§®Ûßߧ¯×Û§–³ÞÍž—žŸ¦–ÍΗž–¶–ÚîšËÏžŸÎΦŸŸ¿ÎŸËÍžž¦›–—¾¿¦Î½›ž›žŸ¾¦ß×–¹Ÿ››¦šŸ–›š¾¾›—š¶Úß–––––––¦ì즖–ßô¦–šš¿ÎŸŸŸš¾ÏžŸÎË—–›Ï¦ßï—Ÿž›—›¾Í¦–Ÿôï—Ÿž›—›¾¾žŸ¦î훦šÏ¾›—šž¼Úî–šš¾¾›—šž¼Úí–žž›–š¶Úò–›š¿¾›—šž¼ÚóžžžÎͦ–ŸÎ——¾žŸ¦¶Úó––—¾Ë–˾›ŸŸµÚôŸ––›š¿¾›—šž¼ÚôžŸ›¦Ï¾›—šž¼Ú󗦦»Úßß––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«®¯«ûûÞªëÿÿÿÿÿÿÕª­´ïÙÛß®Ÿéëæß»ïÜæê´üì¦××êÜ›ÿõ¶ºµÓ›º¯ùÜßÛ³÷ùçÙ¯úî³Ý뛺ü½úì¦×ò÷éß®ÙÞ¦—ÏåÛíÍýÚùùÚšç¹õ§­—ÚÙ§ÿ½úÍÙÝ÷»š«ù­Îíï­»»¶¶ÓÓË˽½ÛÛ««³³ÙÙ×׳¦Ë¦Ÿ——¾¾›—šÏ³§Ë——š¾–§§¦Í——š¾¦¦§§¦Ó—–›—Ë–¦¿šš¾¦–¦§§›Ó——Ÿ—š¿›§­½–šž——Ó½š———Ó­§Í¦Ÿ——¾¾›—šµ³Í›š›—žÎ¾›—šÏ³³Ï–žžŸÍ³³¦¦³§––§ïóïßõºÏ×æëÜקçÍöüò×ß¼¾××ååÛÛúË×ßßééïõí󧫚úùóóùù·÷é켯Ïéüî¬ÍÛ¬¯³òéÞòôóïôË–«›¹ëžêžÝ×ìéÝ×ÝóúßééÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«®®®úþÞªëÿÿÿÿÿÿÕª­–Ú–ç÷´õ¼ŸÙöšíÙïÛ¹éß®®í鹧–¦›šîÿ®¦¦­³§¬«çß–§–§ßÖ§ßÖ–××ÖÖ––šš´´šš—›ïí–´´¼­Ííü²—ìꫧߖ–Ù²é–隶¶¶·ì–¾–¾–––§§–§§–§§–¼¼Î¹«–¼¼–¼¼–šŸ§§––––ÏÏ–¾¾–ÎΖßß–ßôÎûºë––§§½½––ß–û¯õß–ß–––ß½½–ÍÍ›¿¾––––Í͛˽½žÎ͗ΖËË–¼¼õõ½Í¾¾ÎÎé––òËß–ï¿–––––––––––§§–§§·¼–¼¼–««¾¾––žÍ–¾½–—¾Î–Ÿ––˞Η¾¿¦Î–¾Î––––––ŸŸ–––––––––––––ÎΖ¾¾–¾¾ÎΖÎΖÍÍ––––¾¾–ÍÍË›½½žÎ–ÎÎßÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«®®¯úÿÞªëÿÿÿÿÿÿÕª­ºåÛæ¿üë¹õÛéß¹üÚò–—·Ù´×·ï—›–ÙÖ—ÖÚ›—ííšší—´µí«Ö³ÙŸþ®µúûš´¾ÓžçŸç—Ÿó›¾ÏòËÝó²çžë­û¬Ÿ³¾¿­ç­¦§üþ–Ùßò¯Ÿ«ÞíùÞò¹íÍÏ××קçÍ»åóóîîîîßßéé®ížùóóùù§üò¹›¹çç–óòéç–ïíëåÝÚšæßëë–ÝÝšíÍë–ÝÝšõ«ë›¹ë¾¶ÜëéÞܼά–––––––––––––––––––––––––––––×ííííí·½ûòÛéûÝÎûÝþþòóùþìß韗––Ÿ––›–—––¿–›–—––¯–—––Ÿ––›–—––÷––þþßëŸÛ»ïß»þÛ»ïëëºû믯êùÝïëû–û÷÷÷÷÷˵ͦټý²¯¦Ï¾ž›êìßõ­«þ÷ëÚêµò®ëóµ÷ßÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«®¯®ûþÞªëÿÿÿÿÿÿÕª­–››šš––––––šš–šš–šš––šš–š›—––›—š––šš——––––š—›–——–››–––––––––——––––šš–——–››––šš–šš–šš––ß««¾Î–––ÎΖ¾Î¾¾––ξ¾–Ζ˚ΖÎν½–ÍŸ¿ÎÎÍÍ–ŸŸ––––––ËË–¾¾––––¾¾–ÍÍ–ËË––ÎΖ¾¾–¾î–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«®¯¯ûÿÞªëÿÿÿÿÿÿÕª­›–¹¹—í¦º½íÚコ»ŸÎ÷ºÏ³Þ³º¬úíõý·çû›ž¹¿¬›«éÛÍ«Î÷מÍ÷Þž¶·žÞÜëÖþô¬·÷óûÛÚ–óÿìóËêšöû®¬¶Í²§ô–––ž¿ïÝîéÝÝÝûóÙ´´Ûÿöìë­ï¹ÓöúëòÙÜ׳ÛæéÝúõ²ùö²ùöü¬õÍæÓìììÎõ½ôÞ´»Ûž×»ÏéÜêÞëÏÛž®­¬²ôî²·ÜÛßîüž§ÿéõ½¹Ý¦çιžìþ³×ÛíçÓ²³×Ûöæ÷÷Ùû¼ËÏ·úöË»þû›²ßÖüî«ÍÛç®Ù¿é¹ÎÿòöŸîºš«êµÝöù²¹ç–÷õ–˺½Ÿæ×»¯»´—¼Ï§ü»×ºæ×릞íÿ÷ºÎš¹¹ï–æå›­¾¾¾Ùõú³þò—ùýµå«žíÍéú¿·¬í®ží¬¾´šÿé—´šýò˺üåÛ­Ûç½µÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«¯ªªþûÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«¯ª«þúÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«¯«ªÿûÞªëÿÿÿÿÿÿÕª­õõõõ²¯òï¿Ù½æ¬Ù¿ôö²þ»ôùíÜçå­¦ÞÛëþšÍ–¶ÿžÖß泞šÝŸ›—¶šï×›¶ëϾÿ»ï½îåºôë²—µ–¶šÛù¾Íšíïõ²ó–¹žßÜûû×Ù›ÞÞ×ù½ÞÞ×û¿ÞÞ×Ù¿——›––··ô·¦¹·æ½ßÙûûÙÎÿûûÙ–ÙûûÙ´ïûûÙºöûûÖß×íù›ÓôÚÏÿµ§Öߧý·¦¹·Í´¯Öܧº÷¼³«Þ·Ó®·¾û§½Úòßùÿþëé­æò÷ºéåýº§ò÷þ®·Ó®·ü–ëí§§§§§÷»«ôµÓæêßÙöþç÷ò¶óÖÙºÿçþåùùÙúÛߟ¬³—ì÷Ú–·íšÿçêú›Î«¹Ï¬º–··ô·¦¹·ææíšß´ß§Öη¦¹·ßÍ–—žžž›Ÿž¦¦–š¦—›¦––––––››——››››¦›–ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«¯««ÿúÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«¯ª®þÿÞªëÿÿÿÿÿÿÕª­———–—–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––žž—ž––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«¯ª¯þþÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«¯«®ÿÿÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«¯«¯ÿþÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«¯®ªúûÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«¯®«úúÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«¯¯ªûûÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«¯¯«ûúÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«¯®®úÿÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«¯®¯úþÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«¯¯®ûÿÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«¯¯¯ûþÞªëÿÿÿÿÿÿÕª­ò·ÿùõ¶—­ü¼Ó·º¿–ÙåûÎÞ¿´½÷Ù峬¬§òûš´Í¿–ïŸßßÖš–¶Öí–Ÿÿßž¶Ï½®–²ÛÝ¿ú§Öß×›²¬Ù–嫧æí¿ååÖßž§Üßéþòæ½ûììßéþ–ûÙÚçÞõ§ÝþòúöýçÙüšÏåßÙÿÝݵìëÙ²öùë³åš÷õêºÿ¦³¦ÝçÞõý¯¶ß´¶ÍÙ½»ëß¼åúßéÚº–þÝ–¬Ó´¹¯Ó¾ù曼½åíÓ§—®ë´ÿÙýÓßÙš—¯Þ½ÿžÝ÷Ó¶¹—Ûí–––÷ï¬úßéþ§›¹ž¼½Î½­—¯Þ½ÿžÝ÷Ӿ﬛ýÓçæ×î½³—é–­òúüôíûÚßòý®·Ó®·¿º½·¦¹·ù«ÙÏÿµ§Öߧ֖η¦¹·Í¼¬Úݧº÷ç–²ô·§§§æíúη¦¹·¶»§»ÓýûûÙ–ÙûûÙæÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®ªªªûþÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®ªª«ûÿÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®ª«ªúþÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®ª««úÿÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®ªª®ûúÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®ªª¯ûûÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®ª«®úúÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®ª«¯úûÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®ª®ªÿþÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®ª®«ÿÿÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®ª¯ªþþÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®ª¯«þÿÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®ª®®ÿúÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®ª®¯ÿûÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®ª¯®þúÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®ª¯¯þûÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®«ªªûÿÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®«ª«ûþÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®««ªúÿÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®«««úþÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®«ª®ûûÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®«ª¯ûúÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®««®úûÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®««¯úúÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®«®ªÿÿÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®«®«ÿþÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®«¯ªþÿÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®«¯«þþÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®«®®ÿûÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®«®¯ÿúÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®«¯®þûÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®«¯¯þúÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯ªªªúþÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯ªª«úÿÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯ª«ªûþÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯ª««ûÿÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯ªª®úúÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯ªª¯úûÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯ª«®ûúÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯ª«¯ûûÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯ª®ªþþÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯ª®«þÿÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯ª¯ªÿþÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯ª¯«ÿÿÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯ª®®þúÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯ª®¯þûÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯ª¯®ÿúÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯ª¯¯ÿûÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯«ªªúÿÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯«ª«úþÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯««ªûÿÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯«««ûþÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯«ª®úûÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯«ª¯úúÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯««®ûûÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯««¯ûúÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯«®ªþÿÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯«®«þþÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯«¯ªÿÿÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯«¯«ÿþÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯«®®þûÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯«®¯þúÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯«¯®ÿûÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯«¯¯ÿúÞªëÿÿÿÿÿÿÕª­éÖÖÖÚÖ–íí—š®´¹½ß––¶Îõ¬ÖµÚÙîÖÙ––ŸŸ–®––®í–š—–––å»————§––ÖÜžšº¹––éݲš¬ž§žÓ´§Ö–´––®–­–––ºš§——¯¶–—¯®ž¯½–§³¬›—§«µÍºŸ–ž¦š––––––Ï—––´¿Îš¶½¬š§––––»¦¬–——ššºµ¼§––––––——¹­––––––––––­Í¼´®›´´´µ—§§–¶¶–šš–––––§¾š¹¿š–Ó–––––––Ó¶¶––´³–šš–¬¬–ž—®·¹º–›¬ž´š––´´––šš–¿ž––Ó–µµ–––——–––§¿ÎŸ¿¬»®´´½Ï¿—»¶¿––––––––¹¬—–––––¹¾¬½–––––––¬¿¿¬§§´´šš–º»´§––Ó––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®®ªªûúÞªëÿÿÿÿÿÿÕª­ü–®–›´í´–––—š½šõßþšÓšµ––›Ú¹¦›––§§½é–›–––––ÍÖ–›–––éÖššš—¼·–¦›§›šžš¦¯­¯—í—µ´í­–––³–––Ó–––§§¹­–ššµ¼–³›Ë¬´¶§·ž›Ïµ³––––––§¿¯–––––––´³šš––¶«Ë§¹¬Îº³—³–¬¬¶š´´¬ž–´´––—³µ–––––´³–––––––––½®¼®¯¼³¶§–§§–––––§¹¦–Ó–––––––Óšš–––Ï›š–Íͦ›§µš–š¬®®·¦Î¾¦–––––––Ó––§§–—­—ͧ–––¹¼¬¼³Î–¼–¶¶–š¶«ž›–š–š–®·––––––Í›–––––––————––––––––––––¿—–Ó––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®®ª«ûûÞªëÿÿÿÿÿÿÕª­é–í´›––óí—²–––šší–÷§›ó§§––ï—––––®–––®í–›–––š³ïšš––®––––—§½º¬§«—š—š–­¹Ö–––—®––³–––Ó–––´»¾–––––žžÍº¶–šš§¬Ÿ¾Ÿ¹¶š–——–––´³–––®§½¯®´¶§§–––´–´´«ŸÓ˧««§´Ÿ·Ë—–šš–§§––Ó–––––––––´³šµ´›–––´´–––´´——––––––––§µÏ¾—–Ó–––––––Ó––§§«»–´¾—¿»––Ÿ«½§–§§–»­›—––––––––»«––λ¹–¶¶§«µ´––´¾µ­½–¹®›²ž··¶§ž––––šš–––Ó–––––––²·Ÿ––––––§§§§–¬­—µµ–šš–§§šš¾Ÿ——––Ó––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®®«ªúúÞªëÿÿÿÿÿÿÕª­ü§–›–´ß§–––§²«žž–Ö¹«¯ü–­®–´–·––šš–Þ½®––Ö´–––®–´´—š–šîÿ–֗ߦ¯››–í–—ý—š——®––Û¹®ó›––š›²–––Ó––––––––šÓš—–—–––§§½¦–––ºµ¿šËµÍ­—––––––––––––Óž—´´–§½³§¿¼žžºµ–­º–§®——–§—»––¯—¹²«––––´¶š––§¾¯Ë³·ºÓ³µ¶–¬¼–––§§–––»¯–Ó–––––––Ó–––––––šÎ––½¹š­ž——––½¦––––º¬ž–Ο—–––––––––––´Í˧––––§§–ž¯®žš¦¹´–šŸ–––––´³–––šÍž–´´´´››––½½ž¼¶§§´´–Κ¬¹ž––––––ϵµÏ––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®®««úûÞªëÿÿÿÿÿÿÕª­ü®––›§§í–´´–¬«®®²úé´í´ó¹­–––š—–––û–®–Ö–´–––®––íòššš¶éÛ½®›¦ž–šùê¼òí³šš§§§§§Í´–›––š—®–––Ó–––––––´–­¹¹––––´³–––¶®ž²³«¼––––––––««––´³§®––––´Ë«›—³½–®¾¶´››––––––§§¹­––Óž¹µ–—ž–§§–––;—¼¯—¯®Î¬¼–šµ¯–šš–––––§¼–Ó–––––––Ó––––§§–ϵµ¯®¿­µ®®——––»«––´–­Ÿ–—º¯–––––´´–––¹³–¬²–´¹——–ÏϛΖ¿Ÿš––š¦ž–¶¶´§¾ÏŸŸ–¹¦®––––´—ˬ––®—Ë—¼–šš––§šÎ­Ïš–——–––´´º²žÏ––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®®ª®ûþÞªëÿÿÿÿÿÿÕª­í–––›ïïí–––—šÍéÍ–éÛ´ý—é´í›–›––´´§îöý––––í––§––›–––®íÖ–ÖÜôÚšú­­þ«§–®®®®––Ö¹û§®–––³–––Ë–––––§¼––––··–§½®½––Ó–¯³Ï—²®´´–Ó–––´´–––––½¦–––––––––¶·Î¦–Ó§«—––––––––––Κ–––¾š––––––––––¦µ–›¶¦–´–¯»®šž–––——––––»®žÓ–––––––Ó–§š¬––Ï—–––ÏÓ—–—Ë—–´Í¼¿µ­µ¶›––š¶³–––––––––¶®—––––´³Ëº­Ï»ž§¶·–Í——¼µ––––¼ËÓ§–––½²«–––––––——Í–»ž²›¾–—––Ï––––——––²Í§—Ó––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®®ª¯ûÿÞªëÿÿÿÿÿÿÕª­÷®–¦´–ÖÖÖ–›ÍÙæí¦Úí´Í›——³´íûß–š›šÖóé¹Í›–––´Ö–®§®–¦››–§í´Í³›«—ßײ¹å¬–§®ž­ÙÖ––í––§§³–––³ºµ´––´³–––´¼žš–ÍϬ­¦Í›¹³»¶––½´«Íš–––––––––´¦®–––´´–—–µ²¾ÏΖ––––——–šÍ—––––Ó––––––––––´§›¹š´Î§§®·Íšž–––––––––Ϭ­Ó–––––––Ó¬²–––Ï–µ´–²³—––ˮ˲ºµ´¯Í›––´´´––³–––––––––¹§›––´´š³Í³¿¬¦¯Ë–ž¦š¬Ó˺–šš´¹²º——–––§¼–––––––––––¬¼š––´µ—––½¦––––––––»«–Ó––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®®«®úþÞªëÿÿÿÿÿÿÕª­ü–®–›í–´´–›–§½ÞìÖé쟲îÖ·š´òµš›ÖíÖü–í®—š––––í®––¼»š–®–åùí›î·šÚÜÍÏ«—Öé—¦§«––´Ö´Ù›¬––³–––Κ–––––Ó–––§³¦–«Ë«®Ë—²¹ž¶Ï¾¦–––––––½¦––´´–––´¿¼š––½Ë­–·š¶®¯´Ó˯²Ÿ§½­––¹´§¿³š––––Í›–§§––––––––®Ë¿š¶¿Í«¾­––——–––––––Ó––Ó–––––––¼§——–´¦§–––šš»š¾¹¬²š¬­»§ÓΚ––––——–Ó––»»–§§–Ÿ¾––––¹¹–½®¬–µÏ²–¶¶®ž½Ÿ«—–´–´––¶³š–––––´³––––––––––¬¬ž–›š–––––––šŸËžž–Ó––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®®«¯úÿÞªëÿÿÿÿÿÿÕª­ü–Í´›–¶šÖ––›–éÚ·Ö´´žŸÛ¬Ù–ÙîÖ››–––¬šü–›–––––ü–ÖÙ—––®–ÙÙšÓ²îîíÛ¬š››¯—š³Ÿ®Ö×󞟧–§¦–––Ï—––––´Ïµ–—Ÿ´ºš²Îž­›š·›Ë»Ó¯·––——––§§Ó––––šš–§—º›–––—µÍ·µµ–—³®¿½–Ÿšº—›®¹´§§–ºš§––––®¶—––––––––––šË¬¬––›Óž–––––––––––¶«–Ó–––––––Ó–––––Ó–––§ž¦¬––ž­µ§«—¿»¶—;ž––––––µ²––––––ž½š–––––´¯¼µž»µ²§¦¦Ÿ²¯¶­›–––———µ³–––§§––¾Ÿ––––––––´´¹º–­š§´µ—––––––––––¾Ÿ––Ó––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®®®ªÿúÞªëÿÿÿÿÿÿÕª­éÖ–´µš––éÖ­§–´—ïîÙ–í×Ù›Ú´´µ›í›š–––½¹––ü–—š–ššš²š–—í–§––Ö–Û¦ïò·Î›§§ŸŸ«—–ÚÖ´Ö–––ú²›§––³–––³´––––Ó–––ËË——–¶¯—›¬§¶²¬—«Î®¶š––––––Ó––§½½¶§¬³§–––––—­«·³«–—«—µµ–¬—žµ––––––––Ë–––––––––´¿º——–––——§–½–´–——–––––––––º²––Ó–––––––Ó§¬š–¹«š–§¬››¶´–¼§½½–ŸŸ–šÎ–––––––––š½—–Ó½¾—šš®¯—–––––«¶»š½›ÍŸ¿­´½«š¹§––––§§–¶¯–––––´´–––½¦–´¹––¹¹––¹´––––§Ÿ²–´³¶µ›–Ó––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®®®«ÿûÞªëÿÿÿÿÿÿÕª­®–íí›––§®›§––´ï–¶Ùò¶––––––¶×ÖÖ—¯–®®–®í—š–––š­¼µóž—–§Ö󹧭š›«««›§­Ÿ›¶ß´Öíí–›®––³–––¼®––Ï—–––«Î¼›Í·¹´¹¹½§·«¾¿š–––––ššÓ––––¼–ºµ®§§–›¦´–ÏÎÓ—º¼´–·¶–«»›š––————–––¼§–––––––––¦¾Ï³´–––›»µ––––––––––š›ºË´––Ó–––––––Ó–——––ͦ–ºž´––––Ó–´´–´´»§¦Ÿ–––´´––·¬š–Κ–––¹´––§§–µÎ»—Ÿš²«›¹º—µ»½––––––§§šÎ–––––––Ïš›–––––––––žž––––š¬§––§§§¬ŸÎ–š––Ó––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®®¯ªþúÞªëÿÿÿÿÿÿÕª­÷§––­§–í–´´–§žš–éó–Íó®ß´¯šÖÖ§«—ÚÖ§¬ÓÙ®––Ö´–—–¯–––ÚÙš–´²ší×›¯²—›–ï¶í¹«›š›–¬š–íÛ¿—––—š®–––Ó––––––––´³––——–––š›³µ–––¶·Ï¿¾½––––––šš––––Ï—¹¹–––®Ÿµ¾²¦š¶¹¦§ŸŸ–§§–––––½¦––Ó´»Ÿ–––––––––¶²›š´ŸËË´š¬½–®›––——––®¶¦šÓ–––––––Ó–––––––®›–¹¯¬¦–––´´´³––––«Óµ®¹Óšš–––––––––––·®–––––––´´§–»´µÎš––––––––––Ó–––›Î—–––––´´–––§´´›­´´––––Í›µ¬––––®®¹­—Ï––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®®¯«þûÞªëÿÿÿÿÿÿÕª­ü®––›–óÛÛÛÖ–çÖ—žŸš½½üÍÛ®–¦–´½¬—––µîÍ›®–––í––´Í–´´–›––žùÖ–½­ìé–›Ùòžóײšš––´¹§–ó´ß›––—š®–––Ó–––––––´³§§—««—–––Κ––½—Ÿ––›·¦§––––––––––––Ó–––§§´¹––§§¶¾¾¬Ï½Ï––––šÎ––Ë®¬š–´´´´––––¿³«šš»Ó»²Ÿ´¹¶³¼—–––––––Ó––Ó–––––––Ó½½§§–––ËŸš––ÍΗ––––––»«–––Λ›š—Ë—––´´––––––´¦§§§–––š–¶´Ï»´Ÿ—Ëž—––´¿¬——–§¼––––¾Ÿ–––––§´½––´¾¼›Í–µ´——Í–­½³–––––¶¶––¿›ŸÓ––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®®®®ÿþÞªëÿÿÿÿÿÿÕª­ó––›–í––§§–›§ü§´ýî–´ßÚõòÓ×Ö›Ö››¼´–ۧ͛Ö×—í––§––—›—–®¹´í競õÓ·ôç鲟–®žåÙ¶´´Ö—󚧖––³–––¦¾¯®´½¦´––«¯§§µ¼Ÿ–––Í›¶žŸ²––´´šÍ—–––––––––Ïž––––§Í»š«—««¼´­ž›š–š®®¶´š–š´²—––––Ó––––––––´´–¬µÍͧ·§§¿ž–ž¼¯–––––––š²¯¬¹Ó–––––––¿¦¶´–––Ï–—šË–¾´´µš§›º§µ²—³´–––––´Í·§§¹´–––´ž¯¦––§§§¿›ÏË´¹¯š–´Ïž«Í¯½º—žµ¾»––––´²—–––––––––´µ¹²––§Ó¶žž¯·´´–––––½½šº§–Ó––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®®®¯ÿÿÞªëÿÿÿÿÿÿÕª­ü®––›´ÖÖÖ–––›®ßÏþìùš®×¶í×ëÖÖîÙ—š–›·§´¹ë—–––í––®––§­–––®–´µï–š¬–ÍùíÙ¬š–®š³µ´––í–ùš–––³–––Ó––šš––»«–––´¼¦§¬Î–­¹––½¦š«–´´´–½›–––––––––ͳ®––––š­—§«ž§Í¦½›º´—–žž–––´´Ó––––´¦§––––––––––Ó«—Íμ—§´Ÿ­Ï®¦––––––––§¿²›Ó–––––––Ó´´´´šš¿ž––§³Ÿ—–«¼›——Ïš—¯¶Í­§––––´–³––š›—––––¶¬¦––––ž¯»›¶´Ÿ¼µ§¹Ë—–²Ë§––––——º­—–––§¼–––––––––Ï»¹¬«¬¬´¿¼¯³––––——Ÿ¬½¬ž–Ó––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®®¯®þþÞªëÿÿÿÿÿÿÕª­ü–®ÖÚ´Öž—––›Û–êþά÷Ûš«¦—Ö—ííµššµ´–ëæ§ü–›––šš´é––Ÿ–—§›·÷ÞÝæ´–Ó¦®²–ŸŸ¯¦­®–´Ö¶šÚ®®®––³–––Ó––––––Ó–––¿¯»§µµ´¬¹§¹­»ŸÏžË––––––§·–´´–––––¯´š——¬®Ÿ¿Ï˽͟´¶§½¾«§´Ë»¬––š³Î´µ³—––––Í›–§§––––––––Ï­¬žžŸ¹¿´¦––––––—›š–½¦––Ó–––––––Óµµ–»­Ÿ–¦Ó¾››½¬Î—¶¬®´­–ÏΚ—––––´¶ËŸ´´––´«Ÿ––––½¿·¾¶ž·Óµ¾ž³§š–Ó–––§ž¶®®–––––Ó——––––––´´–§§¿¬¹¶¶–––––––––––»§–—Ó––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®®¯¯þÿÞªëÿÿÿÿÿÿÕª­üí´´›¹Íš—––¶´·Ö—ך§½í–––µ›×–›šž–®–®í–›–––š¯—›š´×«§®§§šŸŸ«§çÝ—–›«š—›š›½ß––––í–¦¬š–³–––Ó§§––ŸËš––ŸºË§´Í¿µ½šŸ¼¾­ŸÍËË––––ššË––§´¾²¯«ž¶›––––´«¦¶¼šŸÍšÏ–žºË¹––´µž¹´–½¦–––––§§––Í›––½½šš––šš–šš––––––––º§Ÿ–Ó–––––––Ó––––¬¹ž®—ž®––––Ë–Ÿš§Í¿µ–––––––——–Ó––§¼¶´ššš–––––´¿´–—³µ³Í¯–¹¹Ë–––––––––Ó––––––––––½»º–––––––––ŸŸ–––––›ŸÎ¦–––Ó––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®¯ªªûûÞªëÿÿÿÿÿÿÕª­ü§–›í–ÖÖššò÷§Û®Ëûó÷ùÖë———–¶–Ö››–ÖÖ–®ÖÍ–›––––í®––«§–š®–š´»óí›õîµþß––¬®šž§²´´í––훧––³–––Ó––––––Ó–––š¿½–š›Ë—®§§›¹–ν—–––––¯¼ž–§½´–––´š§ž–––š²®½–›§¶¿»·¹Ÿ·®›´––––½¦–––––Ï«§––§§––––Ÿ§—´›¦º¹Ï–––——–––§¼––Ó–––––––Ó–––––´³––––¬¬–Ÿ»šž¬›—¶ž—¾³Í›–––––––Ó––––––––Ó§§–––››–Ÿ·¶®´¿¿§§®§Ÿ½—–šš½¿¬Í­––––––½¦–––––––––š²¾¶¦Ÿ—¦–––––––––––Ï—––Ó––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®¯ª«ûúÞªëÿÿÿÿÿÿÕª­ü´Ö´·®§§––—š––—µ×µ½÷¿ËÙ´——·Ú—›—››–éÛ–ÍÖš—––––®–Ÿµ»¶ß––´µ¦Ÿš—ëÚ—š›—§––³¬¶´–Ö¶š–í–­––³–––Ó––šš¹«š––¬Ëº§—»–´´´½®žÍš§¾µ–––––——Ï—–——––§·——––––––Ÿ´«–¼®¾š¯«žž¦Ížž–––––ͦ––––––´µÏ–––––––——––––––––––´´–––Í–›––Ó–––––––Ë——–½¦–´´¹´–šº­·½§ŸŸ¯¦µ–´´–––––––Ó–––ŸÎ´´––––––––žÓ—–¾¼Î§¬µ§§µ¬–––´´––Ó––––––––––ÍΗ½¦–Ÿš––®®–——´´–––šš––´Ó–´––Ó––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®¯«ªúûÞªëÿÿÿÿÿÿÕª­í–›–––í––®é¬×§¬¦Î÷¹Öͮڽ´§ß›–––§¬¦ú®––í´´–Öé–ÖÖš—–´´å¼´öôîÙ´×——î÷Ÿ—––Ýæ§ü§Ö´›–––—²§ö÷½–––––––––Ӵ͹½——Í®´Ï—––¬–Ζ§²¿³–––––––––§§–—Í–š§§«®ž´²ÓžË´šš´§Îš½´––––––––Ï—––Ó§¬Ÿ–›¦––––·¼Ë–š¶·´¿¬›§½–¶Î––––––––ŸËšÓ–––––––Ó––––––––Ëž¯§Ÿš´µ—§µŸ–––²·š§§½¦––––––––––––§¼´·›––––––––Ë´¶¦¿–½¾–µ´––––––›Í––Ó¹¼›–––––––––¼®²­Óµ¯ÏÓ»§š¹´–Ÿ¬§—›ŸË–Ó––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®¯««úúÞªëÿÿÿÿÿÿÕª­ü®›–´–Ö–ÖÖ§®§­§š­›Ë×´Ö—Û¬ííÚ––Ÿš–­ó®–´Ö––šš®––––›—µ´ŸÙß–›—šßùÙ—×íé–›šš®Ö–Ö–üÖ´›––š—®–––Ó––––––––®¶«§§§›¶›¬¦––§³Ïš¦¦ž¬¹–––––––´´––´´Ó–´´µµ–´¬ž—¹»›½µ­š¶¯–––—µ´––——º¬––¼·»¯––®¬Ÿ––––›³›´–¾¯›Í›§––½³½´––––šš–¹­–Ó–––––––Ó–––––––Í›––––´´–¹­–––§¼¬¬–´²—–––––––––––½Ÿ—¦»µ––––––––®·—Ï–š››––š–––—›š¯¶––¦¿›—–––––––²Ÿ¼´³––——®»–ž–Κ––––——–²µššÓ––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®¯ª®ûÿÞªëÿÿÿÿÿÿÕª­í–––›ß½–——––—Ýߵ괚Ùíµží½–®·í´í–›—µ¹§í³––––í––§–´·––§´–´í®ü–Ÿ®ÿ––®–¯ž––´í´û––§­®–––έ¾´––––Ï­¬––½§´¹´–§§½¦–¬Ÿº®¬ž—·®––––––––´¦š¬––§¬š–§««§¹³®žš´§§½Í–––––§¼––––Ó––––®§–––––¬§–«¬—´¶š­»§«Î—––––––šš½Ó½Ó–––––––Ó§§§§––½›Ÿ›—§«—´®ž¼¯³®š¶³–ͿΟŸ–Ïž–––––––––²½«––¬Ÿ«¦šË­§¦šÎ½¹¯«´Í––šš§—´Ÿ––––Í›––––––––––¿­¦§µ³¾š«ž¿¯–––––––º›«Ó––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®¯ª¯ûþÞªëÿÿÿÿÿÿÕª­í–––›´Ö–––––¦–ü÷ÖÛÍ§í¹¬Ý®Í§—ššÙ×›«–«žïž––šší––®–––—›–«–Íé´§í¾ëÙÿ–š›³²š—›–šÙ¿û®–––­–––Óššš–š–´³–½½–¯¯––´´–––´³–—›²´š—––Í›––––––––––½¦¾¾––––´´––——˧ϫ–§§––­­–––´–³–––šÏ›––––––§­›–½­¬³µ³²²§§»µ»¦Ï––––––¬¬—¼»ÏÏ–––––––Ó–§§–––Í›–ÏÓ—š¼¿¶Ë›—–Ó´²—————®·–——––––––›Í–––––ŸŸ§›²¹Ÿ¯ž½§¼¾Ë¼¹µ®–´¹»š¯›—–––½¦––––––––––––¹—­Ó§³¯Íε½›––––––š²Ï»Ë–Ó––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®¯«®úÿÞªëÿÿÿÿÿÿÕª­ü®––›§÷§§––íò´½éµ—÷󟛽Ù󖷶–––½–é–ÚÖ––í–®––šš—š®–š»¶§êîíÞÓº–—–¬¦žž²¾¹––í––í­®§––³–––Ó–µµ–––¼§–š¶Ó³–––ÓŸ¼ºÎ¯­´³Í›–––––´´Ó–––´´––––´Ïµ–––––›²·–®³¿¿´·¯§º¹Ë›š–šš¶¶¬¹®¯––––Κ–––––––––§§¼§——¾—½š—Ó›––——§§–––´³––Ó–––––––Ó–––––»«–––—º¹´¹ÏµÍ«—³®ÍºŸ»—§§–––´µÏ–––––´¹Ïž––´ºº–¿¶¦´›§¾–¬³¼´–¶ž§––ϲ¶š½›–––––Ó–––––––––¹–¼–ŸÓ³¾®——––––––§´¦––Ó––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®¯«¯úþÞªëÿÿÿÿÿÿÕª­ü–®§­´í´šš–íò´½ÝºÚÖ—ßÚ×íµ¶Ö—ššžÖ®––Í–›––šš´é––——›–®–ßß߶åµåÙëé–²­–—¬¦¯­––î—–ôŸ§––³–––Ë–´´––Ó––––›š——¦µµÎžžÎšÓµ²®®–––––Ï—––––––––·§––§¬»Î·›Ÿµ¿›§´º¬¿®­§—––—–—š½²­––––Ó––––––––––³´—›—›¯¯»¯§–§––––§§´³––Ó–––––––Ó–šš––§»—–¹®Í––¯¶µËÏÍͦŸ²ËÍ›––––––›Í–––––––š¦¿–––§¬¶´½¦žŸ·³Ó¹¹–§§–¾›º´–———–Λ––––––ϵ´––––––––š¬§ÓÓ¾²²«´–––––––––––Ï—ŸÎ––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®¯®ªÿûÞªëÿÿÿÿÿÿÕª­üí––ÚóÍ––—š–¹ºµ§½ÖÙ×íÚ›—×Öï—–—š›–®–ü–—š––––®–š—–ÖÛ÷´´–—§«›¹÷×—–ž—š²¯²¹´íšš—î–›®––³–––Ó––––§¦´––´›¿«–´¬¦š«§—´Í¶—»®¿––––––´³––––§§–´³–––––––Í–›—¯®–¦¦Ÿ¹Ïšµ––––——µ²––——–––Ó––––––Ÿ¶´–´¶š´´–––––––––––¼®ž—Ó–––––––Ó––——½žš––§–¿¶¹–¬—½½–§§»´´­¶´––––´³––––²µš–Ÿžµ´–––––ž®»š¬Î¶¦§«¾§Ï´—–––šš––Ï—–––––––––ÓΚ½¦––´–´§§–——šš§–§––––––ŸÓ¦—–Ó––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®¯®«ÿúÞªëÿÿÿÿÿÿÕª­üíÖÖ›®®®––š—–––ÍìË½í·µžÛµ×Úš´Ùš–š–§––®í—š–šš—³šš›Ù–üÖ––—«§››ÚêçÙ§——«šÖÖ–¶Ù–šõ›®––³–––Ó–––´ž¬––´½Íµž—–¾«³—–µ²–ÍÓ›––––––¾Ÿ––—«§§¼®§–––––––¶µ§žÓš½¹Í¶¬¶§¦š–š§²––¼®–––´–²–—–––––§§–´¶š–——–ŸŸ––––——–´–›®––Ó–––––––Ó––––½¦––Ï¿––ž«»ž´–´—›ÎŸšž—–––––§ºš––»«šš—›¬§–——–®½¦§—›Î–š¿¦––¼®ž—––––––Ó––––––––––´¹Ó––§–§–§§——šš––––––––«·¶·––Ó––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®¯¯ªþûÞªëÿÿÿÿÿÿÕª­ü®––›–½ß´–´–––³–§––ÍÖ–º—ÖÓß´ß–—š––––¯ï®–´Öšš––®–––›––—î–Û÷í¦»î×ï´—Öåô›—–§–´´´ßí›––›«ž–––Ó––––––––Ÿ½µ–´¿Ë—®§¬¶›––§µŸ––––¹­––––––––¬¬––§¼–¶¶–®®–²µÍ·­µ¹—µ¼¹²›–––––––—«»—––ӽϦ———»Ÿ´––––¿¹·¬–Ëά–šŸ–¿—–––––––´«Ÿ–Ó–––––––Ó–––––––¶¯šš––šš–žž–´®›–––š³¶´¹½¦––––––––——–´¯š¶¶––––––––žžÏµ«Ÿ´²¬º—–––§§–´²—––¼«—–––––¹½§–ºÓ»«¾š²­¦Ë¹Ë¦›½–––––––§ºš–Ó––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®¯¯«þúÞªëÿÿÿÿÿÿÕª­ó®§–›–ííí֖鮯Ÿ––§óÛü¹Ö¹¦ß–×–š—š›–¦ü§––í––––§––—š––×·ÏÙš—»¼–·´ííÖé–š—–Ûߧ§´–üÖ›––—š®–––Ó–––––––––Ó½¿¬®¦·µ³—´––Ïž´·Ë§³––––––––——–––Ζš–§§®§¼Í­¿µ´Ÿ§›Ë®µ´¶¶––––––¾Ÿ––²¬²º––šš–ššÍ¿µ­›º¾²·µ««–½¯¬–––––––´¹·§Ó–––––––Ó–––––––´³––´´¶¹Ÿ–––—Λ–––´Ë¹–š¾–––––––––––––Ó›—š–––––––––´¬žÍ›–¹º—–šš––––Ë–––Í›––––––´–½§–¦›·§Ó´´––§Ë½¾»–––——–§Ë®—Ï––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®¯®®ÿÿÞªëÿÿÿÿÿÿÕª­í–––›šï–––––ž¬Í½í´¬ÝºÖ¯÷÷½ç½íÖ–›Ö÷½½–æ—–––í––§––›–––®Ö–´–¹î—ºù››ùž–Ÿ¬Í¼¦––ííí÷¦––––³–––Ó–––––Óšš––νž––––––µ²–®—š–µ—––´³––§§–´´–––´³ž—–§®–––Í—š³§½½½–——–––––—Ï––––šÎ––––¬¬——–––ά§Ë–«½¹½»´Í¦––––––––½ÎÓÏ–––––––­¹›š—––µ²——–´µµ´ššÓ½—³­šÓ´šÎ´ºÎ§–´—²–––––––––¦Î—–––›ž®¯·»Ë¯­µ»Ó¯Í¿¯ž–––––ͦž—–––½¦––––––––––¿ºÍϽ¼¶´³µµš³š––½½—›š–µš§Ó––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®¯®¯ÿþÞªëÿÿÿÿÿÿÕª­í–––—Ö›µ––§§³§ÛÛ§ýîí–¦òÓåú½îﶚš—®ó¯š––Ù¶––®–––›––§½§–íéÍ–×Ûßš³î¦Ÿ–®²š–Ÿš´Öﯖ––§¦–––Ï—–––——–ά½´–³³–¶›´—–––Ó–ŸŸÓ››šš–§¼––§¬š–––––½žš–––»»––´¯¬·ž—–––§§–––––§ºš–––Í›–––––´´—´µ–¾²¾»½––––¼­ž³»––––––´´š»³Ó–––––––ӹͽ´––½¼µ—–ͺ«––Ó´Î˾¹Ï—Ë—––—®–¼–––––––––´³––––§§²¯µ¶ÍÍ¿žÍ¿«—¹Ë«¼––´–´—«–»—–––´³––––––––––´ººžžµ—½¦––¦¾—––––––––——ΚӖ–––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®¯¯®þÿÞªëÿÿÿÿÿÿÕª­ü§–›´Ö——––µïÙŸ½åùüüíÓ—µ—·µµ×›–›¹´§í®–›–——´Ö®––———š–®—«§¿å—µÖüò››š—²§çì—®––ï–šò–®–––³–––Ó––––––Ó––§®­³––Ë–——»Ëµ·³Í›–––——–šÍ—––»»–––´¹¬µ–––ž®µ»·»Ÿ§¿š¬¬¿®´·®––––¶Ÿ›§––––Ó–––––––––––Ÿ¹—´Í´»²«–¿–––––––––´Ó´–Ó–––––––Ó–––§§§Ó§––¶Ï®––Ÿ¯¹¹¹–¦¶­—³²—–––––´¹Ë–®Í´––––Óµµ–§½¼¹Ë—¶Ï½­¦®šš¶´ššµ²–––§»¿¿ž––––––ͦ––––––––§¯µ—›Ÿ¹Í¦Îš––––––––––µ²––Ó––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®¯¯¯þþÞªëÿÿÿÿÿÿÕª­––––––––––––š››––šš——››––šš——››––šš——››––š–››——šš––››——šš––››——šš––››——šš–›––š—–––––––––––––––––––›––––––————————šššššššš››››››››––––––––————————šššššššš›››››››š———›––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯®ªªúúÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯®ª«úûÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯®«ªûúÞªëÿÿÿÿÿÿÕª­µ®òõ¾—úûïö¦ìí´¯µ¿»¾Î¾¯ÍíïôÞßý»Ö¶·÷Ïóú»»Þì–›ç«òìÓóóºÜ½§šŸëõ–ÎòÎé›ûúùéͶ²éúîóÞ××ÜÜ—×úû¯Ÿ«›š––šÙéçÜ›—¦žéé­«ž¦éÛΦ–ŸÍÍ–¦šž›Ë¾–ž¦——šž¹¶´§¬éÛΦ›¾½—–žžž–ÍËš¾Î¦›¾¾›ŸŸ¶¿½²®éÛ¿—¦—–ϽŸ–——–ν›–›š¿š½—›¿¬ÖÙ¯³éÛ½›š¾Î¦›šËΗžžÍΦ›¾§Þܯ³éÛ½—–žžž–ÍΟ˾–ž¦——š¾§ë鶴éÛΦ›¾½ž—–žšŸÎͦ–ŸÎ½›šµòéÛ¾žŸ¦¾¿—ËΗž¿­ùû·µÖõÙ÷üþ–ìîÏÖÚ–›üÛÎËÏëÖš–»¹Öß–¦¦–—Ÿ¦¦¦——¦¦–¦¦¦­ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯®««ûûÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯®ª®úþÞªëÿÿÿÿÿÿÕª­ŸÝÛë»ßÚËõËžÛݳµÍ­æô¹ýòŸ´Î×Íë¼Ü¯¯º»ó·Ú«æ–¹»»¿ÜÏÜ»ëüýì×ü³Ë¾šßºù«ôò½ŸüÿöôÛ¼û¹ëôº´ÛþͲš——¦¦–¦¦¦ž›¯ž¦¹»Úë–›²ŸË¾éé²®¾ËéÛË–ŸÎ¾–ÎΦ›¾¿—›½½—–žžž–¹¹»ÍÏéÛ——½›–Ÿž—ÎΟ˾–—š—››·»¹ÙÖééÍÏ×Ú¶—›Û®ï¦–›÷¬ï¦–›÷þ—–¯ÏÍÞÜéÛ§ÝÛæßéÛ–Ë›—Ζͦ–ŸÎ––½žÎ¿—›¿Ÿ—¯êìßæéÛ–Ë›—Ζ¾žŸ¦¾–½žÎ¿—›¿Ÿ—¯ìêìêééóõê칦ޮw›Ùþ—¦÷þ—¯÷úíﵞ֮w›Ùþ—¦¬›—õóëݽž—–žšŸÎͦ–ŸÎ¿ŸÍ–ͦ˖½›šµÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯®ª¯úÿÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯®«®ûþÞªëÿÿÿÿÿÿÕª­––—›››šš—›————––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––§¾žŸ¦¾¿ŸÍ–¾ž¹––÷÷–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯®«¯ûÿÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯®®ªþúÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯®®«þûÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯®¯ªÿúÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯®¯«ÿûÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯®®®þþÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯®®¯þÿÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯®¯®ÿþÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯®¯¯ÿÿÞªëÿÿÿÿÿÿÕª­––––––––––––—––››—––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––›–––––›––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯¯ªªúûÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯¯ª«úúÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯¯«ªûûÞªëÿÿÿÿÿÿÕª­–––ÙúóÛÝüþßžž¬–²–¬§«««­«›–¬—³–²¬®®Ÿ¯›š§«›—¬§®–¦§­­­³—­²¬¬Ÿ­—›š—š¯¯²›—²®Ÿ§–²–š§§››—«Ïå¼ßëý´ÿý«ò¯õù¼ž²ê¶Ü¹ç–ïµÓóúϧ·žÍš¿ü­›–––×Ú›Öì³Öò·—Ù›¿ú—Ù›Ïþßìó½íö¯¶Ó¯¶Ú·›Ö–­–––––––¦Óž—žŸ¦Í½›–ŸÎΖ¦——¦›º–­–½›¦ššŸ››¦Î½–¦š¾½›–¦—–žÓ›¿—›Ë›š››¯–––¼¦–ŸÎΟ˽›–ŸÎ¾ž¦–˚˖–—žŸŸ¿š¦šß–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯¯««ûúÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯¯ª®úÿÞªëÿÿÿÿÿÿÕª­––––ÙÙšš¶ÖíÚò·›šïµÚ–µ·›—ïî×îÙ¶î×ò×íÖ·ïÖí×íïïÚí––Ùí·›ïò—–×îÖíÖíÖ´íÖí–––––ÖíÖ´í´––íí––––––––ææ×ÎÎÎÎëëÜëåÙ릧›ß¹üÙëëÜýýì¹üµ––òÜ®§›úõõžºº¯ô÷–½½¹í›Ó–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––šŸšŸ–—––«šŸ¯›®Ï¶´Ÿš¹—–––¦––—–––›––—––³––—µš·–ºš¼åšŸë––—–––¦––æ²ÜÞŸšÚ––›–þšŸú—ù²÷ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯¯ª¯úþÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯¯«®ûÿÞªëÿÿÿÿÿÿÕª­žž§®««šš—–«§–š¯²—®®Ÿ«³³¦ž—®®®§ž¦§Ÿ®®Ÿ¦ž³¦–ž«–—®ž§²²¦š––›—š››–›š—››—š—–š––––šš––›—š›¯ôŸš»íîºþ—ÎÓ«÷ò´¯Ó«µ¿ì¶¼ÙßýÓí¯§¯´Ùú¯§³òöüìºî›§žÏíÛÛßìì–¶––òßËòß˺¦–ÛçýÎÚ®¶–––Ë–ËË–²­®ÛçýÎõ¾¶–––Ë–ËË–²Ï¾ÛçýËÖ›­Ÿ×ÝÛçýËÖ›­ŸóòÛçý–õߦ¯Ý¶––µüÿÛç¼½–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯¯«¯ûþÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯¯®ªþûÞªëÿÿÿÿÿÿÕª­íí®óÍÝšü½òµÍŸüÜ›ší´òµ¦ž—×ôòÝ®ÛËîÖþ¼µ¿ÖóΫ–í鼯Ÿ»ÝýÞ¿··Îº×¾éÛ§­Ü»úš—ì¿Îê®åµÖÍÛ³ê¬Ù榯š–ßÖæÏÛö®·óúéÞ—«¦º®·óú®½Ï§¹²«®·óú®¾Ó¯·æÙ›ßÝ®·óúß»›æÖìÝ–ó³¿ßÝ®·óúß»›æÖìݖ¹®·óú§õ›öíç®·óú®ž›õ÷º®·óú®½»ç¾»í»ÓßûŸô÷íô–·®·óú®¦—§Ÿº®·óú®½Ï§¹ßì®·óú®Ó¾¯·æ×ßÝ®·óúóçßÝ®·óúö–ìê­µ½çÝý·Ï¾š®·óú®ž›Óµº®·óú®½ÏÎìÏùç×ôÓÖߦöòõûçêúÜÓÜÛòêÓ«ò÷­õýæÖ›¬šß»§÷õýÿ¬þõýßôÓ­¬šß»§ßïÝÓ·ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯¯®«þúÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯¯¯ªÿûÞªëÿÿÿÿÿÿÕª­––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––æºÿ––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯¯¯«ÿúÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯¯®®þÿÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯¯®¯þþÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯¯¯®ÿÿÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯¯¯¯ÿþÞªëÿÿÿÿÿÿÕª­––––––––––––›šš——››––šš—š–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––›––––––—————š––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþªºªªÿîÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþªºª«ÿïÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþªº«ªþîÞªëÿÿÿÿÿÿÕª­­Üõ¹ýôÏùï×üÖÛ®–½æÚÙöξÜ×íüßÚÞÍæûô­ûê¾þÝßÖ³ûÝúÙ¹ùû¶¶³û¦¼Ý¼óܶ—›²ëõÝߖέݽó­ËÚ¯çó¯Þ¯çê›—–šå›Ý–––®ž¦¦žÙéçܬ§ž¦µ½ý¯ò¦¦ÙÛ½ž—¦½¿¾§´¶¬§¹—ŸŸ½ý¯òŸ—¦ÙÛÍ—ŸŸµ¾Ë­«´—š¿ý¯ò¦¦ÙÛ½–ž—žžÍ½—š–ËͦŸŸšµÚק¬ßÛ–šååϾýü¾¦¦—ž–¦—š¾½›–Ÿ¾–ŸÙÖ–––šåÞßæ²®ëÿ½—½—ŸË½›–Ÿ¾–§ëé÷úéÛ½—šŸžÍÍ——Ÿ—š¾½¾«ôöþüܵþŸ–þ÷ï￾›÷þŸ–Öþ¾¦ÙéûùõôåÛ–šÜ·ïŸ––Ÿþ¦þüËÝ–——®ŸóöìÝΦ–ŸÍÍ–¦šž›·ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþªº««þïÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþªºª®ÿêÞªëÿÿÿÿÿÿÕª­Öצ¹–íç­ÎË–š¬´¹¬²—­¬Ÿ­——›š­¬–®›®¯­¬²—¬–­²—š›®«­ŸŸ¯¯ž¦š–—³—¯³—§›Ÿ«§¬¯›§¬ž®¬—ž¦›š²§¦²Ížž—¦ŸžžÍΦšžÎΦ›¾¾›—š¾§·µû÷ìÖÖú—ŸŸ½—½›–Ÿ¾–Í—ŸŸ½—–½—¾Í–žžžšŸÎË–ËΦ–ŸÍ¾›ŸŸ¿§»¹ùúìþ—š¿¦ëÖÙÖüÿìÝͦš—ž¾½›–¦—ŸŸÎΦ›¾¾š¦Í¦¦Í–¦šž›–——š¾§æßššéÖÖÝË››Ÿž›Ë¾š¦Í¾ž–¦¦Í––í–Ÿ¬êì——éþ—š¿¦ëÖ––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþªºª¯ÿëÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþªº«®þêÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþªº«¯þëÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþªº®ªûîÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþªº®«ûïÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþªº¯ªúîÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþªº¯«úïÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþªº®®ûêÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþªº®¯ûëÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþªº¯®úêÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþªº¯¯úëÞªëÿÿÿÿÿÿÕª­–––––––––––––——šš–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––¦¦¦›––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª»ªªÿïÞªëÿÿÿÿÿÿÕª­íšý–³íþšü–ü–®–®–ü–ü–®–®–®–®–®–§®–®–®––——–®–®–®–³–³–³›®š²–––––––––®–®––®®––®®–®–®––®³–šž¦›–––––––––––––––––––––––––––––––––––ÏÏ–––––––šýÿ–§®–––––––––––––––––––––––––––––¦÷ÿ–ÿ–ÿ–ÿ–ÿ–ÿ–ÿ–ÿ–ÿ–ÿ–ÿ–ÿ–ÿ–›üÿ––ÿÿ–¦÷ÿ–––––ÿ–ÿ–¦÷ÿ–¦÷ÿ––ÿÿ–––––––––¦÷ÿ––ÓÓ––ÓÓ–¦÷ÿ––ÓÓ–¦÷ÿ–––––¦÷ÿ–––––¦÷ÿ––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª»ª«ÿîÞªëÿÿÿÿÿÿÕª­–š›—–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ž—–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª»«ªþïÞªëÿÿÿÿÿÿÕª­–¬–¬–––––––—¶µî–ÚšïÖÖ–Ö–––––§§§®®®§–®–––––šš›íò›íò¶òÙš–—–––––®®§§–®®®–®®®––››–›šš–›¦›–––––––ŸžÚ´›¦šÏ–––––––––––––––––––––––––暟žÙµ›¦šÎ½›šÏ––––––––––––––––––––ß–¦Ú´›¦šŸ½––––––––––––––––––––––––暦ٵššš—Ë––––––––––––––––––––––––ß–¦Ú¹žšŸŸ›—žÍ–––––––––––––––––––––盦ڵ›—ššË––––––––––––––––––––––––ß–§­Ù´››¾––––––––––––––––––––––––––êž–ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª»««þîÞªëÿÿÿÿÿÿÕª­–š–š–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ž—–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª»ª®ÿëÞªëÿÿÿÿÿÿÕª­§²Ÿ§®–––––š—šï–ïí·òµ¶µ›––––®®®–®§–®§®––––››×ï·š–›–››—–––––––®®§§§®®®®®–––––››–›šš›–¦›–––––––§­Ú´›–Ÿž—¾–––––––––––––––––––––ß–§­Ù¶Ÿ–›—Ë–––––––––––––––––––––––럦ڹ—ž—¾–––––––––––––––––––––––ß–›–Ùµ›–Ÿ¾––––––––––––––––––––––––å—›–Ú¹¦–ŸÎ–––––––––––––––––––––––––å—ÿüší›Ÿ¦Ó–––––––––––––––––––––––ç­§––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª»ª¯ÿêÞªëÿÿÿÿÿÿÕª­–šš––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ž—–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª»«®þëÞªëÿÿÿÿÿÿÕª­–š—›–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––Ÿš–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª»«¯þêÞªëÿÿÿÿÿÿÕª­–š—›–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª»®ªûïÞªëÿÿÿÿÿÿÕª­–š›—–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––Ÿš–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª»®«ûîÞªëÿÿÿÿÿÿÕª­–š›—–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª»¯ªúïÞªëÿÿÿÿÿÿÕª­–š–š–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––Ÿš–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª»¯«úîÞªëÿÿÿÿÿÿÕª­–š–š–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª»®®ûëÞªëÿÿÿÿÿÿÕª­–šš––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––Ÿš–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª»®¯ûêÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª»¯®úëÞªëÿÿÿÿÿÿÕª­–š—›–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ž—–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª»¯¯úêÞªëÿÿÿÿÿÿÕª­§¬­¯–§§–––›´¶—ïÙí›·íÖí´––––§®®®–––››–òîÖ¶íÖšµíÙî´íÖí–ÛÛé–®§®®®––››š×Ú–››¦›–––––––¦Ú¶›š––Ë––––––––––––––––––––––––ß–žŸÚ´–¦šž¦šÎ––––––––––––––––––––ß–žŸÙ¶–›—–žÓ½›šÏ––––––––––––––––––å—žŸÙ´ž–Ÿš½––––––––––––––––––––––Ù¬žŸÙ·—Ÿž–Ÿš½–––––––––––––––––––––Ù¬ŸžÚ·›—žÍ–––––––––––––––––––––––ß–ŸžÙ¶›—žÍ½ž—ž¾––––––––––––––––æš–ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«ºªªþîÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«ºª«þïÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«º«ªÿîÞªëÿÿÿÿÿÿÕª­³ž²å¶¼ý¾ü––ó½ç›Öï·Öô¼Þ¾¾þ¿´õ¶ÎÎý–é쬽ùÚ¿´ß²¬Ù¹ûß—¶Ù–íÖîô¹í¯«×Þ²å×ò®¼åçìÙù¾ÙôÞÝϳéßš––šÙéçܦž¦žµ½ý¯ò¦¦ÙÛ½ž—¦½¿µ²®ž¦ßۚϾýü½–¦š¾¿–¿ŸÙÖ–––®¿½§¬ßܛϾýü¾š¦ÍΞ–Ÿ—–˦¦–Íšš—šËË›—žÍŸÙÖ–––®Úײ®ßܛϾýü¿š›ŸžšÏ¦›š–šŸÙÖ–––®æ߯³ëÿ½¦Ÿ½›–›—¾Ë–›—–žÓ½›šÏ§òî·µÚë—š››ÙÛ¾——ÎË–›—¾¿—Ë¿—Ÿ––žÍ½–Ÿš´Ÿ»¹ßÛ–šêµü››–Ͼýü½›¦ššŸ››¦Î½–¦š¾½›–¦—–žÓ¾—›Ë›§ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«º««ÿïÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«ºª®þêÞªëÿÿÿÿÿÿÕª­š–¬§šŸž§–«²¬®³ž­¯¦³¯ž²®§²¬§›­—³««ž®®¦¬§¯®­¬­ž­³š³¯²¦­§›­¬ž³§³§š––¯¬Ÿ®§—›š—›š–—š³š–š¦¦š–šŸÙÖ–––®·µ¹»´Û®ï÷þ–––ŸÜûÛùüÓÖååϾýü½—¾Í——ž¾½––ÍË–›š¿¿ŸÍ¾šŸŸËŸÙÖ–––šåÞ¼ºË¾ë¼ò¦¦Ÿ¾žÍ§ÎÓ÷úéÛ½—šŸžÍÍ——Ÿ—š¾½¾«ÜÞþü´Û–þŸ–þ÷ï￾›÷þŸ–ÜûÛ–÷ý×Û÷®ßæýÿÜôÏÖþ¾¦Ùé––µµ––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«ºª¯þëÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«º«®ÿêÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«º«¯ÿëÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«º®ªúîÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«º®«úïÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«º¯ªûîÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«º¯«ûïÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«º®®úêÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«º®¯úëÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«º¯®ûêÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«º¯¯ûëÞªëÿÿÿÿÿÿÕª­––––––––––––—––›š–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––¦¦¦›––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«»ªªþïÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«»ª«þîÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«»«ªÿïÞªëÿÿÿÿÿÿÕª­³ž²å¶¼ý¾ü––ó½ç›Öï·Öô¼Þ¾¾þ¿´õ¶ÎÎý–é쬽ùÚ¿´ß²¬Ù¹ûß—¶Ù–íÖîô¹í¯«×Þ²å×ò®¼åçìÙù¾ÙôÞÝϳéßš––šÙéçܦž¦žµ½ý¯ò¦¦ÙÛ½ž—¦½¿µ²®ž¦ßۚϾýü½–¦š¾¿–¿ŸÙÖ–––®¿½§¬ßܛϾýü¾š¦ÍΞ–Ÿ—–˦¦–Íšš—šËË›—žÍŸÙÖ–––®Úײ®ßܛϾýü¿š›ŸžšÏ¦›š–šŸÙÖ–––®æ߯³ëÿ½¦Ÿ½›–›—¾Ë–›—–žÓ½›šÏ§òî·µÚë—š››ÙÛ¾——ÎË–›—¾¿—Ë¿—Ÿ––žÍ½–Ÿš´Ÿ»¹ßÛ–šêµü››–Ͼýü½›¦ššŸ››¦Î½–¦š¾½›–¦—–žÓ¾—›Ë›§ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«»««ÿîÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«»ª®þëÞªëÿÿÿÿÿÿÕª­š–¬§šŸž§–«²¬®³ž­¯¦³¯ž²®§²¬§›­—³««ž®®¦¬§¯®­¬­ž­³š³¯²¦­§›­¬ž³§³§š––¯¬Ÿ®§—›²¯›š–—š³š–š¦¦š–šŸÙÖ–––®·µ¹»´Û®ï÷þ–––ŸÜûÛùüÓÖååϾýü½—¾Í——ž¾½––ÍË–›š¿¿ŸÍ¾šŸŸËŸÙÖ–––šåÞ¼ºË¾ë¼ò¦¦Ÿ¾žÍ§ÎÓ÷úéÛ½—šŸžÍÍ——Ÿ—š¾½¾«ÜÞþü´Û–þŸ–þ÷ï￾›÷þŸ–ÜûÛ–÷ý×Û÷®ßæýÿÜôÏÖþ¾¦Ùé––××––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«»ª¯þêÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«»«®ÿëÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«»«¯ÿêÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«»®ªúïÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«»®«úîÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«»¯ªûïÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«»¯«ûîÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«»®®úëÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«»®¯úêÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«»¯®ûëÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«»¯¯ûêÞªëÿÿÿÿÿÿÕª­––––––––––––›šš—š–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––¦¦¦›––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª¾ªªÿêÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª¾ª«ÿëÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª¾«ªþêÞªëÿÿÿÿÿÿÕª­ó柺å¦é¾ËìÙ³Ý쬗ù½íºÿ¾ÿüó駽韯îŸÿÚîýÏõ¬—Ùܳ²é×ÿ¯¿ßßÙæí½ëõÝé½å³ÝŸ³×§æ´ûËóÛìô¿´ÖÍö½ûΛ×Þž¦š¶¶·ÏÚæ–·ÚÖ½ÜÞ¬ÍÍ—žî×®»ç笼ÿ½ž—¦½¿îŸ—¦Ëöé––íÖ®»ú–¦š¾¿–÷¬¼û»ú–®Ÿ¬Ëõé—–íÖ®»ûš¦ÍΞ–Ÿ—–˦¦–Íšš—šËË›—žþ¬¼û»ú–§®Ëõé—–íÖ®»÷š›ŸžšÏ¦›š–šÝ¬¼û»ú–Ÿ«³½å×—Ëú›–›—¾Ë–›—–žÓ½›šÏݬš·µ·þê´¹Ëöëš–·ÏÚ—ì–íÖ®»ú›¦ššŸ››¦Î½–¦š¾½›–¦—–žÓ¾—›Ë›š–š¦¦š–šÝ¬¼û»ú–Ÿ´»íé¼­ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª¾««þëÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª¾ª®ÿîÞªëÿÿÿÿÿÿÕª­­²¦§š¯Ÿ³¦§²¯Ÿ«¯Ÿ®³¯®«³§¬­—²§«³³žš®®¯¦¬¦¯³›Ÿ¦«²¦››–§³²—›§­§š³¯¦¬Ÿ›§³š¦žš¦Ÿ³š–š–šš–šš³š×ÿ¶Îͽßõçé—«Ïûô¾–½½²¾¼¾ó×®¾ôòÓ–íÖ®»ú—¾Í——ž¾½––ÍË–›š¿¿ŸÍ¾šŸŸù¬¼û»ú–¾ó×®¾ô·ÿ–›¿¾½å×—Ë÷—Ÿÿ¬žÿú¼ÿ½—šŸžÍÍ——Ÿ—š¾½¾å§óüíéí垬–þÖ®¾åé–Íͽßôåé–«ùéíé––›üÿ¹Ûí½ßÖ´»»³¾»íí––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª¾ª¯ÿïÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª¾«®þîÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª¾«¯þïÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª¾®ªûêÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª¾®«ûëÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª¾¯ªúêÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª¾¯«úëÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª¾®®ûîÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª¾®¯ûïÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª¾¯®úîÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª¾¯¯úïÞªëÿÿÿÿÿÿÕª­–––––––––––––——šš–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––žŸŸŸ›––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª¿ªªÿëÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª¿ª«ÿêÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª¿«ªþëÞªëÿÿÿÿÿÿÕª­§§––®®Ö´½§Ù¾Ë—«æï¹ÍÏݧ֧ͮ¹Û÷Ö÷½´æ«ç§ééžžºóö»÷¶ï¾ûí¬æ¶÷¬ÙóÍþºçæîÿ²¹ú–¿Ë—¬¬––鲦ºóݮ묚º´¶Ë®º´¶ÜõËéö––––¦›ÎÍž––––––––û¯þž§êß×½¶ç÷æ—ù—­´Ëç÷æ——÷—«¶Ë«¶¿ÿõÚó¼Úó¦òó–éçòóõå­´Ë­´úþÖï¿õ×­´Ëç÷¬×Þõåç÷¬²§ó·ùëì­´Ë­´¿¿µ»ÎëÜ»ÎçÖßýÿÖ­´Ëç÷¬úüõåç÷¬²§ó·ùëì­´Ë­´¿š«»ÎëÜ»Îæ×ßýô˫˯ìßÚß—–ö¼ßéËòž«ò¯Ÿ«ºßì¾ï–ž«òž²«Þ§ëþß¼ºéÜ»»»›õßßæêÛ»»»Îò÷ºÏìÛºüëÙÜ˧µÞ–ëëÞÖ¦ëæ–ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª¿««þêÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª¿ª®ÿïÞªëÿÿÿÿÿÿÕª­ú¾ÞÙŸÙîöõïŸïÍ´Íê­š§¦¦ÙþÍË·§«µÜÿúÖ¬Ýü¶ÏÍ›·š¿½û·ß—ìêåßÚ쯚»›óÝ¿Í×Þ›—´ó–ÖÖš¬¿Ï»ô¯µêêÓ®—ÙÝ—ëòúÞ–ëìÝÝ—®º¾ëëé欫žÖÛ·úêéßëöÍÝÞ–ëëé欫žÖÛ·úêëçÖºõÚ½´´µßìõÍùûò››õ÷§šô×½´å›ì´Ú¶å½µßîž–›ö–ížÙùëݽÿìžõͳºþ˧ÎõÍÝÞ–õÎõÍÝÖ¦é¼Ï˧·ºº½·ëé欫žÖÛ·úêéßÚÖ¦éæ÷–Ÿß꛺õÍ«î—êúߦ÷þîí¦÷þßú®Ë֦ܾ¶º½þÍÿºõÍé´ô³Öޖܽîþïê´¯ž¯ßõíó«®ÞÚõ¹Û½´·Îï´Óí·¯–Óç«íô¼¦Óæ´ûÙ—½´µËÖ¦®Ÿ¬ééÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª¿ª¯ÿîÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª¿«®þïÞªëÿÿÿÿÿÿÕª­µíéîù§÷û¿Ëµ¿–§«­æí´¿µ—ú÷ÙÙ–¿¶–›¼»Ù雦ÛÎÛ³¿åꦭ®®´¾åٲ駶ú²Ÿ›çé®ïúçÞ®ÙÞ­®²Í§û×ôöŸÝÛšŸÜ¾««óžÖµ¼®Þòݹî§ÓÞ–šìÎ笴ÝÝ—ëëé欫žÖÛ·úêôž–—μÏËïëÙ¯íûí·ºº½¿Ö¦²Ÿ¬¶¹·öÖéßìõÍù¹­Ö¦þºõÍÝÞ–¼®Ëëæ×¹Ó¹Ó¹Îßé¾µµ¦Ÿ¬¼ÍòͿ׹—§Ý«¾³¯í÷×¼¼¼ÍæÚ֦ܽ½½µß鿺֦ÞÜšõÏ¿ºÖ¦ÞÜšÍíìì¼¾—õ¹öõúÝíæõóßßç´ûÙ›»Óß×»ÿ¬ŸÏ¶÷󮚳»·÷¶ïï–צüšŸ­ó¦üÙ꺽Ÿ­ó¦ü¶»²ÙïòîêÝÞ–ÞÝ—ëëé欫žÖÜË–«úêê·ŸûÿùÜÖéßÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª¿«¯þîÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª¿®ªûëÞªëÿÿÿÿÿÿÕª­³ô¿ÙßöÜüéÿÎ涾òºÓﶶ¿½–ë®ú¿ÙìÿÙöÜ筞춫꿟µù¿½´Í¦ÜŸ²³¯®š¯ž³«¯åý¾ü÷髲Ëêôòö—Ûµ¶µî¶´ÖššëöÍÚ¶óÙÝù¼Ïºº–õåïÍëïÍÛ¹¹¹ûÞέ½Úܺ¼Þ–êβú׺¼Ý—ç§ÚæöÍ×´ŸŸ¬¹ºÏ½×î´¿Þ–íôåçöôùûöóßß溽õ¹›ìÎ笴ۻÏκ»ÎòîêÝÞ–ÞÝ—ëëé欫žÖÛ·úêšìÍÍ·Ü÷ÚëšßëöÍ×·ž–Ÿ«¹Î¼Þ–ÍË›––—–––›–––—––›––––—å––––––Ë–›—›—š¾¿—Ÿ––žÍ½–Ÿš·–Úò–›—›—š¾½–¦šž¦šÎ½–Ÿš·–Úß––––––––––––¿—ŸŸËËšš–¦šÎ§–Úîž–ŸïÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª¿®«ûêÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª¿¯ªúëÞªëÿÿÿÿÿÿÕª­››–––––––––––––š›——›———›–––––––––––––š›—––›š—›—–ššššš–—››š—–š–—›š——š›—››––––––––––––––í½–––––––––––––¿—Ÿž–Ÿš½––––––––––––¹ýÚÏþõóÙ»óç­´¿æ×ò¿çͼÚݾËõÍÙþÍÖµŸõ÷Û½––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª¿¯«úêÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª¿®®ûïÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª¿®¯ûîÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª¿¯®úïÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþª¿¯¯úîÞªëÿÿÿÿÿÿÕª­––––––––––––š››––šš——›—–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––žŸŸŸŸŸŸ¦¦¦š––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«¾ªªþêÞªëÿÿÿÿÿÿÕª­š–ú´÷¿ýÿ®üóôÚ½ú¾­šæçç›ééžÖæ­ííå뺷§´¾¬×ßš²õÍÝý¦¿Ú«Ù÷ïßåîÍ·Ó§¼žÏÛÚ›×Ú¶ËÚå³Ó¾¿–¶ÙûºÝꦲ÷½›¾Ýüš½Ý¿®òÏ­îï»Ûמϗ¦›½Ïíûõëë¯ûõîó¿¹Ý·—úû—úû²ôû²ôû²ô«®¼ß¼ÜÝóúçÜü§¶ê»–û§òÛÓû§òû§òû§òû­íû­íû­ûù«­›²ÿïæ×Ü®Ûééé·—åò¼Þ¹ôçùö—³–²åÞ–²ž­úüö榦¦ó¿ÛÛïúî—çÍõ­›žíéëïúÞ²·óßß­Úß··÷¬šó·Ÿê¬Ÿ´Û·´óÿݾÿ»åÎÖ—×Ö—××Úßó¿¿ó·ÿéßé¼¼îÎêÓ–«Ýšÿí³»«««—ê÷ýåß׬òîê–¦çß隽Ϛ§îìçêïÛé–ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«¾ª«þëÞªëÿÿÿÿÿÿÕª­ÙïÍþí¯Ó÷ËîëëÛõ·ÿöæ·í½¿ßæ—ö¶Ý¿Üþåþýõ¿×ŸÖå›ß»§Ó³ž¬Úß«Ö÷›´¬–߮ݾ¶«æÙ§íõ»ö쫯¦šêìÞììììôÓ²ÝÙק纼Ó×ÓÖûúéÜ«õ§ÍçÖßûϬ¶ò꟬®½Ï¬¦¦¦Ÿ·¾¦å­Ó×ÜÞ—¦ŸóùÏ­­ÿÍöýóÜô­–«ÍºŸ³Ë¶Ÿ³¼¯²ý«›þîúïî¼Ù–Ó×þ›þù¯«Óך«ôÓ×ÍÙü¶®¬—Û¯¾Þþµê–ôÚ÷¾å®ü–í߬ý—üÖÏíÖÿöüû¦ó¿¶ûó³ûó³÷¿÷÷¦ÿ¶êÿµëÏ—æλ럟¯—›Î¹õõõËÿÎëé¶ïõïÜêô«Û駵ëÿß¿ï¯ïϧòû§ò÷¬ïü³ÓõÏÖÓ¦¦¦¦óÞŸýÖÿÿÿõßéš¿×ýßéšßúîÿÏš³üìÏš³üÎÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«¾«ªÿêÞªëÿÿÿÿÿÿÕª­ßü®®³›š—û÷÷Ùíγ˳Ӟºí½ÿö¦¶®íë²Ý«­çêžë½—ôÓýË·êÞŸþÙ²®ÚßÞŸï·ÞçžÖß®é–÷õšÖóßËÛÞ­¦¼Þ´üæ–ÍÛšš³óó¬µêìé­«¶·¿¿úí¬—³²ºÓ¿¿žž­­««ôôííéé««Ÿ¦ššÞÞÝÝßæöôóóÖÖÝÞÞÞÖÖ××ÚÚììÝéÚåÎκº²²ùù¶¶ËËÛÛêÞùùïïÛÛ­ý§þéé––êê®®»¾­ÎÎïüÝÞ®›··ÓÍì춵ÛÞµÏïò´µ÷šö³ü¦Ë½´´çæ÷ù——¦¦ôïËËÜÖ®®§«ù÷––ßßìì½½ÎÎÞë«Þó·Þþ¿ÛÖÜúÏì—ÙÝšÛßé§Ûú¶ë–ëÝšÙÖšÞÞš¦ÚÛ—žÜÙ—¦—ÖÛ–ÙÙ›×Þž—×ÖÜצÚ×–üú—û÷–›·ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«¾««ÿëÞªëÿÿÿÿÿÿÕª­íúšæŸÛ¾½›æºÎ½¾ÖêÛìåê›Ö³²­éÿºé¬æÚíˬš§éí¹×¶Ë×埮Ùߟ®õüíîî¿Ö¬éëþͽ½ïïÖîÍË·ÜÞ¦²ìÜŸå—íúí½šéÿö³³¬Ûù¼Þô÷—éóÞŸÿåÙ–Ó×Óóóóº—ïòÎÚþÛ駚üÜÞ—«ÛÛöî¿ÖõÙüå¦ßëóÝüëóÝ—ÿé·šÞüï·üמùÞíÚúåòõéÙ›þþþ¦òç횶Íü½´Í×μõÿï·åŸ²ïééŸïûݦ¦¦¦óÞŸÿÙÿÿÿöóóóüüüÿ–íýÿÍ´Û·ÓùÝÍú—îêÍÎöæó·¼îÍöÿ³³³¦óóöÿüüüž»Þš¶Ö÷ôýžºÚûôÍó¬þû®ö§õÜÖ®öó¬þö–ùìí–¯ôûòò›¯ôûòýô¹ý§õþö–õüî·¬éÝì«Óþüß×ëëëÜþôë³ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«¾ª®þîÞªëÿÿÿÿÿÿÕª­½®÷Þìó§Ÿÿ®µþÿùÿæéΦݫÿ¹çò¶òþÛéö·í¯ËåÓüî·ý¦Û¶›êÓôóûÙ³þê½ê»þ½îç÷Ë«úé—ìýùÿ²³êòýÜÓëúÿüæÙ›úÞ¦–ÝÞ——×ÝŸ—××›ž÷þ›ÜÝš›––¦ûýŸ¦–ÝÛžÜÚ¦žÜÞ¦žÖÙ—–ÙܦŸúû–›šþûŸ—–›×Û—–×Ù–Ÿ—–×Ù–¦¦›Ú×—Ÿž–ÜÖš›ÝÙ›––¦ûû¦Þ×–žÖÙ–—ššýý––ššýý–šžÖÖžž—ŸÙÜž—–›ÖÞ—Ÿ¦ÜÜ–ž––þüšÛÛšŸÝÞ—Ý×ÚÜžž—Ÿ¦Ü½÷š¦—ÜÛž–—ÞÞžÙÞ—ŸÞÞÖÝžšÞÝ–›×ÜžÛÖ–Öܦ—ÚÜ–Ÿ—ÝÜ›–ÝÝ—Ÿ×Ü›š—ÛÜ–ÛÝšÛÖž–úÿÝÙÙÞ–úÿ¦›ÙÚÜÝ–Ý×—ÜóÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«¾ª¯þïÞªëÿÿÿÿÿÿÕª­´òÚ«ž¿ôòïŸþóÙ—­çùË­§×÷µ÷òÞÝ›«§žùÏßíýçµõÜ–ÝŸŸ´ú³ÜÙÖ»õëóíûû®ôû¿î曧¯ž¾·ßç­§Ù¼òéúõצŸ¦Ùëë¹êîííòûëëëÝòòòûëë뼿òé¼þó·¬éý·ëÝÏûÍæ§ý—Φüû¦üûó³ûó³÷Ÿþ¿ÜꧦùÜÞ—ý­ôþ×ÓÓóéÜ÷ëÛß¼ö¦¦¬Üû»êßííò¶³ïµÚë³Íú׳¦²Îú׳õé­ººÏ–åµê¶¹Ï´þæê²Úþž¼îÝמê–æÖéïìü¦ûü¦û³óû³ÝÖÏ´ÖÓö³³¬Ûù¼õíÝžÚß×Ùçß×ÙææææÙÙÙÙ욶Ÿ­ïÿž­–úü§–ŸÖ––š´»åÿÜêï½»ýçËù÷¦Ï²·ô«×Ó¬µÜÜêéé·Íùܾüþõ¦çÖÏ´ýò½Ï»·¾Íô—ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«¾«®ÿîÞªëÿÿÿÿÿÿÕª­¼ž·õ²¦Ó×›úÖËÙ›Ïçò—þ¼æîêõ§íöåßæ¯ó½½óì§÷ÎòÛ®Ü÷Ú®ºúÖì–´ó¯çô¬ò³æÜîú½¾·æ·¿öܾîûÙ¶êß˾ܧ²Ö———ÍÞ›ÙÙÞË––ûžÙ×—ÝÜ–Û×—ÖÜžÜܦùþžÙÞ¦ÞÖ–ÖÖ¦ÙÙ–ÙÖ¦ÙÛ›ÞÖŸ×ÝžÚÚžÝÞž–ÚךÙÞ——ýüžÚÚÛÖšŸýúš–üýŸ››¦üú—›÷å·š¦›ÎΦ¦¦—Ÿ–ξšÞÖšžŸžÝÙž–—¦ËΦ¦¦—Ÿ–ξš¦—ÜÚŸ–ÎËš¾¾—žÜÙ—–š–—›ËÍ—ž›Ÿ¦¦ÚÜŸžžš–ÝÝŸ–ÎËš¾Ëšš–¦ÙÚŸš––½½¾Í—žžšššÝÜ–—¾Í—žŸŸ×מ–›—¿½¾½–ÝÞ›¦¦ŸŸ—–˽ŸÏϦžÞ×—–š–—›·ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«¾«¯ÿïÞªëÿÿÿÿÿÿÕª­ßéžå–¿ï®«ÞŸ§×«Ö×—ÜÜÜûÏ›ååקßßÖç­ÖÙÖæšê–é´óüû¬¬šë³ì®ß§Ëô¯¦Ûæ¬Ù´ù–­ú¶æéÜß×­ßê÷Ÿîûæíßž¼«¾üþÛ駭ôùö¦×šíß×ôôô÷µ¦îæÙæýôõÜóæ¾Íý»­Ïº­Ï²¯ôôýþ²¯ôôººÎÎýý¯¿ÙôíÛùêÍÛé·¼ïþí³»–––­Ïü÷¦Ïê»û껿»åê´š·é›ïÍÏ–®¹Ýï­û´ßå—®ž·Ë—®žù­¿òÖïßé¾ê÷×îôÚ²¾æÿÞæ—¾çþÝõöæ—¾çõêß———ûþËÏßéÖý¯µ¬¬¬š­­¬Úý®·¯³ßךššçžóµß鳦ž·Ï³¦ž·Ï³¦žù´¦ùþÜêüôôõ÷š®ïüšõúîÿù¯úûôüïê¾»åþ¯§ûÿžõòî—çÖžÍæÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«¾®ªúêÞªëÿÿÿÿÿÿÕª­–úËûÎÚ÷þõ¶úëÖý×ÛÙÿöÞ›—·ûÙ›Öò÷疳ݟþþë·ÖÙõõ´Óͼö÷ÎÝ–ï²Ó¾Ó¿¼§³–Ÿ—šÚÓí¹·¾õÞ¬ìÍܼӻ­ŸºæôŸ¬¾›Ÿž—ÜÖ›šž¾Ë—Ÿ¦›žžÙÝ——Ÿ—š¾ÎŸ–ËË––ÙÖš¦¦ŸŸ›½ÎŸ–˽›–¦¦šÞÝ–›¿Íν›–Ÿ¦—ŸÛÛŸš––½½¾¾Ÿ›ž¦—Öû¾ž–¦¦º—§¿—˧›·ž—š·—ë¹–––ºì–ﶹüקºõêì–×–²ì–×–»ö–óôߧ»ö–üýÚÛÍÏëÏšë´í®ºúúúºÞ®ÍÓ¦õý›®Íϯ´Í¿ó×®çöëõ«éî¹çÞ®Íëõ«ëò¹—Üê«——¦»¬¶«——¹¹¹¹¼Ÿ§Û¿½¼××éõù¼ëòì·åê÷ëþôíæÿé¿úæÛóÿ«»õúõå½µºýÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«¾®«úëÞªëÿÿÿÿÿÿÕª­šë®òýÜ­ï¬õÝ÷¿¿·ÝýõÍúš¶»ë½ïú–ï·Ú÷¶ç¼ÝÚµÍìšß¦ë´ú·ùžžùýŸ¶Öò¬êòóçÎýÞ®ÚÖܧôÖ÷ž¯û—Ë«Ö¼ûæ®æÞ³­­Ó×ÛêÞîÖûóÙÜ«õ§šü¶Ï²õÎßêÙ¬ô­÷õü·×žýëÜò´ËíêÜç´§Ÿô«Ûé·Ý›þÎÚš§óî—í§ù·šßú§²¶šûÓÓ×–îö§ó§õÜšÞÍÙ›×ܯٶ¿®Û—ýóòôº¯ûºóٺܚîéù÷§¯å¼­ôßööõþüüü²×žê·ÿïžå¼é埻µ·ÓÿŸ÷Óöööÿ³³³õ´«ù´ßßßææÚÚ–æú½ï®ëæúüö­ß¼ÎÛŸ÷¦ÿ¦ùÜÙ¦þÏÖþ«ù¶×ßÍÿ§›þÏç–ïïóí¼­ëþÏÖܽþÍõõõô®ê×æ×ÛÛþþ—ßí³»–––§¦¦¦ëÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«¾¯ªûêÞªëÿÿÿÿÿÿÕª­¹ïÛŸåîßß÷ó½¾ý빺›Ý¶ô¦æ´÷³ìŸ›ôò¶¾×Ÿº»ôîÖé³çßíš»ì¬Þ²÷òÚ«êÍö¦ëÍ¿ö»½¼Ý×Ëò¯®Ýÿù½þŸêù½¯¬µÿšÎõïÛííçê÷Üôôíæöé½íû¿ÿï·åŸóõ§þÏÖ¾öéÝ¿Ó×®ÖÏùôߺÓþüÍüŸ÷Óóì²ü§²ýòõ§ÏÓÿ›þ¹³³³ÿÞþÛé滦·¼ÏüùÜ«ÏÚݶöÓš¬ûòž¯û¶­ôþÏÚ¹Ù­²òµôùß鬦õþòûõþ²Ÿùî³Ï¿ÖÓ›ûûûùîò–ÜÏûÚϯÛÞ³ÓÚíŸéú­åÏÓ²òÛîݵæûòü柬¦ëë×柧¼ç–üïÞôôóüúúýôòûü¿Ù®òû—Ûï·êé´ÎýýýöÍÿÚÍÿåïïïúûûûòæê´þÙŸš¶¬õµéÍííòûõõ×ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«¾¯«ûëÞªëÿÿÿÿÿÿÕª­¿¾Úß«ïûÛêå¹þëç¦ÛÜ×濺žÖÙíôÜæýóëËõ²Ííìöùïÿ®­Ýº÷￶õ®š¿Ýþï¿æš¾ùëë¶éëÛïÛßÞôÚù›ò¹ßþüÝ­¦ŸšÞ––›­õõ«—³³³ÝÜêóò²®µ¼­­üôºüÚ–ß¼¼ßóõ²·¼ÏÖþÿ—¼³³³ÝÛ髯–§ž®µ»÷˳æ×ÙÿÿÙÙîúóýçÛìÙåׯÞÙ榦¦ó¿ÛÛïúò›í¦õî»ßܳçÜùç–üí»¶¿å¶ê®´ëþÜêüýòùöü·³æÓ¦¦¦³þþ—«§§­›³³³ÝÜêüíÞ½Ûì¬Óéî¦Öï¼þÖϽÏíéÙ÷Ïš¶çÜÏš³ÿéϚͷþòšÙë´²½¹›Û¾ýÏõõ««é—·¦ÙÏßéòÚýçÎÓÓÛÎ÷ë¼Ï¦›—½¿›š–¦ž–¶›³Ëž–šŸž¼›óôåßÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«¾®®úîÞªëÿÿÿÿÿÿÕª­ÚÚ´úÖ¦¯¦ÜÛµîì³Ý´´–Öß²¦ôûÿ½¬Þ¹ý®Ù­ç×׬éÏÓ´·åÚÜéî¾²Þ«Ú¿ò·ùßÙ«¿úïùßµ·ôºý¹îîêμܟ¶º¶·ŸºµëßéûÚõçòû¬šòû¯ÿÍúÎåòÏûÚ¬®¹ÿ²ýšßÛòþþ¯¿ï»òõõõõò´Í§—ê¶Ü¦›ÓÛß·µæÞÞ–ÙÏþê´ÿ¬º÷½ÿ¼æß¼¼ß½´­üôº¦î¦Í¿åÖܯü–¶µéÝÞ—³ºì–«¯½Îòúó—ÍÙîúó×—³×ýûôç¿ÜÚþßÜòýçç묗ϺŸ¯¾¶Ÿ³ß×Ù×›³Í–ŸóùÏκì–ïúóšíïË˦«¶¹Ûµšî›žöéì–ï×ìîÿ×ìíÝ˽šµ§¹½þë´þüï–óóïýòÖÝó×ܬóÛ準Ùéì–ü­Ÿïÿ¬¹½þú²§º¦¼ùÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«¾®¯úïÞªëÿÿÿÿÿÿÕª­Öçç³–êÖݯ¯æùòß««÷¶ÓýíÍåîíí½§ÍÎý®ïúÏ­éö¹óò¼íë¯ÜžÝ›òóö涽¼úêïó®¬Ë—¾¯üí½ŸþͦÞÿÓ󶲮–––¬üü§í³»–––åµê§ýåßüÝüÍ–––½½–––––Ëùíߧõ¹—êš×«—§§§åÞ»î—ò¶ß§Ü¼¹Öîýšüùæé›×üïç×üïç׳—ç׳ýÞ—¼÷Ïë®ëÜêïùÿ§óÛé§ö§ÿ»å¦¯§®éé½ó·¼–û¼îͦ¿óîÓÓÓŸß«Ëíí÷æ§ý—ü´ìÎæ×›æÜê²ó«¼×öïéßõ﬽¶µò··Ÿüù›æÛé·ôµÏ­»ÿÞïËÜùÎíó·õÍÚÜÏõºË²ýí鿽½ôµ¶êÜ¿ö§êò§Ü—ì»å×ÚŸºÝßÚ¦¿óîÓÓÓŸëÞ›»—›¿½½þõÛÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«¾¯®ûîÞªëÿÿÿÿÿÿÕª­›åÝÜé®Öמ¼½¿¬½þý«›ê§é­ÚÛ¯ž²Öæž²µ½¶½žëÜë—ç·û¹»ßßžìé–¼ò–ŸŸï×Ëß½êÎ浶«Ýž¦¦­½½æÛÝÙ­×Ýž–ì­ºŸóùÏÜݾµ­··§ì–槾ÿîӺϳõîííòïßצ¦Ÿ­¬¿ûô–ËýÖ¶šÙúüÙ»õçýõ»¶šÞÿþÖ²¬®§²¬¬¾òÏé­ºæ×¹Ó²ýç»ýí훿×ûû¬šò–¿×ûû¯Ûê´ÓæóþÚôôóüúúýôòòòûûûúúúúú·¿ÛÏýóô²íí﻽óóó÷æ×ÿÿÛÎÏìí›Üϳ¦ò–ÜϳõüÝþþí–²ýòùÿ¯î­ôþ²òýÜêü÷õ–²ýòùÿºåÛ駭ôšŸß–òýººÖôçºÏôôôüß鬿ê¾ÏÖþõ§Ï¬®½Ï¬¼ÜÖô÷êßüéÞæ–å—ïûÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«¾¯¯ûïÞªëÿÿÿÿÿÿÕª­–§§––®®–––—––››——šš––››——šš––››——šš––››—›––šš——››––šš——››––šš——››––šš——›–››——šš––››——–––––––––––žŸŸŸŸŸŸ¦¦¦¦¦¦¦¦žžžžžžž–››››››››šššššššš————————–––––––—šššššššš››››››››–––—––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«¿ªªþëÞªëÿÿÿÿÿÿÕª­š–ú´÷¿ýÿ®üóôÚ½ú¾­šæçç›ééžÖæ­ííå뺷§´¾¬×ßš²õÍÝý¦¿Ú«Ù÷ïßåîÍ·Ó§¼žÏÛÚ›×Ú¶ËÚå³Ó¾¿–¶ÙûºÝꦲ÷½›¾Ýüš½Ý¿®òÏ­îï»Ûמϗ¦›½Ïíûõëë¯ûõîó¿¹Ý·—úû—úû²ôû²ôû²ô«®¼ß¼ÜÝóúçÜü§¶ê»–û§òÛÓû§òû§òû§òû­íû­íû­ûù«­›²ÿïæ×Ü®Ûééé·—åò¼Þ¹ôçùö—³–²åÞ–²ž­úüö榦¦ó¿ÛÛïúî—çÍõ­›žíéëïúÞ²·óßß­Úß··÷¬šó·Ÿê¬Ÿ´Û·´óÿݾÿ»åÎÖ—×Ö—××Úßó¿¿ó·ÿéßé¼¼îÎêÓ–«Ýšÿí³»«««—ê÷ýåß׬òîê–¦çß隽Ϛ§îìçêïÛé–ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«¿ª«þêÞªëÿÿÿÿÿÿÕª­î¬ê­ž­­šë—õ—ÝóÙúÖü¿³ù§æ›ù÷ü§ž¬­¬§ú–«®×²öŸçú²êîß›öÖõëîæòÞû鿲½ù¹ž¶ìÏ›¶ïº×ºïÓ–ïšÖ›ÿòº×õ–šõ¹×××ßé®­õ¹ÖÖÖ¶µö¾þ–ÖÏþ÷íš­–ÝÍåçÞü«ùóô÷ùóô¾Ùå½þ¼Ïý¶Óù—²·åçÞü«ùóô÷ùóô¾ÙåšÛ¼Ï§Þ–Ý—²µ¹ÿšß­´¹×ç¹ÿ¶ëý´µó¬´­´ûöù××ïÍ­´é¾××ææ²ôÿ××ææ××ååó¶Í–åï¹®ùóô÷ùóô¾Ùåõ´—³û–ý–¦–®–ž–›–Ï–ž–š–³–š–Ÿ–š–þ–›–Ÿ–š›š–³–š–—–¦–—–›–—–Ó–—–›–———–¦–———–›–––—–––³–––———–––›–––––———–––––¦¦¦–›ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«¿«ªÿëÞªëÿÿÿÿÿÿÕª­§Û¹ÍæŸÝç»î×­¬ê¦æš§Ÿþþ²¬öúꯦߧî¼Ï¿ìÜùµ÷ß—Û»¾¾å¯Ó¾å²³ëŸî·ûúÜÞæšúç§Ö·òööýŸ«¿½´½õŸ½õþ§–¦¯­óó¬ÖÙçæ«çþÜËÿÛËÿÛ¿æ×ÝéÙ«×Þëß×ÞìëÚÙ²ÖÍŸŸ«ÿì쮯ò³Úûç§Úç§Ú秶½úµßË–·§ßß·ûß­––­–­­–­Ë´ÖÖ›¯¬«×ßç¶íüýåÖ¶Ëò§ûê¶Îæ«æžº²ºêæóùÙ«×Ýçݶ´›ÿÎë·Î–ž½ÎêêµÍ¯ÖÜÏþê·Ùµê¹úÝß×Ú¿µêìæ«åëžíšóžß뺯þÝÓîܲ´ïéûά¶šúë·Óßé¿íìýÏ­ýôÚô»ž–žýïýî¬æô»ž§–šìýÏ­ýÿìܽ»²ž÷óûÎêêÖý¯¯Ï¬ïï¿õ³ì–¬ŸÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«¿««ÿêÞªëÿÿÿÿÿÿÕª­ò÷–ߦ۾½›æºÎ½¾ÖêÛìåê›Ö³²­éÿºé¬æÚíˬš§éí¹×¶Ë×埮Ùߟ®õüíîî¿Ö¬éëþͽ½ïïÖîÍË·ÜÞ¦²ìÜŸå—íúí½šô–––µ¬Ûù¼Þô÷—éóÞŸÿåÙ–Ó×Óóóóº—ïòÎÚþÛ駚üÜÞ—«ÛÛöî¿ÖõÙüå¦ßëóÝüëóÝ—ÿé·šÞüï·üמùÞíÚúåòõéÙ›þþþ¦òç횶Íü½´Í×μõÿï·åŸ²ïééŸïûݦ¦¦¦óÞŸÿÙÿÿÿöóóóüüüÿ–íýÿÍ´Û·ÓùÝÍú—îêÍÎöæó·¼îÍöÿ³³³¦óóöÿüüüž»Þš¶Ö÷ôýžºÚûôÍó¬þû®ö§õÜÖ®öó¬þö–ùìí–¯ôûòò›¯ôûòýô¹ý§õþö–õüî·¬éÝì«Óþüß×ëëëÜþôë³ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«¿ª®þïÞªëÿÿÿÿÿÿÕª­šÜ·ôÚᄃ§«êÜÚöóë߯›Öå­¯ÿõìÚÝÛôÿõ»­ž¹îçù¿½ö»¶×Ú§æååæÖåç²­²Ûêš÷ϧ®—­Ÿöê³ÓŸÝæßåì¬æÞ³¦Ýòî›ÚÖšî²–ü«§Üæ¯ö§§ýËΫÙß϶¿ûÖ·õ–é¿ÝÎß·õé¿ÎÏ´·ÜÏßµÏìַˬ§ý§êÙÍÙþ¯–ÿ§÷êÖ·²Ÿë–ü¶ëÎßÙÙ«ÛÛ¿Ù×´ê´Ý÷æÚç§Úç§Ú秿§Íôò§¶í¾ò§×ô÷뽧êÜ¿¶÷æùêôôôó³ûôôó³ùç§Úç§ÝÖýò§ÛÜ·êÜÜÏôö秾¯¿öêþ–ºŸêôÝéÙ«éꛬæ»úÞü®¯ôóüüìú×óùܽ»²ž½Îêêò²ô÷þûÝòý÷¿þõ¬ïìü®¯ôóüü®¯–Ù»–—›Ÿ®½ö÷–—›Ÿ›¯Íž­ýŸ¬Ï¬ùÿÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«¿ª¯þîÞªëÿÿÿÿÿÿÕª­´òÚ«ž¿ôòïŸþóÙ—­çùË­§×÷µ÷òÞÝ›«§žùÏßíýçµõÜ–ÝŸŸ´ú³ÜÙÖ»õëóíûû®ôû¿î曧¯ž¾·ßç­§Ù¼òéúõצŸ¦Ùëë¹êîííòûëëëÝòòòûëë뼿òé¼þó·¬éý·ëÝÏûÍæ§ý—Φüû¦üûó³ûó³÷Ÿþ¿ÜꧦùÜÞ—ý­ôþ×ÓÓóéÜ÷ëÛß¼ö¦¦¬Üû»êßííò¶³ïµÚë³Íú׳¦²Îú׳õé­ººÏ–åµê¶¹Ï´þæê²Úþž¼îÝמê–æÖéïìü¦ûü¦û³óû³ÝÖÏ´ÖÓö³³¬Ûù¼õíÝžÚß×Ùçß×ÙææææÙÙÙÙ욶Ÿ­ïÿž­–úü§–ŸÖ––š´»åÿÜêï½»ýçËù÷¦Ï²·ô«×Ó¬µÜÜêéé·Íùܾüþõ¦çÖÏ´ýò½Ï»·¾Íô—ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«¿«®ÿïÞªëÿÿÿÿÿÿÕª­¶·÷ËמܿÞËÛÖ­¼Ïêµë¹¼žÜÓþù›õ¾´¾¿û÷ך´Ö›Ùæ×Ú¯¯–¬®¯æ«Ÿóù›Úþò×ÜÏËÚžî­ŸÍóߧ¼µŸì¾ïµÚײúýŸÛÖ­çÖ›¬¬­§­––×ç§åÖË–½­š­§Úç§çÙ«š¾¶«šß½ËÜŸºÜßÝ­Íç§ÙÛζ«ÛÛûò§Ú秽ùÞÞÞé÷–––òôõ߫垺²ºôŸµåž¹³Ÿ·ôÿÙ«ßßÚå¬ßëÞôü§—óóóþÙ«åü˼¯ôóîÜ«þšïìü®¯ôóîÛ§þšŸŸ¯´ýŸ––Ý–¯ÿïóùÿëëïŸæùÞÞÞé÷–––òôõ߫垺²ºôŸµåž¹³Ÿ·ôÿÙ«ßßÚå¬ßëÞôü§—óóóþÙ«åü˼¯ôóîÜ«÷ïìü®¯ôóîÛ§þšŸŸ¯´ýŸ––Ý–¯ÿïóùÿëëïŸæ´é´óÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«¿«¯ÿîÞªëÿÿÿÿÿÿÕª­ßéžå–¿ï®«ÞŸ§×«Ö×—ÜÜÜûÏ›ååקßßÖç­ÖÙÖæšê–é´óüû¬¬šë³ì®ß§Ëô¯¦Ûæ¬Ù´ù–­ú¶æéÜß×­ßê÷Ÿîûæíßž¼«¾üþÛ駭ôùö¦×šíß×ôôô÷µ¦îæÙæýôõÜóæ¾Íý»­Ïº­Ï²¯ôôýþ²¯ôôººÎÎýý¯¿ÙôíÛùêÍÛé·¼ïþí³»–––­Ïü÷¦Ïê»û껿»åê´š·é›ïÍÏ–®¹Ýï­û´ßå—®ž·Ë—®žù­¿òÖïßé¾ê÷×îôÚ²¾æÿÞæ—¾çþÝõöæ—¾çõêß———ûþËÏßéÖý¯µ¬¬¬š­­¬Úý®·¯³ßךššçžóµß鳦ž·Ï³¦ž·Ï³¦žù´¦ùþÜêüôôõ÷š®ïüšõúîÿù¯úûôüïê¾»åþ¯§ûÿžõòî—çÖžÍæÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«¿®ªúëÞªëÿÿÿÿÿÿÕª­ëšìÞÞ˹ÜÙÓֵܫ²§ËéŸÿÎïÝÝóýÙ×ÛçìúþÛùÏÝÜÛ«¯¦Í˽üÖæÓÏé·ó§ìì´óÍõ¯ì¼õ¹ú®Þæ·ÎæµÿµÛßëò—Ù櫧ÚÓÝ¿ë¶ë¶›ÿÓÚ§½´õ¬Þ®çÓÙ«¶¿é´üºåü붻íó®ÙÚÓÏí¶µêÓÚ§½´é´Þ¼íüõ¬üÍÖüŸúÓÚ§½´õ¬üÍÖüë¶ÓÚ§½ûç§ßÛé´¼æ«ßÙšé´Ýù׬×Þê׬×ÞëÖ–é´§ïÝßíõúüéÖ²ÝÛùÿ–éŸæÓÓé½Ïæε¬æíšíêåþÝîÞ²þ¬ûç§ßåêþ÷½Ïþ÷¶þüúÛÓ߫׷ç­é´ŸšÍµÜû秧³ûóö–ºæ×ëé嬟Óæ¾–ßÚëé嬾æÓÜ÷›Öç­ßõçÝëëëýŸó¿¿×òòòò¶¶¶ûõ—ºæ§§ÿ¹Ú§–ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«¿®«úêÞªëÿÿÿÿÿÿÕª­šë®òýÜ­ï¬õÝ÷¿¿·ÝýõÍúš¶»ë½ïú–ï·Ú÷¶ç¼ÝÚµÍìšß¦ë´ú·ùžžùýŸ¶Öò¬êòóçÎýÞ®ÚÖܧôÖ÷ž¯û—Ë«Ö¼ûæ®æÞ³­­Ó×ÛêÞîÖûóÙÜ«õ§šü¶Ï²õÎßêÙ¬ô­÷õü·×žýëÜò´ËíêÜç´§Ÿô«Ûé·Ý›þÎÚš§óî—í§ù·šßú§²¶šûÓÓ×–îö§ó§õÜšÞÍÙ›×ܯٶ¿®Û—ýóòôº¯ûºóٺܚîéù÷§¯å¼­ôßööõþüüü²×žê·ÿïžå¼é埻µ·ÓÿŸ÷Óöööÿ³³³õ´«ù´ßßßææÚÚ–æú½ï®ëæúüö­ß¼ÎÛŸ÷¦ÿ¦ùÜÙ¦þÏÖþ«ù¶×ßÍÿ§›þÏç–ïïóí¼­ëþÏÖܽþÍõõõô®ê×æ×ÛÛþþ—ßí³»–––§¦¦¦ëÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«¿¯ªûëÞªëÿÿÿÿÿÿÕª­üÍÞ§Þïÿ×¼›íÛÙ³—é–Ûæç·³¯ìïµ×Ûš¦õ÷–ÜöÍ­«›–ÞÝŸ¯¯Öë›×êÏíûºÓÎÍÖÏÝÖó­ÎÙÖ§¾þßå·ô²«³Ÿ–¯Î­«ÙíæÓµÖ—íý§æÓûº·¿¹§ôòïÿ–žŸ—ýÿ›üõµÓ¦î¯ô²Í÷Û¹ëó¬ÿô–—¯µÎååå姲ÿ·—ÚòºžÞò»éé鯲ÿîçÍöçÏöžÞݯöóíí·«×û·«Ù›®öýûæéŸõí«ÿõ½×Ö»Ÿ¦Ÿ³®ÚÞžÞê—Ëôëü®ú»Ë®¬¦ÏÝýûßÞõšóõý–Û½þšéÞöüú´¼öõýþŸû–þš²«öõ›þýìå¿ÎìêšéÚ³óüæÓú¹·òý§óï¿žÓ§ÿ­óæÓ²ùºÓ½ïÎÓÎÝÿ¾ÍÛÚë–ï½ÏöúóÜåéÙæÜïõúÝíßéÚåÛšÙÝúõ§ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«¿¯«ûêÞªëÿÿÿÿÿÿÕª­¿¾Úß«ïûÛêå¹þëç¦ÛÜ×濺žÖÙíôÜæýóëËõ²Ííìöùïÿ®­Ýº÷￶õ®š¿Ýþï¿æš¾ùëë¶éëÛïÛßÞôÚù›ò¹ßþüÝ­¦ŸšÞ––›­õõ«—³³³ÝÜêóò²®µ¼­­üôºüÚ–ß¼¼ßóõ²·¼ÏÖþÿ—¼³³³ÝÛ髯–§ž®µ»÷˳æ×ÙÿÿÙÙîúóýçÛìÙåׯÞÙ榦¦ó¿ÛÛïúò›í¦õî»ßܳçÜùç–üí»¶¿å¶ê®´ëþÜêüýòùöü·³æÓ¦¦¦³þþ—«§§­›³³³ÝÜêüíÞ½Ûì¬Óéî¦Öï¼þÖϽÏíéÙ÷Ïš¶çÜÏš³ÿéϚͷþòšÙë´²½¹›Û¾ýÏõõ««é—·¦ÙÏßéòÚýçÎÓÓÛÎ÷ë¼Ï¦›—½¿›š–¦ž–¶›³Ëž–šŸž¼›óôåßÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«¿®®úïÞªëÿÿÿÿÿÿÕª­—×—ŸŸå韫«½þ¹Ý»ÖÖÙ÷úÙË÷ßß–é³Ú–—ܯÎý²Üܼ״ÖÖµ»­§––Í¿š®Ï履Ӻ®—¿—ü×å×­–òçîû¶½š¦ÿïíæ¬íï›æμÙùŸöæ秫ÿù³§õíÜÙ­æÓôýô—§Üé–åÛ¯ßßêìÝóæïܶ²ú³ù¾ºåïÿýÎÝÿ¾¹¼÷ݼ¶þë³¼»«Ÿ—ô³ûóÎÖÎߧ›öóÎÖÍÓë´õ—ºì¯ú¯Ïæ›õ—¼×—ö–·¶õö–¼ÝŸò›ÿ¶¿ææ›Ýµ¼Üå½ì¿õž––¬ÿòŸß¿›óöéË·Ú¦þ«ºšÖòº–Ùòܶþ«º–Ùòº«íߺ«íßÍÎþÚÎþæùíÎþ½ï¿½ÎÝÿ¾Óæ§ü—Óºöü—ÝÎîÏ׶êÏ×åÝëÖÖÚÚÚæß×ÖÖÚÚÚçÝÝåÛÝퟬ¦ûퟫ¹ÝÚêíîü÷ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«¿®¯úîÞªëÿÿÿÿÿÿÕª­Öçç³–êÖݯ¯æùòß««÷¶ÓýíÍåîíí½§ÍÎý®ïúÏ­éö¹óò¼íë¯ÜžÝ›òóö涽¼úêïó®¬Ë—¾¯üí½ŸþͦÞÿÓ󶲮–––¬üü§í³»–––åµê§ýåßüÝüÍ–––½½–––––Ëùíߧõ¹—êš×«—§§§åÞ»î—ò¶ß§Ü¼¹Öîýšüùæé›×üïç×üïç׳—ç׳ýÞ—¼÷Ïë®ëÜêïùÿ§óÛé§ö§ÿ»å¦¯§®éé½ó·¼–û¼îͦ¿óîÓÓÓŸß«Ëíí÷æ§ý—ü´ìÎæ×›æÜê²ó«¼×öïéßõ﬽¶µò··Ÿüù›æÛé·ôµÏ­»ÿÞïËÜùÎíó·õÍÚÜÏõºË²ýí鿽½ôµ¶êÜ¿ö§êò§Ü—ì»å×ÚŸºÝßÚ¦¿óîÓÓÓŸëÞ›»—›¿½½þõÛÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«¿¯®ûïÞªëÿÿÿÿÿÿÕª­ßٯ쫭²®×ßìëßžéž®—éÜÖ¯Ùš¯ÞÝ–¦´Û·êšæεúíÝïÓìÝóÙößôÜòߧ–˺ü﬚˴½Îºé»õµõúÝÞËçÓë²Ýë«—®Íûß«þ«¾ëæ¼Íå§æ¼ì¶éµ¦Ÿ¯–÷òŸ›ÏÝÝåÛÝÚÙÙÙúúæ姾ÛÍ姾Û󚬬ææïþçÓ¶åÛÝûûõš³ûퟗêù×åç·¶ÙÚçç·¶ÙÚçåÛÝëëòîüžçûç¬þ«»ç¬æ¼ÍåÛݬæ¼ì¶æ¼Íç¬þ«»ç¬æ¼Íå§æ¼ý›óº«íßöþ«ºšûßÏÙÙÙ­æ¼ý›ó»åµ¶ÙÙçå´¶ÞéÙšÖò»ÝýÝþË翧òº—Úò¾¶ôçŸÛòµ¿—ýòÎÝîÍæ´ï¹¾š–›–––—––ß×ÖÖÖÚ¶öçë²­õ¹ÖÖÖåÖ–­õ¹ÚÚÚæ欧ުëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ«¿¯¯ûîÞªëÿÿÿÿÿÿÕª­§§––®®––––›šš——››––šš——››––šš——››––šš——›–šš––››——šš–š——››––šš——››––šš——››––šš——››––š––––––––––––žŸŸŸŸŸŸ¦¦¦¦¦¦¦¦žžžžžžž—––––————————šššššššš››››››››––––––––————————ššššššš›––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®ºªªûîÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®ºª«ûïÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®º«ªúîÞªëÿÿÿÿÿÿÕª­ßÝÝóÎôþ«ï×Íí¹ü¹Öí¶òï¼ýùÜîÖ駷¼ÍæçÛôËËêåþúÖÛìËëõ²÷¯òæ¿üÚöû­ïÚóê¿íî¼»ŸŸï´×ÓþÛ½›¦³¾ÿóêû¯ùò›—–šå›Ý–––®ž¦¦žÙéçܬ§ž¦µ½ý¯ò¦¦ÙÛ½ž—¦½¿¾§´¶¬§¹—ŸŸ½ý¯òŸ—¦ÙÛÍ—ŸŸµ¾Ë­«´—š¿ý¯ò¦¦ÙÛ½–ž—žžÍ½—š–ËͦŸŸšµÜÞ§¬ßÛ–šååϾýü¾¦¦—ž–¦—š¾Ë›—žÍ½ž—ž¾ŸÙÖ–––šåÞéë²®ëÿ½—½—ŸËË›—žÍ½ž—ž¾§îò÷úéÛ½—šŸžÍÍ——Ÿ—š¾½¾«÷úþüܵþŸ–þ÷ï￾›÷þŸ–Öþ¾¦ÙéþüõôåÛ–šÜ·ïŸ––Ÿþ¦þüËÝ–——®«­óö—ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®º««úïÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®ºª®ûêÞªëÿÿÿÿÿÿÕª­¯½ÜÖ¶åö®×æ¹ïçϺ³§÷ÖÿËצ¹–ú٧ͽšŸ—­šŸ¦«³—¬­Ÿ§–›–—­¬š¯›®¯­¬³—¦¬›§²š››®«­Ÿ²ž¯ž¦š–—³—¯³—§ëÝΦ–ŸÍÍ–¦šž›ËÍžž—¦ŸžžÍΦšžÎΦ›¾¾›—š¾§½¿û÷ìÖÖú—ŸŸ½—Ë›—žÍ½ž—ž¾Í—ŸŸ½—–½—¾Í–žžžšŸÎË–ËΦ–ŸÍ¾›ŸŸ¿§Ë¾ùúìþ—š¿¦ëÖÞÜüÿìÝͦš—ž¾½›–¦—ŸŸÎΦ›¾¾š¦Í¦¦Í–¦šž›–——š¾§ìêššéÖÖÝË››Ÿž›Ë¾š¦Í¾ž–¦¦Í––í–Ÿ¬ïí——éþ—š¿¦ëÖ––¬¬–––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®ºª¯ûëÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®º«®úêÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®º«¯úëÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®º®ªÿîÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®º®«ÿïÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®º¯ªþîÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®º¯«þïÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®º®®ÿêÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®º®¯ÿëÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®º¯®þêÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®º¯¯þëÞªëÿÿÿÿÿÿÕª­–––––––––––––——šš–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––Ÿžžž›––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®»ªªûïÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®»ª«ûîÞªëÿÿÿÿÿÿÕª­›––›––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÿ––ÿ–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®»«ªúïÞªëÿÿÿÿÿÿÕª­ßí·æ³ëíõéú·å§ŸóËòí²éšÞý¶®õ®¬–ïëÛ³³×å×–®ìý·ç›§Ùšúò§Þ®ìÞçµ·µ³îõþ§ÛÙ˶«žé³Ûë²ßÚ­é²Ù¬›«šššýþçå­«›¬–¬ßæ§íú¬æÖÝÙé߬«›åç¦ô×ìÿ´š·÷–––´ç«íúµþìå柹´º«ìößÙÓ·ôõ×ú·å¾þ÷þß߬íúµþìß߬«›ßæ§íú¬¶Üö¿´ë¼·ìåÙ³Üû¼ßÝù¼æ§«›ßæ§íú¬­—ßæ§íú¬Ÿ®ëÓûåÚÝõ÷߬«›åöÓ—ëéšÝÜçßõóæ߬íúßç«íú¬Ÿ®ëëß߬«›µ«½ß߬«›ßç«íú¬Ÿ®ë¶ºï¿µ–––´ïµÎ»æ×ÎÞÞüæç««›ßç«íú¬Ÿ®ë¾Ý–µ–ßž¼úÚη¼úÚιßé´ë´ÙßòÜ»²šÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®»««úîÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®»ª®ûëÞªëÿÿÿÿÿÿÕª­×ù÷›ïû¶ûÚ֮ۧݴ»õŸÎ«Û²–æ«×åÚ½ûî–ËåÖÝŸí÷¿æ·ìžµÝõÖ´µ«üóÝìµ¾¯ÜÚÍší½»Î³ýçì¼ò·´ùù´ºžÛ¬²—üž§³šž§²Ù¬¿ÏåÜûߵߧò¦ÿûýëÚ³ù²§»«íߺ»ÎéÞéÞìÛºÏééìêÏýæ­–ê¹´­ü¯µÓýò¹¿üó§úÏúÏöæιßëë–ï–¿¹š®š¹ÚìßÞç³ùšÿûûåë–ïµÓÿî¾¼þò¯–ýòŸ¯ö»ïš³ç³ùšÿò¬÷Ïïæóóææ§Ûëßåçîµþõéæêî¾îšóíôåßû×¾Öù¾÷Ö½ßí½îÿù›îϬÖïóï²í÷×ÎÎιßé´Óö¼Öó¹îÏ´Óö¼Öó¹çéæý´Üÿ¿×ÝùÞùÿÓËÝüÖÖéé¿¿ùùÞÝùù¬¬··ÖÖÿÿ–­––§ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®»ª¯ûêÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®»«®úëÞªëÿÿÿÿÿÿÕª­íÚó³¼²¶ÿüÛëÛºÿš³ù»ë›ïò§ššïïﶚšÝæ–Í﮼÷çþ­Ó—ÿ´Íú¶ÖóŸïÚí«ÙæšÝ¦åæÓÝæùšÖÙ÷ßÛ¿¬ÍÖ§ßü§ßíõ¬Îš¦Í¦¦––Ë›—žÍ››½ž—ž¾Î–¦——¦›º–­–½›¦ššŸ››¦Î½–¦š¾½›–¦—–žÓ¾—›Ë›š–š–­­–––––––––½›–ËÍŸ››¦—ÍÍžžžž—–¿§–––­–––––––š¾–ŸÎË–›—›—š¾¾š¦Í¿—›—–ËåÖ¼¦š—ž¾¿—¦—–ÎΦ›¾–¾žž–¦—š¾–Í–¦šž›¿Î¼¶›—š¾Ë››šÓÝç–¼žššš›—žÍΦšžÎ–Ë›—žÍ–¾ššžÍË–ŸÎ½ž—ž¶»¦›¾–¾žž–¦—š¾–Í–¦šž›½›Ë·ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®»«¯úêÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®»®ªÿïÞªëÿÿÿÿÿÿÕª­µ«÷ßïîÜõÏÏí¬ÚÚš§úÙíÙù¹Þ÷¶Ú˾Úû»ò¹§ÙߧÖþ¯öþùû´Ïúêìæ¶ï«³é§¶÷½šúó·Îš¹üý³é²–¬×ן鼗Ïé¬ìå§ÍÍͦ›–—¾¿¦Î¿—´»¦›¾¾›ŸŸ¿¾›Ÿž—žŸ¦šº–­–Φ–ŸÍ¿ŸÍΦ›¾¾›—š¾Ë››š¾Î¦šžÎΦ—–˽—¶¼¦›–—–¾Î¦¦¦–—ËΦ›¾¿—›—–Ó¯–­––Ö策ͦ›–—¾Î¦›¾¾›ŸŸ›–¾ÎŸË½—¾Ë›—žž–¾–¿—´»¦›¾¾›ŸŸ¿¾žŸ¦¿§–­–Í–žž–ÍÏšž–—¦ÓΦ›šËÍž——¦º–´–ŸÓŸ¿›¾ÏžŸÎΞ›ŸÎ½½¾››––žžšŸÎ¾›—š¾Ë››š¿Ó–žž–ÍϦž¦ÍßÖ­–Φ›¾¾›ŸŸ›–µÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®»®«ÿîÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®»¯ªþïÞªëÿÿÿÿÿÿÕª­÷ó¶ôÚµûÖ­¾ï¶þõÙþéßþ«ù²šé®ÿò§×þ춿Ïߟ»ó½–õý¼´²ÍÛ¦òóæÖëì«¿ù«¶öêî¦ü§ì›êòÖ¾ò¿³Ûåõ¼¿ÿÛŸì—–§¿šÍ½—–šËΗž—ž–¿›ÏžŸÎË›Ÿšžš–Ÿ¾¿¦Î½žÎΦ–ŸÍΦ—š¿§–­–¿›¾ÏžŸÎΦŸŸ¿ÎŸË–Ë›—žÍ–½›–Ÿ¦›žÍ¾›ŸŸ¾§¶–¿›Í–žž–ÍÏšž–—¦Í§–­–ËŸ¦›ž—¦Ÿž¾Í–žž–ÍϦž¦ÓΟ˾¦¦Î–Ë›—žÍçÖ–­–¿›¾ÏžŸÎΦŸŸ¿ÎŸËÍž—šÏÍ–žž–ÍÏšž–—¦¹–­–ËŸ¦›ž—¦Ÿž¾Í–žž–ÍϦž¦ÓΟ˾¦¦Î–Ë›—žÍçÖ­–¿—¦žž—ν½Íšš—šË§ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®»¯«þîÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®»®®ÿëÞªëÿÿÿÿÿÿÕª­í²µé¯æß뚶ò«´ó¯­ýüååŸìÝúÿß›šÍìòåûÓÝ÷ÓíÿéËŸî®ßÓ§ÏÞ³Þ¯úÝßË­ÎÚíÝí¶éíåÎÿÓÛ½å–ü³Í¬®÷«¯Ý·ï«¾›ŸŸ›–¾½›š¾Í–žž–¼ºšž–—¦ÓΟËÍž—›–ŸÎ¾š¦üçš––«–Ο›–›š¾ÎŸËÍž——¾¿—›—–¿§ÖÖš––«–¿—›—–¾Ëš¾¾š¦Í¦¦––š¾›—žÏš¿ŸÍË–Ÿ»–·žžš—›–›š¿›–½š›—š¿¿—¦———žž¦—–¦Ó§ÖÖš––«–Ο›–›š¾ÎŸËΗŸ¦¿›–¾›ŸŸ›–¾ËŸ——ν—¶µ——¦¦š›—¦–¾Í–¦¦žž¦žÎ›–½š›—š¿¾›ŸŸ›–¶¶š¦ÍÍ–¦¦žžÍ¿—¦žž—¦—–½ßÖš––«–¾›Ÿ¹ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®»®¯ÿêÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®»¯®þëÞªëÿÿÿÿÿÿÕª­Ú—¶–»»»ÜÚ·ï·ïæ¬ßôÏ­úùçÙ¶îžÛžÞÖ–«Ÿ­²¬š§¯Ÿ¦²«¦®–š¦®¦—–§®®§–§–®®®§–§–§–®––––«õ²´›–¾¿ŸÍΗŸ¦¾Í–¦Ÿ—ž–¿›–Ížš–Ÿ¶»—Ÿ¦¾Í–¦Ÿ—žÎΞ–ËßÍ––––––––––——––––––––––––––——–ÿ½½–––½Ë›––––½½––û¯õ½½–––½Ë›––––½½º—Ÿ¦–šË½ŸÏ¿š›šžÍÍÓ›¿¦——Ÿ–˾–——š›—žÍ—Ÿ›š››ŸšÓ¦–ŸÍËšž–—–¾¿ŸÍ¾›—–šžÓ›Î¦ÏÍž——¾¿¦¿žî––––––––––––––––––––––––––––––––––––––––––––ÿÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®»¯¯þêÞªëÿÿÿÿÿÿÕª­––––––––––––š››––šš——››––šš—›–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––Ÿžžžžžž¦—––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯ºªªúîÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯ºª«úïÞªëÿÿÿÿÿÿÕª­–¯³«–›—›²²­®¦—®²ž¦­¬Ÿž³››š›—–›–š—š—›šš›–›—–š—››š–š—›››š›—–›–š—–›—››š–š—›››š›—–›–š—š›šô–žž–ÍÍž–—¦ù˵¹Ü›Ù´š–š·ÏÚæ–—ž»»ó–ž–—¦ù˵¹Ü›Ù´š–š·ÏÚæ–—ž»»®½Ü›Ù´š–š·ÏÚæ–—ž»»½½¹Ü›Ù´šÙÖ·ÏÚæ–—Ö×»»››»»óó–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯º«ªûîÞªëÿÿÿÿÿÿÕª­´›—¦¯­——›–š›®§§®í÷§´Öߧʹó½ß§÷®óßÿå架ںÍé´ßüÛš×–··íò¶¬´§´í–í´µò×·´š›ºé¹÷óçü›¶Ú›—³«–›š¶¶¦šž¼ý–––––––––––––––––––––––––榖¦¼ýš––––––¾›ŸŸ¿½›¦šÏ–––––––šæ¦¯¬¼ýš––––½›¦ššŸ››¦Î½ŸÏ––––––šæ¦­®¼ýš–½–¦š¾½›–¦—–žÓ¾—›Ë›––šæ¦§³¼ýš––––––––š–š––––––––––šæ¦»µ¼ý–––––––––––––––––––––––––榵»½¶çµ›–›—¾½›¦šÎ½›šÏݬ¼Þ¾žÍÍ雿¾·Ù›Ù½ÛåžÍͳ¹Ë·×Ù½ÜÞ¬ÍÍ·ÏÚæ–½¶¬ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯º««ûïÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯ºª®úêÞªëÿÿÿÿÿÿÕª­ééßüÛ¿ŸÍ´ïþ韯é秬²Ûæž×¿ÏÜë¯Íêþ¿­óóå÷´–—ÓùéÝôÓ¯ú÷¹åÿõíïÛ´¦÷Ù÷þü­Î¹¼Ûݳ­æþÓ¬îͦÖúÿÎÓ­¦Ü––––½–¦š¾¾›ŸŸ¿¾—¦—š–ž¦—–ËÍ–¦šž›ù¬½½½½žËÏ·þÎí–íß¼ÙÏò;åß–¦ÞÖ¾óÓᄊÚÓòͽßé––¼Þžž—ž—ôŸÜÚ¾óÏò¾¶ÚÏïͽßé––¼Þž–ššî´ôÜïÙ®»Ù˦Ÿ››—››ù¬òìéóíéîÏò–¼û¦ç–ò¦ßìòòì¼Ù¾óÍͼûšë–òšêìòíéîÏò–¯ÜßïÙ®»û—¦—š–žû¬òìì¦ó¼û¦ç–ó–ßìòòìíé–öšî¼ûšë–óžêìòšßæîåíé––®×êËõé—–¹÷æŸÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯ºª¯úëÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯º«®ûêÞªëÿÿÿÿÿÿÕª­÷Ú¾šü󖧮üéúº½ò÷Öç·ýô÷ìο͹éíß÷½í§Ö¹²¹ïίúέåþòËγöîßòÏëóìööÏÛÓí¯çæúÖ·¼òßþËåòÚûçÿ¯Ë®Ÿ§–½¶Ù––––––Ù¬Ëôéš–¹÷柖½¶Ù–––––––––––Ù¬®Úì·þÎí–¾óÏò¾ê–îåß–¾óÏò¾æ¦îåß–¾óÏò¾êžî¾ó¾ó¾æšîõïËöß–¾ôÛ§¾ôß–šõó·ÏÚæ–®ûö½¶×–›Í–žž–͗Ξ–—¦¿—¿›¦ÏΟ˽—–›—˽›¦šÏ›–×˵¹ÝÙ´šú÷·ÏÚæ–«íùî›Ù®»Ù˦Ÿ››—››ù¬¼û¹÷–¼Ý–Î˦Ÿ›¾¾›ŸŸï¬õüËõé—–¹÷柖¾ó×®¾óÙ³–½¶þž——›—šû¬¾ó×®¾ô·ÿ–žûþ–ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯º«¯ûëÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯º®ªþîÞªëÿÿÿÿÿÿÕª­šù´ÙëýúÜÞ–ÝÖþõóëËÏîÜÿÏæýÙóÜ­éۧ߯éîíÚ««–­õ¿ûÖŸÎ쯫ÛõÞöå×–Ëùï–ßÖßë¹ê›šëýŸÛµì®÷³ó殫ÏþÎí–¼ÿÍž——¾½½¿¦Ÿ——½·ÙÓï;å閫ܯז¼Ýž–¦¦Íߟž›Ëõé—–¹÷柖½¶Ù––––––Ù¬šŸ½·ÙÓï;å閫ܧۖŸ²§½åüÜþ¶–¼Û–ŸÎ¾›Ÿ–—ÎÍžî«š­î›Ù®»û—¦—š–žû¬¼û¹÷–¼Ý–ξ—;›ŸŸï­Ÿ¯Ëôéš–¹÷柖¾ó×®¾óÙ³–½¶÷——¦¦š›——šû¬¾ó×®¾ô·ÿ–¯Î´½¶ç·——¦ÎÏ––ÎÓþËÜ–ÜË׿ûËÜžÖË×ÏÿË¿ÙÓïÍÍîåíé––¼ûùº–«Ë¶îîÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯º®«þïÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯º¯ªÿîÞªëÿÿÿÿÿÿÕª­Ë¦§®–Ÿ¿ÖúôùÏæé«ûûûæîåê廧–¬Ÿ®ÖšÎÍžÛ¶ëžËÖí··îµíûÚõËêúÞúò¼ê¶­¬›ŸšËëôùíËæÞžþöÏÿ­êŸ½®§®®»«îÙ®»û—¦—š–žû¬¼û¹÷–¼Ý–ξ—;›ŸŸï¯½ºËôéš–¹÷柖¾ó×®¾óÙ³–½¶ÿ—Ÿ¦¦—šû˵¾ó×®¾ô·ÿ–½¶Ù––––Ù˵ž¶¼·þÍî–¼ÿΗŸ¦¾½½¿¦Ÿ—ïŸÍ¿Ëôéš–¹÷柖½¶Ù––––––Ù¬½Í½·ÙÓï;å閫ܺù–²µÓËöß–¾ó×®¾óÙ³–½¶Ö–––––šÎŸ›–›š¾ÎŸËΗŸ¦¾š–––––­–笼û§Û–®ê×Ëöß–¾ó×®¾óÙ³–½¶Ö–––––šÎŸ›–›š¾ÎŸËÍž——¾š––––æÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯º¯«ÿïÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯º®®þêÞªëÿÿÿÿÿÿÕª­«õüù÷»ÍÙ¾¯ôÚ­¦ëûùÙˬÿöû«¼þËå¬Û®òßü¹Ú÷Þòõô¯¿öºùÚüËÞÙý¯¿ë›ÝìóÝûºÚ®Þ²ô×û¼ëöÚÿùï«®ží½ß­›æ­–笿þÛËöß–¾ó×®¾ô·ÿ–¾¹×´ò»ôé––½½¹ÏûšËÏžŸÎΦŸŸ¿ÎŸËË›š›¾½›–Ÿ¦›žÍ½›¦š¾Ü›ûÙ´½»üÙ®¾åé–«Üžå–½æÙ¿Ýé–§Ûé–Ͷüü›ÜŸæ–ŸÖݽæÙ¿Ýé–§Ûé–Ͷùù›Ü§Û–žé嶶·ÏÚæ–·þžß–šé÷»–¹¹¶ùç½½¹÷é––½æÙ—Ëٖͦ–ŸËŸÙ˵òìíé––ïëîé—–¼ú½ô–½çÙµ¾ó×®¾ô·ÿ–¼úÎí–¾ååæõåß–»»´þë¼û¾ô–½çÙµ¾ó×®¾ô·ÿ–¹ùé—–½¶¬ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯º®¯þëÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯º¯®ÿêÞªëÿÿÿÿÿÿÕª­í´é®ééÖ¹«¦­·Ó¾ëº÷ìÝÛüŸû综–êç›ÿúÚî–î›íòµî›Ùï·šÖµïÚ­Þš»Í–ÿú­êÞùì¿ÿβۖÞÿöæÚ§²é·­ï×÷¾«—Ý––––––¾žŸ¦ÓŸÙ˵òìíé––ïëíé––¼ûÍí–»»µ×íï뼚×鴮ͽæôç®Ö«ÜÍí–¾¹×´ò»ôé––½æöå³Ú«ÜÓò–ïëëõß–é–½æôóóôóóûÜÍí–òìëï§ûò¹÷åž–½çÙËÙ–––––––––––––––––Ù¬»»§ýô¾ó×®¾óÙ³–¹÷åž–½¶û––—žŸŸÎ¦¦Ù˵»»›û÷½ç¦îî–ýÓ»›ùú½çšóîž÷Ó»¦úý·ÏÚæ–½å›Ù¿Ýé–§Ûé–Ͷûû›µ½®òÿ½¶÷—¦žž—ÎÙËÖ›Ù—ËÙ¾›ŸŸ¿½›š¾ßÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯º¯¯ÿëÞªëÿÿÿÿÿÿÕª­––––––––––––—––››——šš––››——š›–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––Ÿžžžžžž¦—––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯»ªªúïÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯»ª«úîÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯»«ªûïÞªëÿÿÿÿÿÿÕª­´žÝµüëÓ×½Íï¶Ïݶåôüïú–÷ï·íÎήé¹Ó¿ßüÙŸÞë×ûÝîÚéì—ùÍÜ›çÚÏê¹ÜÜ­ë­÷¿çܴ֯ìÿÜš§ê³ûõÖŸú¦÷×Ïõ¬æ߬¬çÎõ×ëÜíûëÛÓóßßÛçý–¾½òŸ¹–––õç¼í——ûÝô·ëý·»žê¯®³ž¬ŸŸé–§Ùæßß溽·óÞ·óïõùºßéÚé´òïÏÚé¼ó·Ï¯§ÙæßßìËó®²íúéÜçæóþšŸ²éßéçìÚéµïÛÞ­ÙæßߧŸ²ÛÜçæóöéÍò×ÙéÍò×ÜëæÚµï§Þì½û¶îç¾ïÙ—µïææßßÛçó«ïç¾ïò–òüÿéËó–û­óìËóïúéÛŸÏïåÛ·óææßæÝçÛ¾ïï»çÖÍòßßÛçÖÍòï»çýÎËóï»çýÎËóÛçÞçé¿ôÛç¦í÷§þõ–ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯»««ûîÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯»ª®úëÞªëÿÿÿÿÿÿÕª­––››šš—–šššš—–›——–š—››š—››–—–š––š—–š—››š—›—–—–——––––––––––––––––––––––––––––––––––––––§ÜêÛÛ½ò¿îö›ó·—¶Ú¶îÚµïÚµï§í÷×ëëë¼ò¿îç¾ïç¾ï½ïš––é–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯»ª¯úêÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯»«®ûëÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯»«¯ûêÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯»®ªþïÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯»®«þîÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯»¯ªÿïÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯»¯«ÿîÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯»®®þëÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯»®¯þêÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯»¯®ÿëÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯»¯¯ÿêÞªëÿÿÿÿÿÿÕª­––––––––––––›šš—š–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––Ÿžžž›––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®¾ªªûêÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®¾ª«ûëÞªëÿÿÿÿÿÿÕª­§§ž³—§³—­šš­–§šš—¯¯—š³¦›§­–ž§ŸŸ§«²—¬—š›–š––››––›—–šš–—š——šš›–š––›–š›–š––š›š›››–š——–šš·¾Í–žž–ÍÍž–—¦ËŸ–ìå––ŸÓ›Ë«§­ÚÖÚµüš—¯¬«Ù×éé––´¾«²¯ÚÖÚµüš—¯³®Ù×éé––´·Ù×éé––üóŸÓ›Ë«»ºÚÖÚµüš—¯¼¹Ù×éé––´üé––µ›Ë«ÎÏÚÖÚµüš—¯ÏÎÙ×éé––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®¾«ªúêÞªëÿÿÿÿÿÿÕª­µš–¦®§ššššžž¯®–´–¹´½§´´½÷ÍÖ÷§÷ßüÛß®¾Ë¦¹«ßܹÛíÖ–ÖšîÖ››½›¬š–ÖÖ––×ךٺžý®×ÖÖ´·ÖÚ¶Ú·—¯­–›š–ÙÙ«­–šéÝ–––––––––––––––––––––––¬´¶¦žéÝš––––––¾›ŸŸ¿½›¦šÏ–––––š¬½¿ž¦éÝš––––½›¦ššŸ››¦Î½ŸÏ––––š¬ÓΧ¬éÝš–½–¦š¾½›–¦—–žÓ¾—›Ë›š¬Þܲ®éÝš––––––––š–š––––––––š¬ë鯳éÝ–––––––––––––––––––––––¬öô·µëÝ«µ›–›—¾½›¦šÎ½›šÏŸÙÛ–½¾žÍÍ®›—»¹ÜçÖÝ–––––½–¦š¾¾›ŸŸ¿¾—¦—š–ž¦—–·ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®¾««úëÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®¾ª®ûîÞªëÿÿÿÿÿÿÕª­½®ž¶ÛÏì¹û½Ö¹Û¯ûΦžÍÿË׶¹ÿ×¾ÓåþŸ¾º¼ýÞ«»ÍŸ¯ž–¶Üô»üúŸ¬Ï¼®§¼¦²­š¦—ͬ®¼º²«µË—«¾š¦­§–­­­—Í–¦šž›ËŸÖÖÖ맬¹»Úë——›Ï֮聯š÷þ—¯³¯Ë¾ëÚ——Ÿò–Ÿ÷þšÙüžž—ž—º»¹¾ËëÚ——Ÿò–Ÿ÷þšÙüž–ššµÝÛÙÖ¶Ëýü–˦Ÿ››—››ËŸÎÞÛ¿ÏÛù—š–ÙÖ––šÎ¦ÖÞÎÎޮ聯–ŸÙÖ––šÎšÜÞÎÏÛù——¯òîÚ׶Ëýü¾—¦—š–ž¾ŸÎÞÞ¦¿ÙÖ––š¿–ÖÞÎÎÞ÷þךÓÙÖ––š¿žÜÞ·ôöæßµ×÷®—›æßßÜ›çå—›ÖÝ––––––––ŸÝÝ–çå—›ÖÝ––––––––––§ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®¾ª¯ûïÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®¾«®úîÞªëÿÿÿÿÿÿÕª­´¹óµÜ›þÚú´ö³Ûµ³ýåýçûÍïû³®¼µ«š®²žþ¦Þéöê×®úççîÓ«¬ôóõݧ¹«´ô—ì«ëì¯çíÝò®ýÙ¹Üþ¾þ¼»Ó쿼·¹®¾¹®–––§®²çåÚë——›ÖÚ——ŸÓ–Ýþ—›ÖÚ—šž½¦Ýþ—›ÖÚ—šžÓžÓÖÚ—–¦½šµ¶´ßæßÛ—›ÖÙ—Ÿ¦—›êµüš—¯º¼åçÜçÖÙ––¦¦®Ú×ìêëÝ›–›Í–žž–͗Ξ–—¦¿—¿›¦ÏΟ˽—–›—˽›¦šÏ›–›Ÿ–ìå––ŸÍË«ÛÝéëÜÜëéêìµ›Ëýü–˦Ÿ››—››ËŸÙÖ——šÙÛ¾–Î˦Ÿ›¾¾›ŸŸ¶ôöïíßÜ›çå—›ååÖÝÍž——›—š¾ŸåÞûùíïÚë——›ÙÛ–Íž——¾½½¿¦Ÿ—¶š–õóç·ï¦—–Ÿþ÷ýýššš²ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®¾«¯úïÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®¾®ªÿêÞªëÿÿÿÿÿÿÕª­ýž¬çÍš»ì¬óö׻ΦçÖ´ù¾ÖÖù´®ßÛ¹å§ö˾¼«—οŸŸº¦š–¦š—š›¯®Î˧ò÷«êþÿ÷¾›Óúÿ–«º›ÛËÍéûÚíîµÙ맬ÙÛ¾ž–¦¦Í§­«ú÷ßÜ›çå—›ÖÝ––––––––ŸÜ·ï¦—–Ÿþ÷ýýšš®µ·ûùçúÛý—–›ÙÛË–ŸÎ¾›Ÿ–—ÎÍžµË¾þüµ›Ëýü¾—¦—š–ž¾ŸÙÖ——šÙÛ¾–ξ—;›ŸŸ¶ÏÍÿýå›Ý—–¯ÝÛÿýßÝ–çå—›ååÖÝ¿——¦¦š›——š¾ŸåÞîòüþëÝ«·——¦ÎÏ––ÎÓÍŸ¿–¿Ÿ›¿¾Ÿ¿žÓŸ›ÏΟõ聯—¦Ó×÷®÷úüþßÝ–çå—›ÖÝ–––––––––––––§ýÿýÿëÙ–—Ÿ¦šÖÙ––¦¦®ÿýýÿæÝ—–¯«¬›ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®¾®«ÿëÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®¾¯ªþêÞªëÿÿÿÿÿÿÕª­¼³§Ëç÷ùî¿ëß²ýýúÙÿÛÜÚ¶žž–—¦×šÖ–ÙÙóÛŸº¹³Öüó뼞ž–«ž§–§–¶ÙÿõïÓÝÝšïÿËó®×§Í®žž¬šé²æ¼×šîíî´›÷ÿµ›Ëýü¾—¦—š–ž¾ŸÙÖ——šÙÛ¾–ξ—;›ŸŸ¶¶µ›–ßÝ–çå—›ååÖÝΗŸ¦¦—š¾Ÿ–ååÖÝ–––––§½Ëš—Úë—–šÙۖΗŸ¦¾½½¿¦Ÿ—¶ÎÏ—šßÝ–çå—›ÖÝ––––––––§Ù×–›ç·ï¦—–Ÿþ¦ÿýýšš®ÞÛ¦ç·ïŸ––Ÿþ÷—–üÎéòퟞßÛš–ååÖÝš–––––šÎŸ›–›š¾ÎŸËΗŸ¦¾š–––––­–«ŸÛÝšš®þýžŸßÛš–ååÖÝš–––––šÎŸ›–›š¾ÎŸËÍž——¾š–––––­–«§µ¶­§ßßÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®¾¯«þëÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®¾®®ÿîÞªëÿÿÿÿÿÿÕª­¶§³ÞÚò÷§ç￵÷§î½í×Ü«ÚÚÝôÎæ·ž¯ÚÖíÿ­¿¹ž«¿š³Ÿ³–²³ºöíûïÎÏë׶¯ìîӬϬ»í®ÿÓüÛº¦«ù¹ï½ÏÝ–þßõ¯¦­¯š–ååÖÍþ———›ž¦šÖÖì徚ËÏžŸÎΦŸŸ¿ÎŸËË›š›¾½›–Ÿ¦›žÍ½›¦š¾¦ŸÍ˦ܷï½Ë›þ÷ýý––®»º¬«çµí½Ëš¦ŸþüÏÏùý——®ÍÓ§­çµí½Ëš¦Ÿþ¦ûËËùýšš®×Ù³®Ùéççêë–—šìé—¦Ÿ—šëÖì鲯ëÖçåšÖü˦Ÿ––ͦ–ŸËŸ–Ÿ–ÎÞ÷šÍÝù›ÙÖ——šÖýΖååçå–šÙÖ––šÙéüÿ·´éÖ——šÖýΖååçß›ÖÝ–––––––¾žŸ¦ÓŸ–Ÿ–ÎÞ÷šÍÝ÷šÙÖ––šÙ鲯µ¶¶Ý®ï÷þ——š›¯ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®¾®¯ÿïÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®¾¯®þîÞªëÿÿÿÿÿÿÕª­šËÞêýÛòܽڮ¦ºË¹§›þÙêÖü—òž³Ù뻲ÿ¦ÖÜúìÚº¹×ïß­žîï—Ù–Ú´·´·µ´×·òÚïŸîüß½ÿ¶²ÎÖíîòîÚ¶Ÿæϳòßí´«›ÜùÝ÷–šÿý––šÖÍþ———›ž¦šÜùÝ÷——ýý——šÍÝÝÖþ—–›ÜùÝÞÖ×××Úý––šÎÞݶ¹¼´·ëÍþ———›ž¦šÜùÝ÷——ýý——®Ë½¼¹¶ÝÝÖþ—–›ÜùÝÞÖ×××Úý––®Îϼ¹·ÞݶÜÝ»ºÜå–šÖýΟ–––––––––––––––––––ŸÙééì¹¼Þåçå–šÖݾ––—žŸŸÎ¦¦–Ÿ–Ùéì龿ç÷¦Ö¦Þ–ÜÎéòíÓÍç÷šÜ¦ÞžÖÎé÷ûÏÎÜçܵí˛˚¦Ÿþü¾¾ùÓ럞ÍÓëÝ¿—¦žž—ΖŸÓ›Ë¦Ÿ–¾›ŸŸ¿½›·ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®¾¯¯þïÞªëÿÿÿÿÿÿÕª­–––––––––––––——šš––››——šš––››–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––¦žžžžžžžžŸ—––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®¿ªªûëÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®¿ª«ûêÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®¿«ªúëÞªëÿÿÿÿÿÿÕª­Ö¯­é´ë·Ü›½´ÿó«Ö«Ú§×´»ÝÛ²æÖ›¬¿ùÖ×꧞Ù×­›ç–žêµµîíÚßÞÖ·íµÛ´´ï妲ŸÝÓ«¦ýžï«»ž«—å¾ú«Ö«×ÚåÖ릗šîîçÎõÚÞßßìûç¿Ûòõúºç÷¬×ìþææêÓíÞ¬êïõùôÚçæçÖš¬òòòûŸŸŸÏÙìôíçÝý«ìÞü–ΟŸ«šæך¬²²—µÙìôíæìó·éÿןŸŸ³ßé­¯½Ï­ÜíÏ­þþŸŸºÏ­þî««Ù²í»ë÷ŸÏ­³ßš½Ë½þŸŸ›Ûùϲ²ÏµÍôí»Ë¶Ý×åü–´­çÎÚÏ­Ú¹ÙÏ­ËòýÏ­¯½Ï­ŸŸŸ¦¼Î´üéÝß–²­ôÍÞïú¾Ëº»›ŸúåËôýÓúÛ›ŸýŸÍÓÿ¦®²ý¿×êÛéå¬ÜÓþŸŸ›Ûùϲ²²²³ß½å—›–¶š«æ××ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®¿««úêÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®¿ª®ûïÞªëÿÿÿÿÿÿÕª­é»ýý®ÍôžÛ®ÞËü÷Ïå¶ïË÷í´ê¯–íÓÚ«¯šŸ«¬¯š²®¦¦²¯–—«­š—¯–¦³®››šŸ¯›³«««–››§«­«¯³›«—«¦¯²›²ÜŸ³íû¦®õý³æ×êÛéßßêöÿ›­õþ–§õþ–¼²–óÛé宫—®ÓË«–åì´þ§ÚçÙ»«³Ïš¶þíúóý«Úç»üöéÞæ×éžïúËôëåßÖéÛßÖéžïú§Ùæ²ÞòÚ¦ÓŸ²òÚ¦ÓŸ³»õëÝúïëÝßß궿þþæÙž¯æÙöÿôÙ²¦·ß§›óÛõêŸçê¾þšùݼê¾þšù›õêËôëËóìËóì¾é——­§××¼½Ó¶ê¿õõüû··¿¾×Ûš–––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®¿ª¯ûîÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®¿«®úïÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®¿«¯úîÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®¿®ªÿëÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®¿®«ÿêÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®¿¯ªþëÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®¿¯«þêÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®¿®®ÿïÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®¿®¯ÿîÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®¿¯®þïÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ®¿¯¯þîÞªëÿÿÿÿÿÿÕª­––––––––––––š››–š–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––¦›––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯¾ªªúêÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯¾ª«úëÞªëÿÿÿÿÿÿÕª­¿´–Íÿ››¦Þìýù«êê­««ïÏÜ›­–³®§¼¼üÿÖ§÷ç¾åß²¦æ·Í²š½¿¿óÞ´µïû×ßæÖ¬šÍ»»¹Ÿîíçßæçý»íòç¾¹¦Ö²ßžé¯æ­­››òò­­››òò­­Íõý›ËŸ³ßææן¬¦÷–––½«ï»Ëýí»Ü²ß¯ËӦ˻˦«õüµ²·ôçÝ߯Ëúݳ·–²ýòùöü·Ùµ¯Ë×Ü»Ýì–ò¿×ûû¬š–ò¿×ûû¯Ÿæßåܯ­ÝúíÞôÝûÖŸ¯›óÞúן»çÚÚÖúéêåü¦û««åçæÛ›žÝú¼í÷ŸŸ§–òû««§—ß׫««¿ú–åºó·ï–«ßå—ÍÎËË—¹ºžßßž§«¬²ž§«—–§Ÿ²–§«Ö¯Ûº›Óß²Ù­Ÿ§´ÏŸ«¿Ï­Ÿ§´µ«§–²Ÿ§´µ«Ÿ²²Ÿ­·´§Ÿ²—¬²­››ž»¬¶éÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯¾«ªûêÞªëÿÿÿÿÿÿÕª­›ÖןÞæû–´ÖÖßßíÍéíÖÖÓß›·û¹Ú禵ŸÍ®®–®ÍÍ´½½´–¹ÙÖÖ×µšÞÝ»ßß­­·íï׵鳛–×֧ߗÝÝ–´¾í®ßýþÝÏšÿý««ýÿéÚ–––––––––––––ËžšŸŸ›—žË–––––––––––––––³³¯›–ÚéççååÛÝ—–¯º¼ŸžºÎýü——ŸÙÖ–šššÝÛšÙÖ–šš®ÛݦåÛšÖÝ——Ÿ–çå–šÖݽ–¦šž¦šÎÍžšŸŸ›—žÍŸ–çß—šÖÝ——ŸÝÜ›ÙÖ–šš®óõ­§åÜ›ÖÝ——Ÿ–çß›Öݽ›¦ššŸ››¦Î½–¦š¾½›–¦—–žÓ¾—›Ë›š››ŸŸ–çß—šÖÝ——§ûù«¬åÜ›ÙÖ–šššÝÜ›ÙÖ–šššååÛÝ–––®š–®³×íÛ÷üüš–ÖúΦ–²ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯¾««ûëÞªëÿÿÿÿÿÿÕª­›Ü¹ÖíÛµÎÚçÝÛ³²å½ÏÎÎêçåêßëë´¶§ÞµµµÍ¹ßúåêêÙêÏïÏ»¬îõÝ×þ–Ó­æ´î˦·ºÙ¾¾ô´–Ï¿Úµ¶´½¹Íµ¿ËÚÞݟכ›²–§§––§­Ù¯Û«ß鞯›º½Ï¬²îܾ¹–ßߺù›Ö²ß¾þ››¯½½æ¾î®›ŸŸŸ«ÍŸ¿ßéôÜü·ö«í÷§–òû§ÞÞ²ÎúÚ¯³§²ÎúÚ®²«ß§Û¯ž¯Ë½Ï«¯îܽέšß§–åÎù›ëßå›òí¯¯›½½æ¾í¯¯§§§§Î–ϵ¿µ½çåæÜš–Þ–ïõúÓ³Ÿß׳ý§åæ´›óö¿éõקïï–¬ÓºÙõ¹Îýå«ïû«§ôê¿šóÛº»ûêêåü¦û«§š¶Öú¼º§žºÚù»¹§ôÿ»¹§óþ»¹«ßåôßóîééêôšÓóîÎ簾³÷ôíß¿šòÚùÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯¾ª®úîÞªëÿÿÿÿÿÿÕª­—Ë­§ú쯭ë«ÿç¾å­ÿü²ÓÚ¬ßý®å÷ÝËžòïšÍ»óÎ÷´¹–ÖÖ³·ì§Þ³¼—½Íó¹šòòÖõÖÖî›æú–îôû—çÎÚùý§ó–®¯ÚõÞû¶­ÖíÏÖúΦÙ馞¶µÛåšÖúΦ–çß—šÖúΦÙéµ·µ¶ìÖÖÖÖÝÍžšŸŸ›—žÍ––šË––—žŸŸÎΞ›ŸžÏš§ÎÓ¼¹ìÖÖÝ——Ϧ›Ÿ–—ΖËÓÏξ—›½–ËÓÏÎÓÍËÓÏο¾ž—š––¾Ó§×Ú¿¾ìÖÖÝËšžž–¾§æß½ËìÖÖÝ—Ë¿––Í—–ÎÍ–¦šž›ËË–Ë¿—–š¾§òîÓÍìÝ—¿Ë––Ëšžž–¾ÎŸËÍ–¦šž›ËË–Ë¿—–š¾§ôöÎÏåÛ–šÖëÿýÖÚìÝÍ–žž–͗Ξ–—¦¿—Ο˽›–Ÿ¦—Ÿ¿––›Ÿ²—›šÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯¾ª¯úïÞªëÿÿÿÿÿÿÕª­®ê³žÜÚ쯯é®ÙþõŸÝŸû¾¬ßš¬îòÖ¦ì–üüžôÎ×ëå¶ç»¾êëÏ´›åÝϧæ²Û纻¶×žÛí¶«¬êþß­Íο½¹¿ìæܲÛõﴽ߮æ§Íµí›¿×¬¬ûòò–¿×¯¯ûïßææÛýûÝú»í´×§ïï–¬ÓºÙõ¹Î—òÞôôóÞúîçÚÚõêåü¦û«§ííòû«««–ßé¹ý秲û›î§—«îù—«îûϹ–ëÛϹ–ëÝôýëÝóüëÞߧ›ó¹Ï¹–ýöϹ–ü·ÜÓºËú׫›Ï¹Ëú׫ëìšï¬ûòžô¯ûíæÚ¼ºš»¹§í÷«—òû«ëëßé¹ûìåòÏͬ®¹ÿîššßÛ®——ï¿ï»®««««®·Û¬ù§ßק§­–çßÖÚŸÖÜ›­­›–ç­ÚŸÜ­­ÚŸÛµí§§–›òò­­ŸåÞß«¿¾ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯¾«®ûîÞªëÿÿÿÿÿÿÕª­Ü—ôöõ´—ή»ËÜõ¬æõö­é½óêéµþÿ嶶š¹ý×έõü¹Ù÷ýùßöÙ½ÜÛÙ¦ÖÞ››´¦Úûº»åÿõ­Ù·¶æü²úí²ÿôÍîÓ鲟¼Î¯×Üëÿ¾«ž¦ÜÝæ¶ò¿¾›þ÷ýµÖ¬§çßæ¶ò¿¾›þ¦ÿ–ýý–——®º¼ëêÛçÖÏý¦šÍžšŸŸ›—žÍ¿ŸÍ¿—¦—ž›–š–¾½›š¾Íž——¦Ï§×ÚéìåÝ–ÖÝ¿›¾ÏžŸÎΗž¾—½žÎš›—Ë–—šš¿š›Ë¦Í—¿›Ÿ¦›—šžÎ—§éëòíìÖÖÝ––ÏžŸÎΦ—–Ë¿šž¾ÎŸËÍž¿Ó—ŸËÍžšŸŸ›—žÍ§ïíîïì¼ò¦¦šË›Ÿ¦›—šžÍ§÷úŸ¯ÜÛ¾šËË–ŸÎ½šš›š–¾––––®ÿý³æË–Ÿ÷¬ïŸ––Ÿ÷þ—–ÿþ–®––¯¯ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯¾«¯ûïÞªëÿÿÿÿÿÿÕª­›å«åŸõú¿ÝéºîÜ´¾ïݹóüºº¹ÛßÝÖ¬«Þ¹ÓöüìûíšžŸ³¯§—ëξžž¶¿ëéûöÛ®žÜü¹Ûßûô¯ž×žÙ¿ïÛÝýôæËÿÏߧ§–›í¿×­Ÿê«Û¯ž»æš–ïÎÝû««ßéžË½Ÿž§§§§žžî×´Îóù·›–½êô›·ÛùÜË–ïü¦û«ùù­›—«§––§­šßéž÷õ·ôòÏž÷õËù›ì–òËÖ§¯Ûù·šßéžË¯­›­þíÏž§ŸºÏž§Ÿ²›ïîòû«—òû§–›éæùõ·ôòÏùõË÷ê—ïËÖ«®Ûù´—ß鿯­›ìõë×òÖíÙßòÜÏ÷ÛÚº³ºóû¹²¬ç–ïüÙê³óõšó²é½µžŸ›í¬—Ÿ›Ïî–––Ÿì—îî««—–ížêò®¿Üå׿û«§²³ßóÎË˲˺ž—›ëÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯¾®ªþêÞªëÿÿÿÿÿÿÕª­½´Ÿ®í×Îõë³³¦›§–®²²²¬«›ž³š¬«›ŸŸ–²¯¦›«¬š¬¬š§¬««›­¦šž¬šš¬««¬¬šš«§—§§­«ž–²²³³ž¯²Ÿ¦²¬Ë­÷óìöÎÝëëëÝö¿×ë«Í½ÚëÞ²¬Úûßßö¯ßÍû矴ºó¦½Úü·ÞôýîòÏý×îùóüîæ÷ÚüþÏý×îùùÛóî×××ùÝûóîþþþÝÝþþÝÝõõÞßéêêÚçóþúÚËÚçóúùíÏýßßéü½çμÙûíóíßü»ÍÏ–ŸÍŸ¿ÎÝýÛóõß¼«îîùù¬¿×îÏó÷ùŸýó¦¿åïîììåæÚóºß¼Ïóº®Î—µ´—Þ³––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––úÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯¾®«þëÞªëÿÿÿÿÿÿÕª­ÙÓú¼ßµÙ¿ì–æõ­×¬®–«þ­Û·ëÿíšÚ­Ü¼æöµ¯Ó¼¶ýÍÛìÝïËÍéÓ«®®ÚÖöüæ­ú«üŸúÝÛ¶«ùÙÙú§¬òËš×ާ쭛æîµåš—¶–ËÍ–¦šž›Ë¿—ËËšš–¦šôí–ËË——šžÍ¿—ËÍ›š–ïî—›žšššŸÎΟ–ËË›ž–ïï—¦—š–ž¾Ë——š¾ËŸŸ›—ž–öퟖÎËš¾Ëšš–¦šôö–¦šž›ËË–Ë¿—–š¿›Î—ž¾–—¿Ë–ΟËÍž—›Ÿžöî—–š¾¾›—š¾¿—ËΗžïí———¦–¾Ëšš–¦šÎ›Ë›ŸÏ¾–ž——¦žÏÍ–¦šž›Ë––––½›–Ÿ¦—Ÿ¾šÍν¾ž²ÙöšžŸžŸô馞—š––êí——š¾ÎŸ–ËË––šïî—›žšššŸÎ¦¦ìµ–²ýòïÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯¾¯ªÿêÞªëÿÿÿÿÿÿÕª­ßÖé¹Ë²ÜÙÙ§ùîùßÓéÙÚÞ›ž¶»´Üö¹ó®§´ú¯»ºíú§ÛÓÎËûͯöÝ×¹õ¼§½ôÛµ¶»Þλ–›Ó¹ßæîòÙš¦åõºÛÚþó«¯å®Û²­å¦¯¯³§¦¯®²åݳ·×Þó·Ëå«ßéôêôÚîû«­º¼ææßןŸŸŸŸŸ««««««««§×ݳžëõåÞÖÝó·÷¬·ÙÛö´û«åݳ·ùÿí®Û¯«ßöž·Îÿîõú§¶ÍýåËÖû«›ÖßÙÛ¯ÎýÜÝíùÿ«ºß×­»ý«üº§–®š²›³šÓŸ¿ÜåÎÝû«­Ï¾—ååÍôå·ßû««ßêóü®ËõúÓ­šßéžË›»­žË­µý¾¯Ûº³·ê»û««ß×­šßéž««Ëú—ßµíü—¹—§«×—ߧ–««×—ßå¯ÛÎö¯ì—îî««—–ížêò®¿Üå׿û«§²ÞÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯¾¯«ÿëÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯¾®®þîÞªëÿÿÿÿÿÿÕª­Ö«ìéõ»¼­®¿¾ûô³šÙÝÝéüù—¶×¯¯­«¦îîîöî󼵺´Íþ¿ÓÜܵöô–ó–šõíò«²¦ôº¾®Ö³·þÞ«þõ›Ú§§ó›»¯ÓºýµÛÙßóÎË˲˺ž—›ëžåê»û««ßæºÓ«×—ß­ºÓ«×—ߧí÷§–òû§—ß×­Ÿž§ŸºÏž§Ÿì»ÿ¯ìçß×­Ù»ÿžÜåÝÎû«å¯ÛºšÓ–§§–›­§–íú¯³§òù®²§òû«—òû§Îöò­ÓÜåÓÛû«åÛ¯åÛ¯­Ïó·ºÝßÛ¯åÛ¯«å«Û¯·²¶»¬ïùºåõ¶ÎýòõúïõïÛ¯¯ºîüº§–§Ÿ²›­Ÿì¦ë«ß×­­­­­šçšÝëë¾¼›òò­­››òò­­››òò­­Íõý›ËŸ³ßææן¬¦÷–––½«ï»Ëþò»ºŸó·³ü¯¦Ë»Ë¦«õòÏåÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯¾®¯þïÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯¾¯®ÿîÞªëÿÿÿÿÿÿÕª­¶¬ö¦ÛÏšù÷˽¬Ëµú§››ÖÝõ÷–Ö–¶¦õ³ëÏÏËËÞö›î–ï»æþ¾«®éëÓ«¼öîµí—µ½š–ÖæöÓί¬½´ýý›³ÝÛÖÜóힴ믗é²Þ·óﲦòݳ·–²ýòùöü·í›¶²­Ûû§§¼ùçí÷š¿¹®¯¶Ÿ—µêåü¦û«Ëúéìç¯êקå­ü¯¬ü·ï–§–§Ÿ²–§«–ßî»»¾¬²­››—ÖÓþõ§êõç—￵­ÝýÞ¶²ŸõÞò›î««—ò›î«§–í÷§íî­¯³§òû§íî­®²ž×›Ö²ß¾í¯¯Ë½›–ò¿Û¯§§§§×Û¯åÛ¯­Ïó·ŸôßÛ¯–ŸìÛ¯–Ÿì¦ë«ßå²›¯Ë˲›¯ËúÛ¯ž¯Ë½»·çùºåõ¶ÎýòõúïõïÛ¯¯ºîüº§–§Ÿ²›­Ÿì¦ë«ß×­­­­­šçšÝëë¾¼›ò¾ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯¾¯¯ÿïÞªëÿÿÿÿÿÿÕª­––––––––––––—––››——šš––››——šš––››——šš–—–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––¦žžžžžžžžŸŸŸŸŸŸŸŸ¦¦¦–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯¿ªªúëÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯¿ª«úêÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯¿«ªûëÞªëÿÿÿÿÿÿÕª­¾öõÛýÜ뫶µÍÖÛéó´¹ÝÚïöêåܵÖü§ò¦üæËóÜûû¯ùëõé½öò»¿¬–î¦Ïæ´òÞ¼¦Ÿ›¹îïéꦻ²æ»ó®ÎÚ²ßó³ÞÓô­®žì¯åç›—–šå›Ý–––®ž¦¦žÙéçܬ§ž¦µ½ý¯ò¦¦ÙÛ½ž—¦½¿¾§´¶¬§¹—ŸŸ½ý¯òŸ—¦ÙÛÍ—ŸŸµ¾Ë­«´—š¿ý¯ò¦¦ÙÛ½–ž—žžÍ½—š–ËͦŸŸšµÙÖ§¬ßÛ–šååϾýü¾¦¦—ž–¦—š¾¾››¾ŸÙÖ–––šåÞÞܲ®ëÿ½—½—ŸË¾››¾§éë÷úéÛ½—šŸžÍÍ——Ÿ—š¾½¾«òîþüܵþŸ–þ÷ï￾›÷þŸ–Öþ¾¦ÙéùûõôåÛ–šÜ·ïŸ––Ÿþ¦þüËÝ–——®ŸóöìÝΦ–ŸÍÍ–¦šž›ËÍžž—¦¶ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯¿««ûêÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯¿ª®úïÞªëÿÿÿÿÿÿÕª­ž›ž›§–»»§®–¬¬ž­šš›—¬§š³š®®­§¯›Ÿ¬—§³š—›®«­Ÿ¬—¯ž¦š–—³—¯³—§›Ÿ«§¬¯›§¬ž®¬—Ÿ›š²§­š§—ž–³«š¦·žžÍΦšžÎΦ›¾¾›—š¾§µ·û÷ìÖÖú—ŸŸ½—¾››¾Í—ŸŸ½—–½—¾Í–žžžšŸÎË–ËΦ–ŸÍ¾›ŸŸ¿§¹»ùúìþ—š¿¦ëÖÓÎüÿìÝͦš—ž¾½›–¦—ŸŸÎΦ›¾¾š¦Í¦¦Í–¦šž›–——š¾§ßæššéÖÖÝË››Ÿž›Ë¾š¦Í¾ž–¦¦Í––í–Ÿ¬çå——éþ—š¿¦ëÖ––––ëë–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯¿ª¯úîÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯¿«®ûïÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯¿«¯ûîÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯¿®ªþëÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯¿®«þêÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯¿¯ªÿëÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯¿¯«ÿêÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯¿®®þïÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯¿®¯þîÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯¿¯®ÿïÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ¯¿¯¯ÿîÞªëÿÿÿÿÿÿÕª­––––––––––––›šš—š–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––¦›––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþºªªªïþÞªëÿÿÿÿÿÿÕª­¹®­¬­–õý¿­¯³šš«ìÚž²æÜì¶þ¼ôÙéÝ—ßòîÞúüæïͲž®³¦š¼úï¿®—š­Ÿ—›šššš—›ššš–›––—šššš—–›š›–šš›šš›žîš–š¶Úò–˾›—šžÍÍžšš—ž–´šÚŸ¿¾Ÿ–´ÚŸ¿Î—Ÿ¦¾Í–¦Ÿ—ž–¶Úî›—š¾Ë–›š›–¶Úᄑ˾ž–¦¦¼Úï—Ÿž›—›¾¾›—šš››šî×–·—¦—–›šš›šŸÎËšš–¦šÏΟËÍ—ŸËÍ–¦šž›´Úæ––––––––––––––––––––––––––––––––––––––««š––––––½–¦š¾Ó—Ͼ›—š¾¾–š–¦žžÍ––––––š««š–––––––––––––––––––––––––––––––––––ßÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþºªª«ïÿÞªëÿÿÿÿÿÿÕª­Ú×Ö–í¾–ž¶Þù͹§úŸ·éÚö»³Î­÷öΧº®Ë¶¶§­µ¶»¹«Ë»¯¶Ëµú¬Öý»¼–ë·ïö¹Úï¬Þêç×æß®·ô¬Î·ÎûßÎÎÝÚ«Û®®ììšÜžÙìÙ¯Þ߯êÞ¬–צÖÍíßææÚÎ÷²µÎìæ¦óòôó½´çÍöŸîöŸî¼å«ûîæå«ûîæë²ûۦ÷üì÷ç–ﶹöçë²ûî½–––––šíìåÛ²Ùû¾ëš²é²ÝÝ÷¹¼¯õ–üš´ë–ïš¹îÞ¬¹÷üßëë–ïµÓ½»¾¼éöê²õ§šÿÚÓß»Ÿ§­Ÿš²Ùé®ûîæì³û۹ç–ï¬ÿî—³ÏæŸîö²ùéóÛåß×Î÷²µÎëçÙÎ÷²µÎÍíê¯óþ¬²ùö²ùö²ù¼ìßï¾Úê²õõùëίçÚ×æÝÙšÛÝúºé›ÞÍùêé›ÞÚŸêçÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþºª«ªîþÞªëÿÿÿÿÿÿÕª­çû·š×óͬæìºÏÙ÷ΚÛ×ûò·òüîÜæõÓþ´¯é·­¶¬¯îüŸéÝýù½Ùí²ž«ß¹·êå÷çþÞÙ·»Úôúηùά²ÝÞÿß–º­þûþÎÜ×쫧šµ¼®¾·×Ÿ×ëæÚ§ìæ¯Û›®æÖ¬þóå–ìéꯛ«õõ¬´¿¬Ïº´Í¯¬óþ¬´¿¬½¶å—ëíôåç­ûžµ´—߬—üü¼¼êšÜÓóúûûý­®½´Ïå¼ê¯ûîµÞóßßìß›Ÿ–––Üì®õõ÷óÿö×××קí÷×××ק›³®ïùåæÚ«ëÍïæ×å–Ïå¼ê¯ûîæê¯ûî¬çͼßßì³ûîéžì®ò¼Ö–ûîÛÖÍ´ÖÙûîíšïõ®íçͼ֖û۹ç–ßߧ›«õ¿¯§ìÞ§ìÍ´ÏåºåÙßÙ–ìšÍ´ÖÙûîßæ×å–Ïå¹–ìé欛«õôçæÚÚÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþºª««îÿÞªëÿÿÿÿÿÿÕª­æºý§Íæ»çÿö¾´å÷¯õÙŸ¹«¯²ï矞þûýî·Ù÷¯¯æÖŸÏæûþùý´›Û篷›¿¿¿¬Úö½üæ½­«²»–·îïÍÓêú»Óž½§Íü«Î¼­›¯ÞÚŸÏïæÚÎ÷²µÎÍïæÚÚë¼ÏÚìêšÞö·éêšÞõ¶êæÚÜšÞÜšÍíçìéÚíºóÏéÚíºÏíçß÷ºÙÛï¾÷ºÙÛ½ò·üÞï¼ê·üÞï¼êÿ·ÛžÙÞÜšìþ¶ÛÚÞÜš¦žšíõߺÍÜšéß½íßßߧ®–ëæÚÚëïò®Úó¯«õ¬¿»³¯š–½ò¶ýÞï¼ê¶ýÞï¼ë¼µù´ÛÜšõÍù´ÛÜšõµÚ¦žš÷÷éß٬ߧ®–ëµæ¼ü—Ï×÷ýæ®Ú󯫖鷯š§³­ìÚìÞ¬Üö¶êÖ¯Üõ·êÍòÞï¼êÍòÞï¼ê¯ÙÞÜšì¯ÙÞÜšéßßßÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþºªª®ïúÞªëÿÿÿÿÿÿÕª­¶Üöìõ·õ¹çìßþ½ßÍô³Ý§ß¾ÿ¦¾Ûþš¾´ù¼²µ¹«Î¶öÜý󷹟ÓçüîöÏÍ´º­ÿܲÛæ¿«ý¹¿¦¯·¾¶úæ·îݵöÖ»ó²Ý´óžÛ—Þì÷îÜç­›«õüÙæò½ì÷õå§ì®Ÿ®ßæÚç®ìé›ÞÛ›ìÚ®ÞÛ›ííëæò½ì÷þק쮟®¬åÚ¿íߧûۦ÷óõåç–ïϧÜòͬÝæÖ–óþµÎ®§­Ùç®éߧûۦ÷óõåç–ïϧÜòϧÝæÖ–óþµº§­Ùۛʹçͼߧûۦ÷óõåç–ïϧÜòͬÝæÖ–óþµïÚ§­ÙÛ›éߧûۦ÷óõåç–ïϧÜòϧÝæÖ–óþµùߧ­ÙÛ›öó›íößé›öû®íôçºÍç®íôçæÚç®Ííê¯óþµêü¬çÍöçÍöçͺš–ìÖÞÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþºªª¯ïûÞªëÿÿÿÿÿÿÕª­÷ü¹åÞý–ýÍκš­¾×ßì¹²¿ó»»··ºž¼îÓÙÞîòîòëËËž®ž¾é³ÿ¬¾ÿÞ–¶—›¹Ûþþ––š­Ï¼¬úïÝì—Öí×ܦçËçýæö«›§®–ìÿ¶ÜžÙìþ·ÜžÙéßææíîýýîîýüÝï¶óŸ§ÓÚšéóž²·Üõ·ÙÛûê´Ïò®Úó¯«õ¬üíìêš÷ü½ò¶ýÞï¼ê¶ýÞï¼ýÍÚÿÍÚæù´—µ´ûû³ìÚìÞ¬ÜÜšÙîµêÖ¯ÜÜšÙîµëßßߧ®–ÿæ¼ê®Úö¹ÚíŸæòÍòÞï¼êÍòÞï¼éëÞÜšëæÚÜš®®–ͬóóííùÞ¬ô÷¯¬Ÿ®ëß³›¬óõú¿½¼³Öì¬ÞéºùÍõéïßß«í¯ï«òéÛÖÛÍííííšò³Öþ—¿ÞæÝßÖ–ß®ÛÜì¬ß®ÛÜì¬ïôš³¬ú˦ÖÞì¬ê¬×ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþºª«®îúÞªëÿÿÿÿÿÿÕª­¬×õÎ×–ÜßÏöµÚýÞùºžÜêºíÞϾ¯éú¿²Ýêºîåž®²¼¼Óšúåùºç럹µ«ì²Üݯ˽ë§æ²¹µË¶¯§«¶¶ž¦¬´æ÷Öîµ÷æÝ÷—¶µõõú»å«ûۯþú²ÿÚÛßìý§þ÷ÏšÓö–ü—¦¾­é鼯õ–üš¹æÚ«ëÞ«ëæë–ïηþíš¹²½¬¹ž—ßëë–ᄐ˖ïµõÎËôçºÍ«ëþ§—ËéÖέµ­ééßÚ­éì—ë÷óÖç­û۹ç–ï—³÷õ¬þ¬Ÿîö²ù駾ߺͫëéå«ûü¯¹¶ôË–«´—çÖË÷æ×ß—÷²»æ¬ûî½ûß—÷²Ýíæ¬ûüöçÍÞíç­ûüöçÍÞ¬óóíí´ßžºþÜÖëºþÜÖåßéêýý«ò¯Ÿ«Þííí횬ííóó¿Ÿîöûîæ¼¼¼ÿÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþºª«¯îûÞªëÿÿÿÿÿÿÕª­»ì¶¾¬µŸÞ´š´§×í¼Ûµî—×ÛÛïϲ¿¬÷®žî˛ͫ«µ—ÖÙ¦«Ííß–å峦¶ïÙ—×ùµ¬½šÎŸÜê·þצºûå—¼Ÿµ›ÚíôÍ­ó«³Ü߯ܦÖí·¯ß×Üš¼úê»ííóó÷æÚò»åÞ®Þé«åß›Þé«êêšÞò»êêšÞò»õíüüßßÚî¹ê¶ýì¶ý®þõÛÞåºÍÜšìù¹ÜÜš¼úêìÛ«ÜíºêÛ«ÜíºÍííí횬óóíí¿Ÿ¬ëæÚÍùëêç´÷ÙÛÙÝúõýôšæêåéݽ÷ÛÝúóëÞßæ¦óòýýÙÜš¼úê®›³Ïííííš´çÍöŸîöŸî¹êšõíõòìé®ûî«š¯–Ÿßß×Î÷²µÎëçÙÎ÷²µÎéëïùÿòôôåéíÿùõíôåéíýûíõôåéíòôíþùö¶Í÷õÙéÿçæ¬ûîåêš®§ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþºª®ªëþÞªëÿÿÿÿÿÿÕª­×åæïóß®¹»úîï›õ®³ºº×ξ§¾Î®íêµ½Íͧ¾î–õ¼îóúþùç¶ß¼þù÷ó¶Î§Þ糿ºóöôîßÛ¿ý§Ó¼ËÝÿ—»ºÿ­óÚí´º×º²ôŸ­Î»¬ÓßÚš–×—ò¯õúõ²ùö²ùÜííííš·³ó½ë²ûüöçÍÞí¼¯§§Öýì÷ýËêÍìí§ÛššòÚ®÷ü§Ü쬹Ïå®Úóíóô«æÖÝÛ½´ÝéÝÓòϺߗë÷þåÚ®÷íÜìµ—´¿íßßߧåÜìÿ¶Üö¶êþ·Üõ·éæÚÚÍòÿ¶ž»·ïó²»òÿ¶ÜÜšìþ·ÜÜšì·üÞï¼ê·üÞï¼ëßßߧ®–éæ×ÚšÏþ®éÍ¿Ú¬êÏÎÛ¬êÏ¿ÚÚçû¶ó¯­ó·«¾·¶ïó·«¾×í¿·½¾íŸé·«¾éú·Üæ¯çû¶ÜÜšçû¶ÜÜšçò¿ŸÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþºª®«ëÿÞªëÿÿÿÿÿÿÕª­ž¦²·üïÙòÙòÖîÚÙüÎ弯û»ý›—×Ö´Ö–´ÖÖíí¬¶Íöÿ¾ËÝæúü§½Í÷óíÖÚÓÍ››í¦¦ö»íù­¦¹´¬¬´´¹Û´ê›ë¶··–ÖË«õ«éÞóßé®ûîåé›Ù²ßڧ쮳žµ´—æ––––––––½½–ŸŸ¾›—š¾–––––––¼¼–¼¼–¼¼žÏ›½½½––ÎΖ–ßî›—šš››šÓŸÍÍÍ¿Ÿ§§–§§–§§–¼¼Î´¯¾²¼–§§–´´––ßôΖ¾–žÍËš—›Ÿž›Ÿ–ËÏ—¾–––ŸŸ–––¾¾››–ÎΞž–ŸŸ––—ž¾žÍ–––––½½––«¯–––—–––›–ëê›ëê————›ëééé——šë¾¿ååõõÝÝÚÚ¾¾ììééî¶¶¶··¶¶·§«¹¼´´Íͽ½ÞÞ××®¯üýÍ;¾¼»ÙÝÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþºª¯ªêþÞªëÿÿÿÿÿÿÕª­úþ›¦®Ÿóö¼µÍ·ó–ô«é´×¼ûüôïË˳Ÿ¦ÚÞ›ºÛþ«ìò—¼¾´Ïßõ®¶ïÙê²›ÎÎÚÚ«üž¿ÓÎÍÖ®ý›éÏö×å›®ŸÎùæÖ®«»ü²ëæ¯éßìú·Öé²þ§šöò«ôçͼå«ûîå—ë÷ó–·Û¹ç–ï—³òý¬úóŸ§þ¬Ÿîö²ù鼦çë²ûî½–š´ç͹–ìõšíìÙ¯²¶éíì®ÚõÎû¶¬¯çºÍ«ë¬»íì³ûîæë²ûîÏò›éÞ­éì›éÞ­é®úîß›éìšê®þôÞç×맗ݛéìšê®ôþÞì–×맞ٛéþ¾¬êÞ­éìšêÞ¬ê®þô§×맳캶šêõµ¬êìšêÖÎê¹²»ÏÏïš›šêõ´¹Ù¶úšÎ¬êÍ´¯Ÿìæåúµõη÷ïÙ¶ïõ÷¾­éõµ¬êí¯ÿÏ»»´¯ŸìæåúµÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþºª¯«êÿÞªëÿÿÿÿÿÿÕª­þ³Ú¶šïî´íÛéÿ³õëîùݲ«ýÍ߬óúÝÿéÏêÿÿÖíí›×î¶ï·›Ö–öÿÍüºÎôýåå¯êµîéæëßÛë»îîæ»×ê®ÛìÛ×ÚõÎÝÚÓ·­¯ææÿÿžž››®®­­¼¼µµÍÍÞÞ³³öö÷÷üüùùúúŸž¬¬¼¼ºº··Íͽ½ÞÞÞÞÞÞÞÞÞÞëëóóííééÙÙççÿÿûû烈——¾Í¦–Ÿ¿ìß–––––¾žŸ¦Ïìî–ž—¦—›ž¦—–Ëͦ–Ÿ¿ìß––––––––––¾žŸ¦Ïìî›—šš››šÏìï—¦žž—ξ›ŸŸ½ÏÏ—›–Í–žž–ͦϞӦΟËÍž–—¦´»ŸËË›š—ËËššŸÎ˦ͽ›žÏËŸ¦›žÍ¿›¦ÏΟ˽—–›—´ÚÚ·›¦ž——¦Ï¾¦Ÿ——Ó›­Úô›šž¾¿—˽½ËòÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþºª®®ëúÞªëÿÿÿÿÿÿÕª­¶íõ»§Ó§¾ÜÖßéúì–¾ëûÏÙßÖ󺫴–šºæþ¹­—ÙìÝí¹——–õ«ÎÜ×­¼Îï纺³ºÙõïÚòóæëžÙ­žýÖ¿¬¿þÞò¹îÚï»ú³Þ§úη÷ïÙ¶ïõíµ­éÝ—¬êí¯ÿÏ»»úíóóùšêì›éÿ·éíõêúµõηóüóéìí¿ê÷üéìåæÚ«ëšÙ×õ¿ê÷üéë߬›«ë¬Ùêç¿·«ë¬¹íííïò–ìŸß½ÍÍõ»í®Íõ»¬òÙ¯²æÍýåé®ûî¿ïçÙÎ÷²µÎéç­ûî¿·š¯§²ßçÙÎ÷²µÎéç­ûî¿·š¯–Ÿßß×Î÷²µÎéç­ûî¿ïçÙÎ÷²µÎÍïæÚ§ìéç­ûî¿ïåÖÎ÷²µÎéç­ûî¿š–íæ×å–ÏåéÞóææÚŸ×ÞŸ×ÞŸ×ÞžÙéßßߧåÜéߧ²žî—¶Þï«»²×®þ«¹çÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþºª®¯ëûÞªëÿÿÿÿÿÿÕª­þžÿåö¿š²µÿ½–þÜÙúΖßæšöÖ·þ¶³¬Ú¿ùÞïõçִ幦絭õÛúµ¯²¿ï»žûæìúӗ粟þòëË»ìò¾îÏ«ŸÎÜ·ëšÞüßž÷›­ùξ›—š¾Ë››š¾¾š¦ÍΦ›¾½›¦šÏ˦¼®Ëž–—¦Í¦ÎŸËÍžž¦›–—¾¾¦Ÿ—¦—š¾¾›—š¾Ë¦¼®Óž—¦½ËÓ–Ëž–—¦Í¦ÎŸË½–››—šË½›¦šº¯ë–îž–¦¦Ó›––½›š–ÏìÚ»ŸŸŸš¾ÏžŸÎË—–›¾ÎŸËË›š›¾½›–Ÿ¦›žÍ½›¦š¾¦ßÚµ—¦žž—ÎͦŸ——¾¾›ŸŸ¿½›š¾Í–žž–ͽ½¿›¦õÚµ—¦žž—ξ–ž—¦—›ž¦—–˾›ŸŸ¿½›š¾Í–žž–ͽ½¿›¦ÏßîšËÏžŸÎΞ›ŸÎÍ–¦–¦—¦—šÏ¦ßÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþºª¯®êúÞªëÿÿÿÿÿÿÕª­¬å³ô­Óëò¶›ÿÝûÞÜ›–µ¹¦—¦¼«Ûï³ÎÍßι×ÜÜßÏÍŸ×ÎÎê«Î»ööæóµ¯ë®§ÍºÎù¦åÓ¶š¼¿¯›ï¼ìŸ¯ú½–µô×Ö¦ÙšÜ×®þ«¼ë²ûîå¯Ù®þ«¹²×®þ«¼ì³ûî¿þó´–ßšßÙ§æŸÍþÛïߧÍéÛ÷šù›éæËþ×ÞŸ×ÖÚêæËþ×ޟ׼žºžéæËþ×ÞŸ×ÖÝßæËýÙÞžÙïéÖ—¿Þïæíï´­¦®ßÛìÚ®÷ü§÷ï¬Üë´íÖßÚ®÷ü§Üì¬ßÛìÚ®÷ü§÷ﬧ³¯š§«ë®Ú󯫛Íÿ·»¶ò—ýîýéßßߧåÜéç­ûî¿´îúßìšÜžÙììšÜžÙéåëÛ¯¹Öõúõ«žéß¿ýé¯üšùܾºßßߧåÜëºÍ¦ÖÍ´¯ŸßÙ¯ÞÚŸëßææÚÎ÷²µÎììšÜžÝÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþºª¯¯êûÞªëÿÿÿÿÿÿÕª­–––––––––––––——šš––››——šš––››——šš––››——šš–—šš––››—––––––––––––––––––––––––––––––––––––––––––––––––§­­­­­­¬¬¬¬¬¬¬¬««««««««§§§§§§§—›››››››š––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþº«ªªïÿÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþº«ª«ïþÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþº««ªîÿÞªëÿÿÿÿÿÿÕª­­Üõ¹ýôÏùï×üÖÛ®–½æÚÙöξÜ×íüßÚÞÍæûô­ûê¾þæÖé›ÿëïÙ¹ùû¶¶³û¦¼Ý¼óܶ—›²ëõæÖ®µ³ë´ó­ËÚ¯çó¯Þ¯çê›—–šå›Ý–––®ž¦¦žÙéçܬ§ž¦µ½ý¯ò¦¦ÙÛ½ž—¦½¿¾§´¶¬§¹—ŸŸ½ý¯òŸ—¦ÙÛÍ—ŸŸµ¾Ë­«´—š¿ý¯ò¦¦ÙÛ½–ž—žžÍ½—š–ËͦŸŸšµÚק¬ßÛ–šååϾýü¾¦¦—ž–¦—š¾ËŸ–›—ËŸÙÖ–––šåÞßæ²®ëÿ½—½—ŸËËŸ–›—˧ëé÷úéÛ½—šŸžÍÍ——Ÿ—š¾½¾«ôöþüܵþŸ–þ÷ï￾›÷þŸ–Öþ¾¦ÙéûùõôåÛ–šÜ·ïŸ––Ÿþ¦þüËÝ–——®ŸóöìÝΦ–ŸÍÍ–¦šž›·ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþº«««îþÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþº«ª®ïûÞªëÿÿÿÿÿÿÕª­Öצ¹–íç­ÎË–š¬–Ûæ²—­¬Ÿ­——›š­¬–®›®¯­¬²—¦§›§³›–›®«­ŸŸ¯¯ž¦š–—³—¯³—§›Ÿ«§¬¯›§¬ž®¬—ž¦›š²§¦²Ížž—¦ŸžžÍΦšžÎΦ›¾¾›—š¾§·µû÷ìÖÖú—ŸŸ½—ËŸ–›—ËÍ—ŸŸ½—–½—¾Í–žžžšŸÎË–ËΦ–ŸÍ¾›ŸŸ¿§»¹ùúìþ—š¿¦ëÖÙÖüÿìÝͦš—ž¾½›–¦—ŸŸÎΦ›¾¾š¦Í¦¦Í–¦šž›–——š¾§æßššéÖÖÝË››Ÿž›Ë¾š¦Í¾ž–¦¦Í––í–Ÿ¬êì——éþ—š¿¦ëÖ–––––éé–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþº«ª¯ïúÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþº««®îûÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþº««¯îúÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþº«®ªëÿÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþº«®«ëþÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþº«¯ªêÿÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþº«¯«êþÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþº«®®ëûÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþº«®¯ëúÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþº«¯®êûÞªëÿÿÿÿÿÿÕª­–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþº«¯¯êúÞªëÿÿÿÿÿÿÕª­––––––––––––š››–š–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––§­­­›––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ»ªªªîþÞªëÿÿÿÿÿÿÕª­§ùû³Ý¾êæ¾ß–¹ó½–óéüíÖî·š×—ííí–Ö´Öíí–Ö–í´íÖ´Ö–ÖÖÖÖ–í´´ííÖÖü´ü®—Ú¦ùÓ½ÿúìçôÚ´½æݧéšþòÛê¬ÛΞ–Ÿ—–˾¾––––––––––š«Úæš––––––––––––––––––––––––––––––––––––š««š½›¦ššŸ››¦Î½–¦š¾½›–¦—–žÓ¾—›Ë›š››Ÿ–š««––––––––––––––––––––––––––––––––––––––«–·š—–¦ž¾Ë–š¾Ëš¾Î¦›¾¾š–––Ÿ¦—š¾Ë¦—¦—–¦¼–Úó–žž–ͽ›žÏ¿›¦ÏΟ˽›–Ÿ¦—Ÿ¾ßí–››—š–š–¶ÚßÍž—žŸ¦–;žž–¶ÚßÍž—žŸ¦–ÍΗž–¶–ÚîšËÏõÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ»ªª«îÿÞªëÿÿÿÿÿÿÕª­÷¯ÞçÍÚþÓ«õºçéôµö–¼¦õçþ›ÿÎÍËÞî²þëïÓí³ÝšùŸÞóËöíî×Ë®³çëžïæ¾õû»µ×®Ëº›ò÷åòÏÿ³ûÝË÷ûê´¯ýûºŸû²³úºÝ«Þ–ÝëܬޖÝëÛ­Þ–ÝÎïæÚšÛ¯¼ËÍïæÚ²åë¼Ï²åìÞ§ÞÚ§ÚÞ§ÞÚ§ÙæÚì§Þë«ÍíçìéÚºòöÏéÚºòÎíçßÎò×Ûï¾Îò×Û½òÎïÞ¼îëÎïÞ¼îëç§ç³ßÞì§ìç§ç²åÞ짦³§íõߺÍì§éß½íßßߧ³›ëæÚ²åëïòŸåó¯«õ¬Ïº§¦§–½òÍòÞ¼îëÍòÞ¼îê¼µê­çì§õÍê­çì§õµ²å¦³§÷÷éß٬ߧ³›ëµ³îÿ—´ì÷ýæŸå󯫖鷦§§³­ÚììæÝÚ§ÚæÝÚ§ÚÎïÞ¼îëÎïÞ¼îžÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ»ª«ªïþÞªëÿÿÿÿÿÿÕª­çû¶šÖóͬßì¼ÏÙûÍ–½¼òî·òüý×ÙóÓüµ®é·­¶¬¯îüŸéŸýµüëͬ¯«ß½¼Üæ¾åÏÞÙ·»Úôúηùά²Ý¦ÿ§Öô­þûþÎåÜÛ¬§šýù²¾·×§ìëæÚ¶ôæ¯ë«®æÖ¬þóå¿ôé欛«õõ¬´¿¬Ïº´Í¯¬óþ¬´¿¬½¶å¿ôíôåç­ûžµ´—߬—üü¼¼êšÜÓóúûûòž®½´Ïå¼ê¯ûîµÞóßßì׬Ÿ–––Üå¬õõ÷óÿö×××קí÷×××ק¦®­ôþåæÚ¶ôÍïæ×å–Ïå¼ê¯ûîæê¯ûî¬çͼßßì³ûîéÍõ®ò¼Ö–ûîÛÖÍ´ÖÙûîíšíó®íçͼ֖û۹ç–ßߧ›«õ¿¯¶ôÞ¶ôÍ´ÏåºåÙßÙ¿ôšÍ´ÖÙûîßæ×å–Ï广ôéߧ›«õôçæÚÚÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ»ª««ïÿÞªëÿÿÿÿÿÿÕª­úÓߦ­Ó»×­·Öµíîý÷ÓÜÖììÓ¹¼­–öݗήæ»ü¿Ï¼Óµ¯·¯õîܵÿÞÍùšÓ¼–¦³½¼ÎÓ¬üí¯®¾ž½é»ïÞí×µë¯æ¿²òæ¦ßÞì§ìŸåÞì§éßßߧ³›ìç§ç³ßìç§ç²åéßææíîýýîîýüÝݧúŸ§Ó²åšéóž¿«çÙ«éÛûú«´òŸåó¯«õ¬ÿóßÞ§÷ü½òÍòÞ¼îëÍòÞ¼îþ»åÿ»åæê­²ž­óû³ÚììæÝì§ÙÜ­ÚæÝì§ÙÜ­Ößßߧ³›ÿ³îëŸåöÏåíŸæòÏîÞ¼îëÏîÞ¼îìëÞì§ëæÚ짮³›Í¬óóííùæõÍæ«Ÿ®ëß³Öæöõú¿½¼—ëìë›éºùÍõéïßß«¹æî«ò­›ÖÚ›Íííííšò–ìþ—ÿšæÝßÖ–ßç›Ü®æçß–Ü®æžÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ»ªª®îúÞªëÿÿÿÿÿÿÕª­µÛôìõ·õ¹ÚìÖþ½ßÓó¯Ý§ç½ý¦¾Ûþš¿µûº²·¼÷³í¼ÞÏôµÛ»ö­ö´ôÏÍ·Û¾ÓܲÛææ¾Î¹¿¦¯·¾¶úæ·îݵöÖ»ó²Ý´óžßžôô÷îÜå«›«õüÙæòšô÷õå¶ô®Ÿ®ßæÚé­ìÝ«Þë«ìܬÞê¬ííëæòšô÷þ׶ô®Ÿ®¬åÚ¿íߧûۦ÷óõåç–ïϧÜòͬÝæÖ–óþµÎ®§­Ùê¬éߧûۦ÷óõåç–ïϧÜòϧÝæÖ–óþµº§­Ùë«Í´çͼߧûۦ÷óõåç–ïϧÜòͬÝæÖ–óþµïÚ§­Ùê¬éߧûۦ÷óõåç–ïϧÜòϧÝæÖ–óþµùߧ­Ùë«öþ«íößܬöý¬íôçºÍé­íôçæÚé­Ííê¯óþµêü¬çÍöçÍöçͺš–ìÖÞÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ»ªª¯îûÞªëÿÿÿÿÿÿÕª­½»ÍûÙ˷ݞܮöô»¾®ž—¦ËöݾÖï¹Ö»×ºõ§ëº¯½®Ùﻹ—µ›ÖÞÜ´žûóˬ¦—Í­òö¶ô­´›×Ö¦¬Ïîå—å埛ÍîÚ–Úù¶šžžüôšéæù˧ìÞ®æëë›Ü®æÝ«ëí·¯ß×뫼üç»ííóó÷æÚ´õæ׬޵öæÙ«Þ´õëÞ§Þ´õëÞ§Þ´õôíüüßßÚ»íë·üì·üü÷üý«þõ··®§¦ÚÞåºÍì§ìÏíÝ뫼üçì¾öݺòë½õݺòÓííí횬óóíí¿¿µåæÚ—Þêêç³Û×ÛÙÝúõýôšæêåéݦÛÞÝúóëÞß³×öòýýÙ뫼ü箦®¾ííííš´çÍöŸîöŸî¹Ý«õíõòìé®ûî«­–Ÿßßךۯ¼ËëçÙšÛ¯¼Ëéëïùÿòôôåéíÿùõíôåéíýûíõô—ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ»ª«®ïúÞªëÿÿÿÿÿÿÕª­«éíº×–êß»öµÚîÚêêÎüÚ»¾¯éú¿²Ýêºîåž²²º¼Óšúù«ôçë»Þí­ê²Þݞ˴ë§æ²¹µË¶¯§«¶¶ž¦¬´æ÷Úí·÷æÝ÷—ÍÓõõú»å«ûۯþú²ÿÚÛßìý§þ÷ÏšÓö–ü—¦¾¯æ鼯õ–üš¹æÚ·óÞ·óæë–ïηþíš¹²½¬¹ž—ßëë–ᄐ˖üÓõÎËôçºÍ·óþ§—ÎæÖέµ¯æéßÚ¯æìËó÷óÖç­û۹ç–ï—³÷õ¬þ¬Ÿîö²ù駾ߺͷóéå«ûü¯¹¶ôË–«´—çÖË÷æ×ß—÷²»æ¬ûî½ûß—÷²Ýíæ¬ûüöçÍÞíç­ûüöçÍÞ¬óóíí´ßž¼üÜÖë¼üÜÖåßéêýý«ò¯Ÿ«Þííí횬ííóó¿Ÿîöûîæ¼¼¼ÿÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ»ª«¯ïûÞªëÿÿÿÿÿÿÕª­—–«§šš®¯ÚÙ–—ÚÙ–ž®«§²³›š¯žîòš¦ÛïÏÓ¶³éìÓ½ê×éÍ—þÎÓôùÛÛ—µÖÖÖ§–÷÷ßÖíîÚÙšÙí´÷§íó§Í–ÍÍ´––š—¯Ýéíòôíþùö¶Í÷õÙéÿçæ¬ûîåÝ«®þ«éÞóßé®ûîåÝ«Ù²ßÚ¶ô®³žµ´—Ù§¾¾––´´–––§·Ë¾›—š¾––––––––––½³³½–½½––ŸŸ––––––ßî›—šš››šÓŸ–––ËËÓËšŸ¼¼Î¬¼–¼¼–¼¼Í½Ë·§–§ÖßΞ½¾¾–––––––––¿¿–ͽνϟÎÍÍ–ŸŸ–––––¾¾–––––––½½––ËË–––ééé–ééééÎϾ¾ó§§§§§«ûö§«¹¹´´Í;¾ËË­­öö´µ¶¶ÍÎÜÛììííþûÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ»ª®ªêþÞªëÿÿÿÿÿÿÕª­îùæïóßü¹ÝúîšÓ¶³º¾Üº¾÷«ý®´êî½Íé½î×߬ÓôíïïîÞŸ®ìïù÷÷»»«×Ú›ÏÏùôôîßíïšî¯ÿ³²›ýšýçÛ¯¯÷ó—¯êŸýŸ­Î»¬ÓßÚš–×—ò¯õúõ²ùö²ùÜííííš·³ó½ë²ûüöçÍÞí¼¯§§ÖýÎõ÷ýËêžõí§ÛššòÛ­÷ü§Ü쬹Ïåžæóíóô«æÖÝÛ½´ÝéÝÓòϺßËó÷þåÛ­÷íÜìµ—´¿íßßߧê×ì·ýÝÚ§Ú·ýÝÚ§ÙæÚ¯æÍò秭›§üó²»òç§çì§ìç§çì§ìÍòÞ¼îëÍòÞ¼îêßßߧ³›éæׯæšÏþ®éÍ¿Ú®çÏÎÛ®çÏ¿Ú¯æçì§ú¯­ó·«¾¦§üó·«¾×í¿·½¾íŸé·«¾éì§çé­çì§çì§çì§çì§çÞ–§ÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ»ª®«êÿÞªëÿÿÿÿÿÿÕª­¹Îå«ö÷ÛýêÏëýýÙïò›×ï´íµ›×›ôýÏþ»Ïóþåå®é·òéçìæÝë»ïïæ»Ùë¯ÜéÛ×ÚõÎÝÚÓòËö·÷ÛÖéÍó®«çÓÚêË®²åÚš³ùù——®®§§¬¬µµ½½––ßßýüíîïïÿÿûûšš««­­ºº´´Í;¾¾¾¾¾¾¾¾¾ÜÜ——¾Í¦–Ÿ¿ìß–––––¾žŸ¦Ïìî–ž—¦—›ž¦—–Ëͦ–Ÿ¿ìß––––––––––¾žŸ¦Ïìî›—šš››šÏìï—¦žž—ξ›ŸŸ½ÏÏ—›–Í–žž–ͦϞӦΟËÍž–—¦´»ŸËË›š—ËËššŸÎ˦ͽ›žÏËŸ¦›žÍ¿›¦ÏΟ˽—–›—´ÚÚ·›¦ž——¦Ï¾¦Ÿ——Ó›­Úô›šž¾¿—˽½ËšÎ¾›—š¾Ë››š¾¾š¦ÍΦ›îÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ»ª¯ªëþÞªëÿÿÿÿÿÿÕª­¿½­«®Ýôº½»ºµ´º«Í–—öûÍôïË·¯²«Þì³î黫ÞÚ×Þº¹õÛ¶¶ïÙê²û¯ôÚç«Ûêæ¼ÎÍ´ÍέͼÚܦŸ³ÍòÝÛô—º–Ùé­éßìì§ëöºþ§šöò«ôçͼå«ûîåËó÷ó–·Û¹ç–ï—³òý¬úóŸ§þ¬Ÿîö²ù鼦çë²ûî½–š´ç͹¿ôõšíìÛ­²¶éíìžæõÎ짯çºÍ¶ô¬»íì³ûîæë²ûîÏòžæÞ®çìžæÞ¯æ®úîßçìç®þôÞçûó§—Ýžæìç®ôþÞì–ûó§žÙçþ¾®çÞ®çìçÞ·ó®þô§ûó§³ìº¶Ëóõµ®çìçÖÎê¹²»ÏÏïš›çõ´¹õ§óšÎ®çÍ´¯ŸìæåóÓõη÷ïõ§üõ÷¾®çõµ®çí¯ÿÏ»»´¯ŸìæåóÓÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ»ª¯«ëÿÞªëÿÿÿÿÿÿÕª­ÛöÖ·þ¶³¬Ú¿ùÞïõçִ幦絭õÛúµ¯²¿ï»žûæìúӗ粟þòëË»ìò¾îÏ«ŸÎÜ·ëšÞüßž÷›­ö×ÿ¬ê»Öò¹ÿÝÖÓù÷ÏÞÖæ¬×½›¦šÏ˦¼®Ëž–—¦Í¦ÎŸËÍžž¦›–—¾¾¦Ÿ—¦—š¾¾›—š¾Ë¦¼®Óž—¦½ËÓ–Ëž–—¦Í¦ÎŸË½–››—šË½›¦šº¯ë–îž–¦¦Ó›––½›š–ÏìÚ»ŸŸŸš¾ÏžŸÎË—–›¾ÎŸËË›š›¾½›–Ÿ¦›žÍ½›¦š¾¦ßÚµ—¦žž—ÎͦŸ——¾¾›ŸŸ¿½›š¾Í–žž–ͽ½¿›¦õÚµ—¦žž—ξ–ž—¦—›ž¦—–˾›ŸŸ¿½›š¾Í–žž–ͽ½¿›¦ÏßîšËÏžŸÎΞ›ŸÎÍ–¦–¦—¦—šÏ¦ßîš–š¶Úò–˾›—šžÍÍžššîÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ»ª®®êúÞªëÿÿÿÿÿÿÕª­Ù–»»÷Ýú¶ºí§ë¶ž–­²—»š´Ö÷¾«Íó–—´Íî¯ùöë¾Ý¹­ó¦éþùκêÞ­ò浫ÜÞýþ¬Í¼ùóÝú¼Ÿ¯¯åͻݻ´³«¹îò²úóÚîõη÷ïõ§üõíµ¯æÝ—®çí¯ÿÏ»»úíóóùçìçÿºæíõêóÓõηóüóéìíÍç÷üéìåæÚ·óšÙ×õÍç÷üéë߬›·ó¬Ùêç¿··ó¬¹íííïò¿ôŸß½Í¿í»í®¿í»¬š–íæ×å–ÏåéÞ󧳭éÞßÛ­÷ü§÷ï¬÷ò´óÛßÛ­÷ü§Üì¬éÞßÛ­÷ü§÷﬽¹³¦§§«ëŸå󯫛Í秭›§ü—ýóÿçßßߧê×éç­ûî¿´ôþß®Ùݳßì®Ùݲåéåë–æ¼Öõúõ¯Ÿçß¿ý§æÿšùܾºßßߧê×ëºÍ§ìÍ´—¬ßÛ­Þ–ÝžÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ»ª®¯êûÞªëÿÿÿÿÿÿÕª­ûÿï릺šüõîßÚîö¬é¬ïüÏÜüÓ¦š¼úï¿®—š­Ÿ—›šššš—›ššš–›––—šššš—–›š›–šš›šš·íò¶šš–¯³Ÿ¬­›Ö§ú­óý·²ÿž–´šÚŸ¿¾Ÿ–´ÚŸ¿Î—Ÿ¦¾Í–¦Ÿ—ž–¶Úî›—š¾Ë–›š›–¶Úᄑ˾ž–¦¦¼Úï—Ÿž›—›¾¾›—šš››šî×–·—¦—–›šš›šŸÎËšš–¦šÏΟËÍ—ŸËÍ–¦šž›´Úæ––––––––––––––––––––––––––––––––––––––««š½–¦š¾Ó—Ͼš¦Í¦¦ÎŸË¦¦½›–Ÿž—žÍ––š««š––––––––––––––––––––––––––––––––––––š««š–––––––––ËŸ–›—òÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ»ª¯®ëúÞªëÿÿÿÿÿÿÕª­«åõ®óêÖö·ô½®Üµò–ÚÚšî¿—­¹ìòÓÏ«½«õÛÚºŸýý˧º®ûöÎß´µ«­µ¶»¹«Ë»¯¶Ëµú¬–ýõ繟·ïöÛò¶šÞÜÞ«Ï÷®›ìßææÚšÛ¯¼Ëì®Ùݳßì®ÙݲåìÛ­Þ¯çë榖׫ëÍíßææÚšÛ¯¼Ëì³×öòôó½´çÍöŸîöŸî¼å«ûîæå«ûîæë²ûۦ÷üì÷ç–ﶹöçë²ûî½–––––šíìåÿºÙžÞëš²öºÝÝ÷¹¼¯õ–üš´ë–ïš¹îÞ¬¹÷üßëë–ïµÓ½»¾¼éöõºõ§šÿÚÓß¿¬§ßÝ—²Ùé®ûîæì³û۹ç–ï¬ÿî—³ÏæŸîö²ùé÷ßåßךۯ¼ËëçÙšÛ¯¼ËÍíê¯óþ¬²ùö²ùö²ù¼ìß®ÞÚõºõõùë—µçÚ×æÝ—ÙÞÙÞªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÕª–ÿþ»ª¯¯ëûÞªëÿÿÿÿÿÿÕª­––––––––––––—––››——šš––››——šš––››——šš––››——šš––››——šš––››—›––šš—š–––––––––––––––––––––––––––––––––§­­­­­­¬¬¬¬¬¬¬¬««««««««§§§§§§§—––––––––————————ššššš›––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––Þªëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ \ No newline at end of file diff --git a/disks/prodos242.dsk b/disks/prodos242.dsk new file mode 100644 index 0000000..8d301a1 Binary files /dev/null and b/disks/prodos242.dsk differ diff --git a/docs/Compiling.md b/docs/Compiling.md new file mode 100644 index 0000000..652f20a --- /dev/null +++ b/docs/Compiling.md @@ -0,0 +1,33 @@ +## How to I compile it and run it? + * You need a C compiler, make, and a few libraries: + * libasound2-dev [ optional, for audio ] + * libgl-dev + * libglu-dev + * libx11-dev + * Many of them will probably be installed already if you regulargly compile stuff. + * Then just type `make` and it should compile. + * To run it, just type `build-x86_64-linux-gnu/bin/bin/mii_emu` and it should start. + +## Development +* This is the first project I made using vscode as my main IDE; I used Eclipse for many years as the indexer was pretty much unbeatable (still is). +* To support vscode I needed some tooling to create the '*compile_commands.json*' file, which is used by the C/C++ extension to provide intellisense. So to create that file, you use `make lsp` and it will create the file in the project directory. +* Another thing vscode sucks at is Makefiles (despite the extension, building is painful and next to useless). So there is a target called `make watch` that you can run in a separate terminal to auto-build as soon as you same any files in vscode. That is when you realize for example that vscode re-save the file anytime you press control-S, regardless of wether the file has changed or not. So you end up with a lot of unnecessary builds. I'm sure there is a way to fix that, but I haven't found it yet. + +## Code Style +I have pretty consistent code style across my projects. +* tabs=4. Just because. +* 80 columns lines or so. I don't like to scroll horizontally and I like splitting my screen vertically. (also see, tabs=4!). +* K&R style exclusively. None of that Allman/GNU horribleness. +* No Yoda, we are no longer in 1975. `if (0 == foo)` is just stupid. +* I use !! to convert to 1 or zero from an expression. I call it the 'normalisation operator'. it is not commonly seen, apart from places like the Linux kernel. +* I use *minipt.h* for protothreads. I like protothreads, and when you are aware of their limitations, they are a great tool. They are used for the video rendering, the no-slot-clock etc. + +## What needs doing? +* I'm sure there are bugs. I haven't tested it on a lot of hardware, and apart from quite a few games and a few known productivity app, it had had very little extensive testing. So testing! +* In the code there are a few bits which needs fixing + * The mouse card is not working properly. It works for some (most importantly A2 Desktop), but it's not working properly. I suspect the VBL Interrupt handling. + * In mii.c, the *mii_page_table_update()* does work, but it sub-optimal, it was handy to debug the countless combination of soft-switches, but it is not the ideal way to handle that problem; it needs a proper switch-case statement. + * The floppy drive emulation was borrowed from bobbin, and it works, and it + got it all working, but it's definitely not matching the style of the rest of the codebase. It needs to be replaced. + * Plenty of the most complicated piece of code (video, memory mapping) load a dozen of soft-switches, it probably should use a separately maintained bit field that is maintained by the on/off switches, and would make it a lot easier to test for bit combinations. + * The static array of memory 'banks' works, but it prevents me easily making a memory extension card. It should be refactored at some point. \ No newline at end of file diff --git a/docs/screen_color.png b/docs/screen_color.png new file mode 100644 index 0000000..a0cd620 Binary files /dev/null and b/docs/screen_color.png differ diff --git a/docs/screen_green.png b/docs/screen_green.png new file mode 100644 index 0000000..5b10a12 Binary files /dev/null and b/docs/screen_green.png differ diff --git a/docs/screen_main.png b/docs/screen_main.png new file mode 100644 index 0000000..f833753 Binary files /dev/null and b/docs/screen_main.png differ diff --git a/docs/screen_mish.png b/docs/screen_mish.png new file mode 100644 index 0000000..36ec020 Binary files /dev/null and b/docs/screen_mish.png differ diff --git a/docs/screen_total.png b/docs/screen_total.png new file mode 100644 index 0000000..785a2d6 Binary files /dev/null and b/docs/screen_total.png differ diff --git a/fonts/DroidSans.ttf b/fonts/DroidSans.ttf new file mode 100644 index 0000000..767c63a Binary files /dev/null and b/fonts/DroidSans.ttf differ diff --git a/fonts/FreeLicense.txt b/fonts/FreeLicense.txt new file mode 100644 index 0000000..e48a09b --- /dev/null +++ b/fonts/FreeLicense.txt @@ -0,0 +1,20 @@ +KREATIVE SOFTWARE RELAY FONTS FREE USE LICENSE +version 1.2f + +Permission is hereby granted, free of charge, to any person or entity (the "User") obtaining a copy of the included font files (the "Software") produced by Kreative Software, to utilize, display, embed, or redistribute the Software, subject to the following conditions: + +1. The User may not sell copies of the Software for a fee. + +1a. The User may give away copies of the Software free of charge provided this license and any documentation is included verbatim and credit is given to Kreative Korporation or Kreative Software. + +2. The User may not modify, reverse-engineer, or create any derivative works of the Software. + +3. Any Software carrying the following font names or variations thereof is not covered by this license and may not be used under the terms of this license: Jewel Hill, Miss Diode n Friends, This is Beckie's font! + +3a. Any Software carrying a font name ending with the string "Pro CE" is not covered by this license and may not be used under the terms of this license. + +4. This license becomes null and void if any of the above conditions are not met. + +5. Kreative Software reserves the right to change this license at any time without notice. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE SOFTWARE OR FROM OTHER DEALINGS IN THE SOFTWARE. diff --git a/fonts/PRNumber3.ttf b/fonts/PRNumber3.ttf new file mode 100644 index 0000000..4843041 Binary files /dev/null and b/fonts/PRNumber3.ttf differ diff --git a/fonts/PrintChar21.ttf b/fonts/PrintChar21.ttf new file mode 100644 index 0000000..7204e97 Binary files /dev/null and b/fonts/PrintChar21.ttf differ diff --git a/fonts/ProggyClean.ttf b/fonts/ProggyClean.ttf new file mode 100644 index 0000000..0270cdf Binary files /dev/null and b/fonts/ProggyClean.ttf differ diff --git a/libmish/.gitignore b/libmish/.gitignore new file mode 100644 index 0000000..115a020 --- /dev/null +++ b/libmish/.gitignore @@ -0,0 +1,2 @@ +build-* +doc/.tags* diff --git a/libmish/LICENSE-2.0.txt b/libmish/LICENSE-2.0.txt new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/libmish/LICENSE-2.0.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/libmish/Makefile b/libmish/Makefile new file mode 100644 index 0000000..7a50281 --- /dev/null +++ b/libmish/Makefile @@ -0,0 +1,98 @@ +# Makefile +# +# Copyright (C) 2020 Michel Pollet +# +# SPDX-License-Identifier: Apache-2.0 + +SHELL = /bin/bash + +SOV = 1 +VERSION = 0.10 +PKG = 1 + +TARGET = libmish +DESC = Program Shell Access + +ifneq ($(CC), emcc) +BASE_LDFLAGS += -lutil +endif +BASE_LDFLAGS += -lpthread +EXTRA_LDFLAGS = $(BASE_LDFLAGS) + +# Auto load all the .c files dependencies, and object files +LIBSRC := ${notdir ${wildcard src/*.c}} + +# Tell make/gcc to find the files in VPATH +VPATH = src +VPATH += tests +IPATH = src + +include ./Makefile.common + +TOOLS = +TESTS = ${BIN}/mish_test \ + ${BIN}/mish_vt_test ${BIN}/mish_cmd_test \ + ${BIN}/mish_input_test \ + ${BIN}/mish_argv_make_test + +all : tools tests + +debug: all ${BIN}/mish_debug_test + @echo "*** mish_debug_test is dangerous, do not install anywhere" + +.PHONY: static shared tools tests +static: $(LIB)/$(TARGET).a +shared: ${LIB}/$(TARGET).so.$(SOV) +tools: $(TOOLS) +tests: $(TESTS) + +LIBOBJ := ${patsubst %, ${OBJ}/%, ${notdir ${LIBSRC:.c=.o}}} + +$(LIB)/$(TARGET).a : $(LIBOBJ) | $(LIB) +$(LIB)/$(TARGET).so.$(SOV) : $(LIBOBJ) | $(LIB)/$(TARGET).a + +# This rule OUGHT to be enough, but somehow it fails to take into account +# the 'shared' dependency, if its written explicitely as it is now, it +# works. I see no reason why it should not work, as the one a line down +# has no problem!! +#$(BIN)/%: | shared +$(TOOLS) $(TESTS): | shared +ifeq ($(CC), emcc) +$(BIN)/%: LDFLAGS_TARGET+=-L${LIB} +endif +$(BIN)/%: LDFLAGS_TARGET += -lmish -lrt + +$(BIN)/mish_input_test: LDFLAGS_TARGET = + +clean:: + rm -f $(LIB)/$(TARGET).* $(TOOLS) $(TESTS) + + +install: + mkdir -p $(DESTDIR)/bin/ $(DESTDIR)/lib/ $(DESTDIR)/include/ + for bin in $(TOOLS); do $(INSTALL) -m 0755 $$bin $(DESTDIR)/bin/$$(basename $$bin) ; done + $(INSTALL) -m 644 $(LIB)/$(TARGET).a $(DESTDIR)/lib/ + $(INSTALL) -m 644 src/mish.h $(DESTDIR)/include/ + rm -rf $(DESTDIR)/lib/$(TARGET).so* + $(INSTALL) -m 644 $(LIB)/$(TARGET).so.$(VERSION).$(SOV) $(DESTDIR)/lib/ + cp -f -d $(LIB)/{$(TARGET).so.$(SOV),$(TARGET).so} $(DESTDIR)/lib/ + mkdir -p $(DESTDIR)/lib/pkgconfig + sed -e "s|PREFIX|$(PREFIX)|" -e "s|VERSION|$(VERSION)|" \ + mish.pc >$(DESTDIR)/lib/pkgconfig/mish.pc + +deb : + rm -rf /tmp/$(TARGET) *.deb + make clean && make all && make install DESTDIR=/tmp/$(TARGET)/usr + mkdir -p $(BUILD)/debian; (cd $(BUILD)/debian; \ + fpm -s dir -t deb -C /tmp/$(TARGET) -n $(TARGET) -v $(VERSION) \ + --iteration $(PKG) \ + --description "$(DESC)" \ + usr/lib/{$(TARGET).so.$(SOV),$(TARGET).so.$(VERSION).$(SOV),$(TARGET).so} && \ + fpm -s dir -t deb -C /tmp/$(TARGET) -n $(TARGET)-dev -v $(VERSION) \ + --iteration $(PKG) \ + --description "$(DESC) - development files" \ + -d "$(TARGET) (= $(VERSION))" \ + usr/lib/$(TARGET).a \ + usr/lib/pkgconfig \ + usr/include ; \ + ) diff --git a/libmish/Makefile.common b/libmish/Makefile.common new file mode 100644 index 0000000..937c0c1 --- /dev/null +++ b/libmish/Makefile.common @@ -0,0 +1,97 @@ +# Makefile.common +# +# Copyright (C) 2012 Michel Pollet +# + +SHELL = /bin/bash +INSTALL ?= install +CC ?= gcc +CFLAGS ?= -O2 -Wall + +O ?= . +PREFIX ?= /usr/local + +ARCH := $(shell $(CC) -dumpmachine) +BUILDNAME := build-$(ARCH) +BUILD := $(O)/$(BUILDNAME) +OBJ = $(BUILD)/obj/$(TARGET) +BIN = $(BUILD)/bin +LIB = $(BUILD)/lib + +DESTDIR = $(O)/build-$(ARCH) + +EXTRA_CFLAGS += -g -fPIC --std=gnu99 +EXTRA_CFLAGS += -ffunction-sections -fdata-sections +EXTRA_CFLAGS += ${patsubst %,-I%,${subst :, ,${IPATH}}} + +ifeq (${shell uname},Linux) +EXTRA_LDFLAGS += -Wl,--relax,--gc-sections +READLINK = readlink -f +endif +ifeq (${shell uname},Darwin) +READLINK = echo +endif + +ifeq ($(V),1) +Q := +else +Q := @ +endif + +EXTRA_LDFLAGS += -L$(LIB) -Wl,-rpath,${shell $(READLINK) ${LIB}} + +all: ${OBJ} + +# +# Generic rules +# +$(OBJ) $(BIN) $(LIB): + +$(Q)echo " MKDIR" $@ && mkdir -p $@ + +$(LIB)/%.a : | $(LIB) + $(Q)echo " LIB ${@}" && \ + $(AR) cr $@ $^ \ + || echo Error: $(AR) cru $@ $^ + +.SECONDARY: + +$(OBJ)/%.o: %.c | $(OBJ) + $(Q)echo " CC" ${filter -O%, ${EXTRA_CFLAGS} $(CFLAGS) ${CFLAGS_TARGET}} "${<}" && \ + ${CC} -MMD ${EXTRA_CFLAGS} ${CPPFLAGS} ${CFLAGS} ${CFLAGS_TARGET} -c -o ${@} ${<} \ + || echo Error: ${CC} -MD ${EXTRA_CFLAGS} ${CPPFLAGS} ${CFLAGS} ${CFLAGS_TARGET} -c -o ${@} ${<} + +$(BIN)/%: $(OBJ)/%.o | $(BIN) + $(Q)echo " LD ${*}" && \ + ${CC} -o ${@} $(filter %.o %.a,$^) \ + ${EXTRA_LDFLAGS} ${BASE_LDFLAGS} ${LDFLAGS_TARGET} ${LDFLAGS} ${LIBS_${*}} \ + || echo Error: ${CC} -o $(filter %.o %.a,$^) \ + ${EXTRA_LDFLAGS} ${BASE_LDFLAGS} ${LDFLAGS_TARGET} ${LDFLAGS} ${LIBS_${*}} + +ifeq (${shell uname},Linux) +define soname + "-Wl,-soname,$(1)" +endef +else +define soname +endef +endif + +$(LIB)/%.so.$(SOV) $(LIB)/%.so.$(VERSION).$(SOV) $(LIB)/%.so: | $(LIB) + $(Q)echo " LDSO $@" && \ + { \ + naked=${shell basename ${basename $@}}; \ + ${CC} -shared \ + ${call soname,$$naked} \ + -o $(LIB)/$$naked.$(VERSION).$(SOV) \ + $(filter %.o %.a,$^) \ + ${EXTRA_LDFLAGS} ${BASE_LDFLAGS} ${LDFLAGS} && \ + ln -sf $$naked.$(VERSION).$(SOV) ${LIB}/$$naked.$(SOV) && \ + ln -sf $$naked.$(SOV) ${LIB}/$$naked ; \ + } || echo ERROR: $@ -- relaunch with V=1 + +clean:: +# rm -rf $(OBJ) $(BIN)/$(TARGET) + rm -rf $(BUILD) + +# Include autogenerated dependencies +-include ${wildcard $(OBJ)/*.d} diff --git a/libmish/README.md b/libmish/README.md new file mode 100644 index 0000000..f9607b6 --- /dev/null +++ b/libmish/README.md @@ -0,0 +1,111 @@ + +## libmish TL;DR : +*libmish* is a library that allows you to add a command prompt to any of your own program. It captures the standard output and standard error file descriptor, create a log with this, and displays it back to you, with a command prompt. + +You can then add your own commands to interract with your (running) program. Oh, *libmish* can also serve this to incoming telnet sessions (on a custom port), so you can connect to detached processes too. + +## Demo +Consider this program. The only "new" things are the #include, and the mish_prepare() call. That gives you telnet access and will log all output, but not much else. + +```C +#include "mish.h" + +int cnt = 0; + +int main() +{ + mish_prepare(0); + + while (1) { + sleep(1); + printf("Count %d\n", cnt++); + } +} +``` + +Now add this at the bottom of the file: + +```C +/* And here is a command line action that can reset the 'cnt' variable */ +static void _test_set_cnt(void * param, int argc, const char * argv[]) +{ + if (argc > 1) { + cnt = atoi(argv[1]); + } else { + fprintf(stderr, + "%s: syntax 'set XXX' to set the variable\n", argv[0]); + } +} + +MISH_CMD_NAMES(set, "set"); +MISH_CMD_HELP(set, + "set 'cnt' variable", + "test command for libmish!"); +MISH_CMD_REGISTER(set, _test_set_cnt); +``` + +And here you go: +![Demo of libmish](doc/demo.gif) + +As you can see, the stderr output is colorized. The program also told you the telnet port to call into (but you can also see it via the 'env' command later on). + +Calling the 'set' command will change the main variable. Of course it doesn't been to be thread safe in this instance, if you want your command to run in a thread safe way, you have to use mish_cmd_poll() from your thread, this will run pending commands in your own context. + +## Ok what's going on here, why do I need this? +Let's say, you have that program that runs for days. Or months, or years, and it has it's log in a log file and all is very well, but sometime, you'd like to just *interract* with it, say, check statistics, internal state, or just change a parameter or so. Or just pet it for the good job it's doing. + +Traditionally, you'd just restart the program with new parameters, or use a *host* of other complicated methods to send commands to the running program, like signals, UNIX sockets and countless stuff like that. + +*libmish* allows you to that poking around, without having to bother that much about it. Just add *libmish*, register some of your own commands, and you'll be able to 'connect' to your running program, check it's output history (without having to deal with log files) and use your own commands on your own running program. + +## What does work? +Well, its' already quite useful: + + * You can browse the history of the log of your program with Beg/Page Up/Down/End + * You can telnet in, and check the log too. + * You can display command history and use control-P/N to navigate it + * You can easily "register" your commands, with their own 'help'. + * It only requires one single "mish_prepare(...)" call at the start of yout main() to work. + +## Security? What security? +Obviously, using mish in your program is an obvious security risk, you're +allowing anyone on that machine to temper with your program via telnet, there's no +safegards in place. *libmish* is really made for developement purpose on +machine that you trust. + +Also, as much as I don't think I code like a dork, I didn't go mega full paranoia on security in the internals, so there's bound checking, but I can almost guarantee there must be ways of fooling the various parsers into crashing. Again this was all written in the space of 3 days, so I went for the goalpost as a hare, not as a tank! + +If you want to make sure *libmish* is disabled on machine that you *don't* trust (ie, production), you can set an environment variable MISH_OFF=1 before launching the programs and it will prevent the library starting. But again, buyers beware. + +As to why I use a TCP port (bound to 127.0.0.1), well it's because: + + * I want to be able to use 'telnet' to connect... + * 'telnet' on linux doesn't handle UNIX sockets + * I need 'telnet' because it gives me the terminal window size. + +... otherwise, I wouldn't have! + +## Issues & todos & caveats +This is a brand new library, a whole ton of things works, but quite a few things don't, just yet. + +Some bits I know I want but didn't *need* and some I've tried to fix, but haven't spent enough time on it to nail them down. + +**TODO:** + + * Currently the main thread uses select(), because it's portable. Need to add an epool() alternative one for linux. + * Display a timestamp for lines in the backlog. + * Display some sort of progressy-bar thing at the bottom when navigating the log. + * Add a UNIX stream socket access, but we'll have to use socat/netcat, stty raw and some sort of helper command line. + * Make the backlog expire after X hours/days. A stamp is already collected, but not used. + +**BUGS:** + +* Find a way to cleany quit without screwing up the terminal settings (telnet). + - If you have that problem, use 'resize' or 'reset' to make your terminal work again. + - Or better, use 'screen telnet xxx yyy' as screen is awesome at cleaning up. + - or __betterer__, use the "dis" disconnect command, that works. + - Backlog navigation doesn't take into account line wrapping. + +## Why is it called *libmish* anyway, sounds silly. +Well since you think you're clever, "lib" is for library, "sh" is for *shell* and "mi" is for **me** aka, **michel** pronunced *me* *shell*. Geddit? + diff --git a/libmish/doc/Makefile b/libmish/doc/Makefile new file mode 100644 index 0000000..bb02aae --- /dev/null +++ b/libmish/doc/Makefile @@ -0,0 +1,21 @@ +# +# Copyright 2008, 2009 Michel Pollet +# +# This file is part of libmish. +# +# SPDX-License-Identifier: Apache-2.0 + +# For the callgraph, you need Graphviz, ruby and exuberant ctags. +# This is not generated in the normal code build + + +all: libmish_callgraph.pdf + +libmish_callgraph.pdf: + ctags -f .tags ../src/*.[ch] 2>/dev/null && \ + ruby ./tags_to_dot.rb .tags \ + ../src/*.c ../src/mish.h >.tags.dot && \ + dot -Tpdf .tags.dot -o $@ + +clean: + rm -f .tags* diff --git a/libmish/doc/demo.gif b/libmish/doc/demo.gif new file mode 100644 index 0000000..1dd89f6 Binary files /dev/null and b/libmish/doc/demo.gif differ diff --git a/libmish/doc/libmish_callgraph.pdf b/libmish/doc/libmish_callgraph.pdf new file mode 100644 index 0000000..c6fb1b3 Binary files /dev/null and b/libmish/doc/libmish_callgraph.pdf differ diff --git a/libmish/doc/tags_to_dot.rb b/libmish/doc/tags_to_dot.rb new file mode 100755 index 0000000..df04cd0 --- /dev/null +++ b/libmish/doc/tags_to_dot.rb @@ -0,0 +1,99 @@ +#!/usr/bin/ruby +# +# Copyright 2008, 2009 Michel Pollet +# +# This file is part of libmish. +# +# SPDX-License-Identifier: Apache-2.0 + +$files = Hash.new +$syms = Hash.new + +tags = File.new(ARGV[0]) + +key = Array.new + +while !tags.eof? + next unless tags.readline.chomp.match(/([^\t]+)\t([^\t]+)\t(.*)\$\/;"\t([^\t]+)/); + key[0] = $1; + key[1] = $2; + key[3] = $3; + key[4] = $4; + + next if key[4] == 'm' or key[4] == 't' or key[4] == 's' or key[4] == 'e' or key[4] == 'v'; + next if key[0].match(/[us]?int[0-9]+_t/); + next if key[0] == "ROM_BASED"; + + key[1].gsub!(/.*\/|\.[ch]$/,""); + + unless $files.key? key[1] + $files[key[1]] = Hash.new + end + unless $files[key[1]].key? key[0] + $files[key[1]][key[0]] = Hash.new + $syms[key[0]] = key[1] + end + #puts key[0] + " = '#{key[4]}'" +end + +puts "digraph dump { node [shape=rect]; compound=true; nodesep=.1; ranksep=2; rankdir=LR; concentrate=true; " + +modules = Hash.new; +links = Array.new; + +1.upto(ARGV.length-1) { |i| + + use = File.new(ARGV[i]) +# puts "<<<<<<<>>" + line + words = line.split(/[ \t]+/); + words.each { |w| + if $syms.key? w and $syms[w] != fil + unless $files[$syms[w]][w].key? fil + # puts w + " is in " + $syms[w] + $files[$syms[w]][w][fil] = 1 + + sym=w + unless modules.key? fil + modules[fil] = Array.new + end + modules[fil] += [ "\"cc_#{fil}_#{sym}\" [label=\"#{sym}\",color=\"gray\",height=\".08\",style=dotted];" ] + links += ["\"cc_#{fil}_#{sym}\" -> \"dd_#{$syms[w]}_#{sym}\";"] + end + end + } + end +} + +$files.keys.each { |fil| +# puts "File #{fil} ?" + $files[fil].keys.each { |sym| + # puts "\tSym #{sym} : #{$files[fil][sym].length} ?" + if $files[fil][sym].length > 0 + unless modules.key? fil + modules[fil] = Array.new + end + modules[fil] += [ "\"dd_#{fil}_#{sym}\" [label=\"#{sym}\"];" ] + end + } +} +modules.keys.each {|fil| + puts "\tsubgraph cluster_#{fil} {\n\t\tlabel=\"#{fil}\"; fontsize=\"18\"; " + modules[fil].each { |lin| + puts "\t\t#{lin}" + } + puts "\t}" +} +links.each { |lin| + puts "\t#{lin}" +} +puts "}" diff --git a/libmish/mish.pc b/libmish/mish.pc new file mode 100644 index 0000000..4b3a409 --- /dev/null +++ b/libmish/mish.pc @@ -0,0 +1,13 @@ +# SPDX-License-Identifier: Apache-2.0 + +mish.pc: +prefix=PREFIX +exec_prefix=${prefix} +includedir=${prefix}/include +libdir=${exec_prefix}/lib + +Name: libmish +Description: Adds command prompt for your program(s) +Version: VERSION +Cflags: -I${includedir} +Libs: -L${libdir} -lmish -lrt diff --git a/libmish/src/bsd_queue.h b/libmish/src/bsd_queue.h new file mode 100644 index 0000000..2e16cbc --- /dev/null +++ b/libmish/src/bsd_queue.h @@ -0,0 +1,860 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)queue.h 8.5 (Berkeley) 8/20/94 + * $FreeBSD$ + */ + +#ifndef _SYS_QUEUE_H_ +#define _SYS_QUEUE_H_ + +//#include + +/* + * This file defines four types of data structures: singly-linked lists, + * singly-linked tail queues, lists and tail queues. + * + * A singly-linked list is headed by a single forward pointer. The elements + * are singly linked for minimum space and pointer manipulation overhead at + * the expense of O(n) removal for arbitrary elements. New elements can be + * added to the list after an existing element or at the head of the list. + * Elements being removed from the head of the list should use the explicit + * macro for this purpose for optimum efficiency. A singly-linked list may + * only be traversed in the forward direction. Singly-linked lists are ideal + * for applications with large datasets and few or no removals or for + * implementing a LIFO queue. + * + * A singly-linked tail queue is headed by a pair of pointers, one to the + * head of the list and the other to the tail of the list. The elements are + * singly linked for minimum space and pointer manipulation overhead at the + * expense of O(n) removal for arbitrary elements. New elements can be added + * to the list after an existing element, at the head of the list, or at the + * end of the list. Elements being removed from the head of the tail queue + * should use the explicit macro for this purpose for optimum efficiency. + * A singly-linked tail queue may only be traversed in the forward direction. + * Singly-linked tail queues are ideal for applications with large datasets + * and few or no removals or for implementing a FIFO queue. + * + * A list is headed by a single forward pointer (or an array of forward + * pointers for a hash table header). The elements are doubly linked + * so that an arbitrary element can be removed without a need to + * traverse the list. New elements can be added to the list before + * or after an existing element or at the head of the list. A list + * may be traversed in either direction. + * + * A tail queue is headed by a pair of pointers, one to the head of the + * list and the other to the tail of the list. The elements are doubly + * linked so that an arbitrary element can be removed without a need to + * traverse the list. New elements can be added to the list before or + * after an existing element, at the head of the list, or at the end of + * the list. A tail queue may be traversed in either direction. + * + * For details on the use of these macros, see the queue(3) manual page. + * + * Below is a summary of implemented functions where: + * + means the macro is available + * - means the macro is not available + * s means the macro is available but is slow (runs in O(n) time) + * + * SLIST LIST STAILQ TAILQ + * _HEAD + + + + + * _CLASS_HEAD + + + + + * _HEAD_INITIALIZER + + + + + * _ENTRY + + + + + * _CLASS_ENTRY + + + + + * _INIT + + + + + * _EMPTY + + + + + * _FIRST + + + + + * _NEXT + + + + + * _PREV - + - + + * _LAST - - + + + * _FOREACH + + + + + * _FOREACH_FROM + + + + + * _FOREACH_SAFE + + + + + * _FOREACH_FROM_SAFE + + + + + * _FOREACH_REVERSE - - - + + * _FOREACH_REVERSE_FROM - - - + + * _FOREACH_REVERSE_SAFE - - - + + * _FOREACH_REVERSE_FROM_SAFE - - - + + * _INSERT_HEAD + + + + + * _INSERT_BEFORE - + - + + * _INSERT_AFTER + + + + + * _INSERT_TAIL - - + + + * _CONCAT s s + + + * _REMOVE_AFTER + - + - + * _REMOVE_HEAD + - + - + * _REMOVE s + s + + * _SWAP + + + + + * + */ +#ifdef QUEUE_MACRO_DEBUG +#warn Use QUEUE_MACRO_DEBUG_TRACE and/or QUEUE_MACRO_DEBUG_TRASH +#define QUEUE_MACRO_DEBUG_TRACE +#define QUEUE_MACRO_DEBUG_TRASH +#endif + +#ifdef QUEUE_MACRO_DEBUG_TRACE +/* Store the last 2 places the queue element or head was altered */ +struct qm_trace { + unsigned long lastline; + unsigned long prevline; + const char *lastfile; + const char *prevfile; +}; + +#define TRACEBUF struct qm_trace trace; +#define TRACEBUF_INITIALIZER { __LINE__, 0, __FILE__, NULL } , + +#define QMD_TRACE_HEAD(head) do { \ + (head)->trace.prevline = (head)->trace.lastline; \ + (head)->trace.prevfile = (head)->trace.lastfile; \ + (head)->trace.lastline = __LINE__; \ + (head)->trace.lastfile = __FILE__; \ +} while (0) + +#define QMD_TRACE_ELEM(elem) do { \ + (elem)->trace.prevline = (elem)->trace.lastline; \ + (elem)->trace.prevfile = (elem)->trace.lastfile; \ + (elem)->trace.lastline = __LINE__; \ + (elem)->trace.lastfile = __FILE__; \ +} while (0) + +#else /* !QUEUE_MACRO_DEBUG_TRACE */ +#define QMD_TRACE_ELEM(elem) +#define QMD_TRACE_HEAD(head) +#define TRACEBUF +#define TRACEBUF_INITIALIZER +#endif /* QUEUE_MACRO_DEBUG_TRACE */ + +#ifdef QUEUE_MACRO_DEBUG_TRASH +#define TRASHIT(x) do {(x) = (void *)-1;} while (0) +#define QMD_IS_TRASHED(x) ((x) == (void *)(intptr_t)-1) +#else /* !QUEUE_MACRO_DEBUG_TRASH */ +#define TRASHIT(x) +#define QMD_IS_TRASHED(x) 0 +#endif /* QUEUE_MACRO_DEBUG_TRASH */ + +#if defined(QUEUE_MACRO_DEBUG_TRACE) || defined(QUEUE_MACRO_DEBUG_TRASH) +#define QMD_SAVELINK(name, link) void **name = (void *)&(link) +#else /* !QUEUE_MACRO_DEBUG_TRACE && !QUEUE_MACRO_DEBUG_TRASH */ +#define QMD_SAVELINK(name, link) +#endif /* QUEUE_MACRO_DEBUG_TRACE || QUEUE_MACRO_DEBUG_TRASH */ + +#ifdef __cplusplus +/* + * In C++ there can be structure lists and class lists: + */ +#define QUEUE_TYPEOF(type) type +#else +#define QUEUE_TYPEOF(type) struct type +#endif + +/* + * Singly-linked List declarations. + */ +#define SLIST_HEAD(name, type) \ +struct name { \ + struct type *slh_first; /* first element */ \ +} + +#define SLIST_CLASS_HEAD(name, type) \ +struct name { \ + class type *slh_first; /* first element */ \ +} + +#define SLIST_HEAD_INITIALIZER(head) \ + { NULL } + +#define SLIST_ENTRY(type) \ +struct { \ + struct type *sle_next; /* next element */ \ +} + +#define SLIST_CLASS_ENTRY(type) \ +struct { \ + class type *sle_next; /* next element */ \ +} + +/* + * Singly-linked List functions. + */ +#if (defined(_KERNEL) && defined(INVARIANTS)) +#define QMD_SLIST_CHECK_PREVPTR(prevp, elm) do { \ + if (*(prevp) != (elm)) \ + panic("Bad prevptr *(%p) == %p != %p", \ + (prevp), *(prevp), (elm)); \ +} while (0) +#else +#define QMD_SLIST_CHECK_PREVPTR(prevp, elm) +#endif + +#define SLIST_CONCAT(head1, head2, type, field) do { \ + QUEUE_TYPEOF(type) *curelm = SLIST_FIRST(head1); \ + if (curelm == NULL) { \ + if ((SLIST_FIRST(head1) = SLIST_FIRST(head2)) != NULL) \ + SLIST_INIT(head2); \ + } else if (SLIST_FIRST(head2) != NULL) { \ + while (SLIST_NEXT(curelm, field) != NULL) \ + curelm = SLIST_NEXT(curelm, field); \ + SLIST_NEXT(curelm, field) = SLIST_FIRST(head2); \ + SLIST_INIT(head2); \ + } \ +} while (0) + +#define SLIST_EMPTY(head) ((head)->slh_first == NULL) + +#define SLIST_FIRST(head) ((head)->slh_first) + +#define SLIST_FOREACH(var, head, field) \ + for ((var) = SLIST_FIRST((head)); \ + (var); \ + (var) = SLIST_NEXT((var), field)) + +#define SLIST_FOREACH_FROM(var, head, field) \ + for ((var) = ((var) ? (var) : SLIST_FIRST((head))); \ + (var); \ + (var) = SLIST_NEXT((var), field)) + +#define SLIST_FOREACH_SAFE(var, head, field, tvar) \ + for ((var) = SLIST_FIRST((head)); \ + (var) && ((tvar) = SLIST_NEXT((var), field), 1); \ + (var) = (tvar)) + +#define SLIST_FOREACH_FROM_SAFE(var, head, field, tvar) \ + for ((var) = ((var) ? (var) : SLIST_FIRST((head))); \ + (var) && ((tvar) = SLIST_NEXT((var), field), 1); \ + (var) = (tvar)) + +#define SLIST_FOREACH_PREVPTR(var, varp, head, field) \ + for ((varp) = &SLIST_FIRST((head)); \ + ((var) = *(varp)) != NULL; \ + (varp) = &SLIST_NEXT((var), field)) + +#define SLIST_INIT(head) do { \ + SLIST_FIRST((head)) = NULL; \ +} while (0) + +#define SLIST_INSERT_AFTER(slistelm, elm, field) do { \ + SLIST_NEXT((elm), field) = SLIST_NEXT((slistelm), field); \ + SLIST_NEXT((slistelm), field) = (elm); \ +} while (0) + +#define SLIST_INSERT_HEAD(head, elm, field) do { \ + SLIST_NEXT((elm), field) = SLIST_FIRST((head)); \ + SLIST_FIRST((head)) = (elm); \ +} while (0) + +#define SLIST_NEXT(elm, field) ((elm)->field.sle_next) + +#define SLIST_REMOVE(head, elm, type, field) do { \ + QMD_SAVELINK(oldnext, (elm)->field.sle_next); \ + if (SLIST_FIRST((head)) == (elm)) { \ + SLIST_REMOVE_HEAD((head), field); \ + } \ + else { \ + QUEUE_TYPEOF(type) *curelm = SLIST_FIRST(head); \ + while (SLIST_NEXT(curelm, field) != (elm)) \ + curelm = SLIST_NEXT(curelm, field); \ + SLIST_REMOVE_AFTER(curelm, field); \ + } \ + TRASHIT(*oldnext); \ +} while (0) + +#define SLIST_REMOVE_AFTER(elm, field) do { \ + SLIST_NEXT(elm, field) = \ + SLIST_NEXT(SLIST_NEXT(elm, field), field); \ +} while (0) + +#define SLIST_REMOVE_HEAD(head, field) do { \ + SLIST_FIRST((head)) = SLIST_NEXT(SLIST_FIRST((head)), field); \ +} while (0) + +#define SLIST_REMOVE_PREVPTR(prevp, elm, field) do { \ + QMD_SLIST_CHECK_PREVPTR(prevp, elm); \ + *(prevp) = SLIST_NEXT(elm, field); \ + TRASHIT((elm)->field.sle_next); \ +} while (0) + +#define SLIST_SWAP(head1, head2, type) do { \ + QUEUE_TYPEOF(type) *swap_first = SLIST_FIRST(head1); \ + SLIST_FIRST(head1) = SLIST_FIRST(head2); \ + SLIST_FIRST(head2) = swap_first; \ +} while (0) + +/* + * Singly-linked Tail queue declarations. + */ +#define STAILQ_HEAD(name, type) \ +struct name { \ + struct type *stqh_first;/* first element */ \ + struct type **stqh_last;/* addr of last next element */ \ +} + +#define STAILQ_CLASS_HEAD(name, type) \ +struct name { \ + class type *stqh_first; /* first element */ \ + class type **stqh_last; /* addr of last next element */ \ +} + +#define STAILQ_HEAD_INITIALIZER(head) \ + { NULL, &(head).stqh_first } + +#define STAILQ_ENTRY(type) \ +struct { \ + struct type *stqe_next; /* next element */ \ +} + +#define STAILQ_CLASS_ENTRY(type) \ +struct { \ + class type *stqe_next; /* next element */ \ +} + +/* + * Singly-linked Tail queue functions. + */ +#define STAILQ_CONCAT(head1, head2) do { \ + if (!STAILQ_EMPTY((head2))) { \ + *(head1)->stqh_last = (head2)->stqh_first; \ + (head1)->stqh_last = (head2)->stqh_last; \ + STAILQ_INIT((head2)); \ + } \ +} while (0) + +#define STAILQ_EMPTY(head) ((head)->stqh_first == NULL) + +#define STAILQ_FIRST(head) ((head)->stqh_first) + +#define STAILQ_FOREACH(var, head, field) \ + for((var) = STAILQ_FIRST((head)); \ + (var); \ + (var) = STAILQ_NEXT((var), field)) + +#define STAILQ_FOREACH_FROM(var, head, field) \ + for ((var) = ((var) ? (var) : STAILQ_FIRST((head))); \ + (var); \ + (var) = STAILQ_NEXT((var), field)) + +#define STAILQ_FOREACH_SAFE(var, head, field, tvar) \ + for ((var) = STAILQ_FIRST((head)); \ + (var) && ((tvar) = STAILQ_NEXT((var), field), 1); \ + (var) = (tvar)) + +#define STAILQ_FOREACH_FROM_SAFE(var, head, field, tvar) \ + for ((var) = ((var) ? (var) : STAILQ_FIRST((head))); \ + (var) && ((tvar) = STAILQ_NEXT((var), field), 1); \ + (var) = (tvar)) + +#define STAILQ_INIT(head) do { \ + STAILQ_FIRST((head)) = NULL; \ + (head)->stqh_last = &STAILQ_FIRST((head)); \ +} while (0) + +#define STAILQ_INSERT_AFTER(head, tqelm, elm, field) do { \ + if ((STAILQ_NEXT((elm), field) = STAILQ_NEXT((tqelm), field)) == NULL)\ + (head)->stqh_last = &STAILQ_NEXT((elm), field); \ + STAILQ_NEXT((tqelm), field) = (elm); \ +} while (0) + +#define STAILQ_INSERT_HEAD(head, elm, field) do { \ + if ((STAILQ_NEXT((elm), field) = STAILQ_FIRST((head))) == NULL) \ + (head)->stqh_last = &STAILQ_NEXT((elm), field); \ + STAILQ_FIRST((head)) = (elm); \ +} while (0) + +#define STAILQ_INSERT_TAIL(head, elm, field) do { \ + STAILQ_NEXT((elm), field) = NULL; \ + *(head)->stqh_last = (elm); \ + (head)->stqh_last = &STAILQ_NEXT((elm), field); \ +} while (0) + +#define STAILQ_LAST(head, type, field) \ + (STAILQ_EMPTY((head)) ? NULL : \ + __containerof((head)->stqh_last, \ + QUEUE_TYPEOF(type), field.stqe_next)) + +#define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next) + +#define STAILQ_REMOVE(head, elm, type, field) do { \ + QMD_SAVELINK(oldnext, (elm)->field.stqe_next); \ + if (STAILQ_FIRST((head)) == (elm)) { \ + STAILQ_REMOVE_HEAD((head), field); \ + } \ + else { \ + QUEUE_TYPEOF(type) *curelm = STAILQ_FIRST(head); \ + while (STAILQ_NEXT(curelm, field) != (elm)) \ + curelm = STAILQ_NEXT(curelm, field); \ + STAILQ_REMOVE_AFTER(head, curelm, field); \ + } \ + TRASHIT(*oldnext); \ +} while (0) + +#define STAILQ_REMOVE_AFTER(head, elm, field) do { \ + if ((STAILQ_NEXT(elm, field) = \ + STAILQ_NEXT(STAILQ_NEXT(elm, field), field)) == NULL) \ + (head)->stqh_last = &STAILQ_NEXT((elm), field); \ +} while (0) + +#define STAILQ_REMOVE_HEAD(head, field) do { \ + if ((STAILQ_FIRST((head)) = \ + STAILQ_NEXT(STAILQ_FIRST((head)), field)) == NULL) \ + (head)->stqh_last = &STAILQ_FIRST((head)); \ +} while (0) + +#define STAILQ_SWAP(head1, head2, type) do { \ + QUEUE_TYPEOF(type) *swap_first = STAILQ_FIRST(head1); \ + QUEUE_TYPEOF(type) **swap_last = (head1)->stqh_last; \ + STAILQ_FIRST(head1) = STAILQ_FIRST(head2); \ + (head1)->stqh_last = (head2)->stqh_last; \ + STAILQ_FIRST(head2) = swap_first; \ + (head2)->stqh_last = swap_last; \ + if (STAILQ_EMPTY(head1)) \ + (head1)->stqh_last = &STAILQ_FIRST(head1); \ + if (STAILQ_EMPTY(head2)) \ + (head2)->stqh_last = &STAILQ_FIRST(head2); \ +} while (0) + + +/* + * List declarations. + */ +#define LIST_HEAD(name, type) \ +struct name { \ + struct type *lh_first; /* first element */ \ +} + +#define LIST_CLASS_HEAD(name, type) \ +struct name { \ + class type *lh_first; /* first element */ \ +} + +#define LIST_HEAD_INITIALIZER(head) \ + { NULL } + +#define LIST_ENTRY(type) \ +struct { \ + struct type *le_next; /* next element */ \ + struct type **le_prev; /* address of previous next element */ \ +} + +#define LIST_CLASS_ENTRY(type) \ +struct { \ + class type *le_next; /* next element */ \ + class type **le_prev; /* address of previous next element */ \ +} + +/* + * List functions. + */ + +#if (defined(_KERNEL) && defined(INVARIANTS)) +/* + * QMD_LIST_CHECK_HEAD(LIST_HEAD *head, LIST_ENTRY NAME) + * + * If the list is non-empty, validates that the first element of the list + * points back at 'head.' + */ +#define QMD_LIST_CHECK_HEAD(head, field) do { \ + if (LIST_FIRST((head)) != NULL && \ + LIST_FIRST((head))->field.le_prev != \ + &LIST_FIRST((head))) \ + panic("Bad list head %p first->prev != head", (head)); \ +} while (0) + +/* + * QMD_LIST_CHECK_NEXT(TYPE *elm, LIST_ENTRY NAME) + * + * If an element follows 'elm' in the list, validates that the next element + * points back at 'elm.' + */ +#define QMD_LIST_CHECK_NEXT(elm, field) do { \ + if (LIST_NEXT((elm), field) != NULL && \ + LIST_NEXT((elm), field)->field.le_prev != \ + &((elm)->field.le_next)) \ + panic("Bad link elm %p next->prev != elm", (elm)); \ +} while (0) + +/* + * QMD_LIST_CHECK_PREV(TYPE *elm, LIST_ENTRY NAME) + * + * Validates that the previous element (or head of the list) points to 'elm.' + */ +#define QMD_LIST_CHECK_PREV(elm, field) do { \ + if (*(elm)->field.le_prev != (elm)) \ + panic("Bad link elm %p prev->next != elm", (elm)); \ +} while (0) +#else +#define QMD_LIST_CHECK_HEAD(head, field) +#define QMD_LIST_CHECK_NEXT(elm, field) +#define QMD_LIST_CHECK_PREV(elm, field) +#endif /* (_KERNEL && INVARIANTS) */ + +#define LIST_CONCAT(head1, head2, type, field) do { \ + QUEUE_TYPEOF(type) *curelm = LIST_FIRST(head1); \ + if (curelm == NULL) { \ + if ((LIST_FIRST(head1) = LIST_FIRST(head2)) != NULL) { \ + LIST_FIRST(head2)->field.le_prev = \ + &LIST_FIRST((head1)); \ + LIST_INIT(head2); \ + } \ + } else if (LIST_FIRST(head2) != NULL) { \ + while (LIST_NEXT(curelm, field) != NULL) \ + curelm = LIST_NEXT(curelm, field); \ + LIST_NEXT(curelm, field) = LIST_FIRST(head2); \ + LIST_FIRST(head2)->field.le_prev = &LIST_NEXT(curelm, field); \ + LIST_INIT(head2); \ + } \ +} while (0) + +#define LIST_EMPTY(head) ((head)->lh_first == NULL) + +#define LIST_FIRST(head) ((head)->lh_first) + +#define LIST_FOREACH(var, head, field) \ + for ((var) = LIST_FIRST((head)); \ + (var); \ + (var) = LIST_NEXT((var), field)) + +#define LIST_FOREACH_FROM(var, head, field) \ + for ((var) = ((var) ? (var) : LIST_FIRST((head))); \ + (var); \ + (var) = LIST_NEXT((var), field)) + +#define LIST_FOREACH_SAFE(var, head, field, tvar) \ + for ((var) = LIST_FIRST((head)); \ + (var) && ((tvar) = LIST_NEXT((var), field), 1); \ + (var) = (tvar)) + +#define LIST_FOREACH_FROM_SAFE(var, head, field, tvar) \ + for ((var) = ((var) ? (var) : LIST_FIRST((head))); \ + (var) && ((tvar) = LIST_NEXT((var), field), 1); \ + (var) = (tvar)) + +#define LIST_INIT(head) do { \ + LIST_FIRST((head)) = NULL; \ +} while (0) + +#define LIST_INSERT_AFTER(listelm, elm, field) do { \ + QMD_LIST_CHECK_NEXT(listelm, field); \ + if ((LIST_NEXT((elm), field) = LIST_NEXT((listelm), field)) != NULL)\ + LIST_NEXT((listelm), field)->field.le_prev = \ + &LIST_NEXT((elm), field); \ + LIST_NEXT((listelm), field) = (elm); \ + (elm)->field.le_prev = &LIST_NEXT((listelm), field); \ +} while (0) + +#define LIST_INSERT_BEFORE(listelm, elm, field) do { \ + QMD_LIST_CHECK_PREV(listelm, field); \ + (elm)->field.le_prev = (listelm)->field.le_prev; \ + LIST_NEXT((elm), field) = (listelm); \ + *(listelm)->field.le_prev = (elm); \ + (listelm)->field.le_prev = &LIST_NEXT((elm), field); \ +} while (0) + +#define LIST_INSERT_HEAD(head, elm, field) do { \ + QMD_LIST_CHECK_HEAD((head), field); \ + if ((LIST_NEXT((elm), field) = LIST_FIRST((head))) != NULL) \ + LIST_FIRST((head))->field.le_prev = &LIST_NEXT((elm), field);\ + LIST_FIRST((head)) = (elm); \ + (elm)->field.le_prev = &LIST_FIRST((head)); \ +} while (0) + +#define LIST_NEXT(elm, field) ((elm)->field.le_next) + +#define LIST_PREV(elm, head, type, field) \ + ((elm)->field.le_prev == &LIST_FIRST((head)) ? NULL : \ + __containerof((elm)->field.le_prev, \ + QUEUE_TYPEOF(type), field.le_next)) + +#define LIST_REMOVE(elm, field) do { \ + QMD_SAVELINK(oldnext, (elm)->field.le_next); \ + QMD_SAVELINK(oldprev, (elm)->field.le_prev); \ + QMD_LIST_CHECK_NEXT(elm, field); \ + QMD_LIST_CHECK_PREV(elm, field); \ + if (LIST_NEXT((elm), field) != NULL) \ + LIST_NEXT((elm), field)->field.le_prev = \ + (elm)->field.le_prev; \ + *(elm)->field.le_prev = LIST_NEXT((elm), field); \ + TRASHIT(*oldnext); \ + TRASHIT(*oldprev); \ +} while (0) + +#define LIST_SWAP(head1, head2, type, field) do { \ + QUEUE_TYPEOF(type) *swap_tmp = LIST_FIRST(head1); \ + LIST_FIRST((head1)) = LIST_FIRST((head2)); \ + LIST_FIRST((head2)) = swap_tmp; \ + if ((swap_tmp = LIST_FIRST((head1))) != NULL) \ + swap_tmp->field.le_prev = &LIST_FIRST((head1)); \ + if ((swap_tmp = LIST_FIRST((head2))) != NULL) \ + swap_tmp->field.le_prev = &LIST_FIRST((head2)); \ +} while (0) + +/* + * Tail queue declarations. + */ +#define TAILQ_HEAD(name, type) \ +struct name { \ + struct type *tqh_first; /* first element */ \ + struct type **tqh_last; /* addr of last next element */ \ + TRACEBUF \ +} + +#define TAILQ_CLASS_HEAD(name, type) \ +struct name { \ + class type *tqh_first; /* first element */ \ + class type **tqh_last; /* addr of last next element */ \ + TRACEBUF \ +} + +#define TAILQ_HEAD_INITIALIZER(head) \ + { NULL, &(head).tqh_first, TRACEBUF_INITIALIZER } + +#define TAILQ_ENTRY(type) \ +struct { \ + struct type *tqe_next; /* next element */ \ + struct type **tqe_prev; /* address of previous next element */ \ + TRACEBUF \ +} + +#define TAILQ_CLASS_ENTRY(type) \ +struct { \ + class type *tqe_next; /* next element */ \ + class type **tqe_prev; /* address of previous next element */ \ + TRACEBUF \ +} + +/* + * Tail queue functions. + */ +#if (defined(_KERNEL) && defined(INVARIANTS)) +/* + * QMD_TAILQ_CHECK_HEAD(TAILQ_HEAD *head, TAILQ_ENTRY NAME) + * + * If the tailq is non-empty, validates that the first element of the tailq + * points back at 'head.' + */ +#define QMD_TAILQ_CHECK_HEAD(head, field) do { \ + if (!TAILQ_EMPTY(head) && \ + TAILQ_FIRST((head))->field.tqe_prev != \ + &TAILQ_FIRST((head))) \ + panic("Bad tailq head %p first->prev != head", (head)); \ +} while (0) + +/* + * QMD_TAILQ_CHECK_TAIL(TAILQ_HEAD *head, TAILQ_ENTRY NAME) + * + * Validates that the tail of the tailq is a pointer to pointer to NULL. + */ +#define QMD_TAILQ_CHECK_TAIL(head, field) do { \ + if (*(head)->tqh_last != NULL) \ + panic("Bad tailq NEXT(%p->tqh_last) != NULL", (head)); \ +} while (0) + +/* + * QMD_TAILQ_CHECK_NEXT(TYPE *elm, TAILQ_ENTRY NAME) + * + * If an element follows 'elm' in the tailq, validates that the next element + * points back at 'elm.' + */ +#define QMD_TAILQ_CHECK_NEXT(elm, field) do { \ + if (TAILQ_NEXT((elm), field) != NULL && \ + TAILQ_NEXT((elm), field)->field.tqe_prev != \ + &((elm)->field.tqe_next)) \ + panic("Bad link elm %p next->prev != elm", (elm)); \ +} while (0) + +/* + * QMD_TAILQ_CHECK_PREV(TYPE *elm, TAILQ_ENTRY NAME) + * + * Validates that the previous element (or head of the tailq) points to 'elm.' + */ +#define QMD_TAILQ_CHECK_PREV(elm, field) do { \ + if (*(elm)->field.tqe_prev != (elm)) \ + panic("Bad link elm %p prev->next != elm", (elm)); \ +} while (0) +#else +#define QMD_TAILQ_CHECK_HEAD(head, field) +#define QMD_TAILQ_CHECK_TAIL(head, headname) +#define QMD_TAILQ_CHECK_NEXT(elm, field) +#define QMD_TAILQ_CHECK_PREV(elm, field) +#endif /* (_KERNEL && INVARIANTS) */ + +#define TAILQ_CONCAT(head1, head2, field) do { \ + if (!TAILQ_EMPTY(head2)) { \ + *(head1)->tqh_last = (head2)->tqh_first; \ + (head2)->tqh_first->field.tqe_prev = (head1)->tqh_last; \ + (head1)->tqh_last = (head2)->tqh_last; \ + TAILQ_INIT((head2)); \ + QMD_TRACE_HEAD(head1); \ + QMD_TRACE_HEAD(head2); \ + } \ +} while (0) + +#define TAILQ_EMPTY(head) ((head)->tqh_first == NULL) + +#define TAILQ_FIRST(head) ((head)->tqh_first) + +#define TAILQ_FOREACH(var, head, field) \ + for ((var) = TAILQ_FIRST((head)); \ + (var); \ + (var) = TAILQ_NEXT((var), field)) + +#define TAILQ_FOREACH_FROM(var, head, field) \ + for ((var) = ((var) ? (var) : TAILQ_FIRST((head))); \ + (var); \ + (var) = TAILQ_NEXT((var), field)) + +#define TAILQ_FOREACH_SAFE(var, head, field, tvar) \ + for ((var) = TAILQ_FIRST((head)); \ + (var) && ((tvar) = TAILQ_NEXT((var), field), 1); \ + (var) = (tvar)) + +#define TAILQ_FOREACH_FROM_SAFE(var, head, field, tvar) \ + for ((var) = ((var) ? (var) : TAILQ_FIRST((head))); \ + (var) && ((tvar) = TAILQ_NEXT((var), field), 1); \ + (var) = (tvar)) + +#define TAILQ_FOREACH_REVERSE(var, head, headname, field) \ + for ((var) = TAILQ_LAST((head), headname); \ + (var); \ + (var) = TAILQ_PREV((var), headname, field)) + +#define TAILQ_FOREACH_REVERSE_FROM(var, head, headname, field) \ + for ((var) = ((var) ? (var) : TAILQ_LAST((head), headname)); \ + (var); \ + (var) = TAILQ_PREV((var), headname, field)) + +#define TAILQ_FOREACH_REVERSE_SAFE(var, head, headname, field, tvar) \ + for ((var) = TAILQ_LAST((head), headname); \ + (var) && ((tvar) = TAILQ_PREV((var), headname, field), 1); \ + (var) = (tvar)) + +#define TAILQ_FOREACH_REVERSE_FROM_SAFE(var, head, headname, field, tvar) \ + for ((var) = ((var) ? (var) : TAILQ_LAST((head), headname)); \ + (var) && ((tvar) = TAILQ_PREV((var), headname, field), 1); \ + (var) = (tvar)) + +#define TAILQ_INIT(head) do { \ + TAILQ_FIRST((head)) = NULL; \ + (head)->tqh_last = &TAILQ_FIRST((head)); \ + QMD_TRACE_HEAD(head); \ +} while (0) + +#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \ + QMD_TAILQ_CHECK_NEXT(listelm, field); \ + if ((TAILQ_NEXT((elm), field) = TAILQ_NEXT((listelm), field)) != NULL)\ + TAILQ_NEXT((elm), field)->field.tqe_prev = \ + &TAILQ_NEXT((elm), field); \ + else { \ + (head)->tqh_last = &TAILQ_NEXT((elm), field); \ + QMD_TRACE_HEAD(head); \ + } \ + TAILQ_NEXT((listelm), field) = (elm); \ + (elm)->field.tqe_prev = &TAILQ_NEXT((listelm), field); \ + QMD_TRACE_ELEM(&(elm)->field); \ + QMD_TRACE_ELEM(&(listelm)->field); \ +} while (0) + +#define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \ + QMD_TAILQ_CHECK_PREV(listelm, field); \ + (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \ + TAILQ_NEXT((elm), field) = (listelm); \ + *(listelm)->field.tqe_prev = (elm); \ + (listelm)->field.tqe_prev = &TAILQ_NEXT((elm), field); \ + QMD_TRACE_ELEM(&(elm)->field); \ + QMD_TRACE_ELEM(&(listelm)->field); \ +} while (0) + +#define TAILQ_INSERT_HEAD(head, elm, field) do { \ + QMD_TAILQ_CHECK_HEAD(head, field); \ + if ((TAILQ_NEXT((elm), field) = TAILQ_FIRST((head))) != NULL) \ + TAILQ_FIRST((head))->field.tqe_prev = \ + &TAILQ_NEXT((elm), field); \ + else \ + (head)->tqh_last = &TAILQ_NEXT((elm), field); \ + TAILQ_FIRST((head)) = (elm); \ + (elm)->field.tqe_prev = &TAILQ_FIRST((head)); \ + QMD_TRACE_HEAD(head); \ + QMD_TRACE_ELEM(&(elm)->field); \ +} while (0) + +#define TAILQ_INSERT_TAIL(head, elm, field) do { \ + QMD_TAILQ_CHECK_TAIL(head, field); \ + TAILQ_NEXT((elm), field) = NULL; \ + (elm)->field.tqe_prev = (head)->tqh_last; \ + *(head)->tqh_last = (elm); \ + (head)->tqh_last = &TAILQ_NEXT((elm), field); \ + QMD_TRACE_HEAD(head); \ + QMD_TRACE_ELEM(&(elm)->field); \ +} while (0) + +#define TAILQ_LAST(head, headname) \ + (*(((struct headname *)((head)->tqh_last))->tqh_last)) + +#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next) + +#define TAILQ_PREV(elm, headname, field) \ + (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last)) + +#define TAILQ_REMOVE(head, elm, field) do { \ + QMD_SAVELINK(oldnext, (elm)->field.tqe_next); \ + QMD_SAVELINK(oldprev, (elm)->field.tqe_prev); \ + QMD_TAILQ_CHECK_NEXT(elm, field); \ + QMD_TAILQ_CHECK_PREV(elm, field); \ + if ((TAILQ_NEXT((elm), field)) != NULL) \ + TAILQ_NEXT((elm), field)->field.tqe_prev = \ + (elm)->field.tqe_prev; \ + else { \ + (head)->tqh_last = (elm)->field.tqe_prev; \ + QMD_TRACE_HEAD(head); \ + } \ + *(elm)->field.tqe_prev = TAILQ_NEXT((elm), field); \ + TRASHIT(*oldnext); \ + TRASHIT(*oldprev); \ + QMD_TRACE_ELEM(&(elm)->field); \ +} while (0) + +#define TAILQ_SWAP(head1, head2, type, field) do { \ + QUEUE_TYPEOF(type) *swap_first = (head1)->tqh_first; \ + QUEUE_TYPEOF(type) **swap_last = (head1)->tqh_last; \ + (head1)->tqh_first = (head2)->tqh_first; \ + (head1)->tqh_last = (head2)->tqh_last; \ + (head2)->tqh_first = swap_first; \ + (head2)->tqh_last = swap_last; \ + if ((swap_first = (head1)->tqh_first) != NULL) \ + swap_first->field.tqe_prev = &(head1)->tqh_first; \ + else \ + (head1)->tqh_last = &(head1)->tqh_first; \ + if ((swap_first = (head2)->tqh_first) != NULL) \ + swap_first->field.tqe_prev = &(head2)->tqh_first; \ + else \ + (head2)->tqh_last = &(head2)->tqh_first; \ +} while (0) + +#endif /* !_SYS_QUEUE_H_ */ diff --git a/libmish/src/fifo_declare.h b/libmish/src/fifo_declare.h new file mode 100644 index 0000000..73706a5 --- /dev/null +++ b/libmish/src/fifo_declare.h @@ -0,0 +1,211 @@ +/* + fido_declare.h + Copyright (C) 2003-2012 Michel Pollet + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +/* + * FIFO helpers, aka circular buffers + * + * these macros define accessories for FIFOs of any name, type and + * any (power of two) size + */ + +#ifndef __FIFO_DECLARE__ +#define __FIFO_DECLARE__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* + doing a : + DECLARE_FIFO(uint8_t, myfifo, 128); + + will declare : + enum : myfifo_overflow_f + type : myfifo_t + functions: + // write a byte into the fifo, return 1 if there was room, 0 if there wasn't + int myfifo_write(myfifo_t *c, uint8_t b); + // reads a byte from the fifo, return 0 if empty. Use myfifo_isempty() to check beforehand + uint8_t myfifo_read(myfifo_t *c); + int myfifo_isfull(myfifo_t *c); + int myfifo_isempty(myfifo_t *c); + // returns number of items to read now + uint16_t myfifo_get_read_size(myfifo_t *c); + // read item at offset o from read cursor, no cursor advance + uint8_t myfifo_read_at(myfifo_t *c, uint16_t o); + // write b at offset o compared to current write cursor, no cursor advance + void myfifo_write_at(myfifo_t *c, uint16_t o, uint8_t b); + + In your .c you need to 'implement' the fifo: + DEFINE_FIFO(uint8_t, myfifo) + + To use the fifo, you must declare at least one : + myfifo_t fifo = FIFO_NULL; + + while (!myfifo_isfull(&fifo)) + myfifo_write(&fifo, 0xaa); + .... + while (!myfifo_isempty(&fifo)) + b = myfifo_read(&fifo); + */ + +#include + +#if __AVR__ +#define FIFO_CURSOR_TYPE uint8_t +#define FIFO_BOOL_TYPE char +#define FIFO_INLINE +#define FIFO_SYNC +#endif + +#ifndef FIFO_CURSOR_TYPE +#define FIFO_CURSOR_TYPE uint16_t +#endif +#ifndef FIFO_BOOL_TYPE +#define FIFO_BOOL_TYPE int +#endif +#ifndef FIFO_INLINE +#define FIFO_INLINE inline +#endif + +/* We should not need volatile */ +#ifndef FIFO_VOLATILE +#define FIFO_VOLATILE +#endif +#ifndef FIFO_SYNC +#define FIFO_SYNC __sync_synchronize() +#endif + +#ifndef FIFO_ZERO_INIT +#define FIFO_ZERO_INIT {0} +#endif +#define FIFO_NULL { FIFO_ZERO_INIT, 0, 0, 0 } + +/* New compilers don't like unused static functions. However, + * we do like 'static inlines' for these small accessors, + * so we mark them as 'unused'. It stops it complaining */ +#ifdef __GNUC__ +#define FIFO_DECL static __attribute__ ((unused)) +#else +#define FIFO_DECL static +#endif + +#define DECLARE_FIFO(__type, __name, __size) \ +enum { __name##_overflow_f = (1 << 0) }; \ +enum { __name##_fifo_size = (__size) }; \ +typedef struct __name##_t { \ + __type buffer[__name##_fifo_size]; \ + FIFO_VOLATILE FIFO_CURSOR_TYPE read; \ + FIFO_VOLATILE FIFO_CURSOR_TYPE write; \ + FIFO_VOLATILE uint8_t flags; \ +} __name##_t + +/* + * This allow declaring a FIFO without the functions that use + * pass-by-value arguments. The compiler isn't too happy using + * some of the variable length array these days and outputs a warning. + * Also, it is not efficient, so if your FIFO member is a big struct, + * you should use the pass by pointer instead. + */ +#define DEFINE_PTR_FIFO(__type, __name) \ +FIFO_DECL FIFO_INLINE FIFO_BOOL_TYPE __name##_isfull(__name##_t *c)\ +{\ + FIFO_CURSOR_TYPE next = (c->write + 1) & (__name##_fifo_size-1);\ + return c->read == next;\ +}\ +FIFO_DECL FIFO_INLINE FIFO_BOOL_TYPE __name##_isempty(__name##_t * c)\ +{\ + return c->read == c->write;\ +}\ +FIFO_DECL FIFO_INLINE FIFO_CURSOR_TYPE __name##_get_read_size(__name##_t *c)\ +{\ + return ((c->write + __name##_fifo_size) - c->read) & (__name##_fifo_size-1);\ +}\ +FIFO_DECL FIFO_INLINE FIFO_CURSOR_TYPE __name##_get_write_size(__name##_t *c)\ +{\ + return (__name##_fifo_size-1) - __name##_get_read_size(c);\ +}\ +FIFO_DECL FIFO_INLINE void __name##_read_offset(__name##_t *c, FIFO_CURSOR_TYPE o)\ +{\ + FIFO_SYNC; \ + c->read = (c->read + o) & (__name##_fifo_size-1);\ +}\ +FIFO_DECL FIFO_INLINE void __name##_write_offset(__name##_t *c, FIFO_CURSOR_TYPE o)\ +{\ + FIFO_SYNC; \ + c->write = (c->write + o) & (__name##_fifo_size-1);\ +}\ +FIFO_DECL FIFO_INLINE void __name##_reset(__name##_t *c)\ +{\ + FIFO_SYNC; \ + c->read = c->write = c->flags = 0;\ +}\ +FIFO_DECL FIFO_INLINE __type * __name##_write_ptr(__name##_t * c) \ +{\ + return c->buffer + c->write;\ +}\ +FIFO_DECL FIFO_INLINE __type * __name##_read_ptr(__name##_t * c) \ +{\ + return c->buffer + c->read;\ +}\ +struct __name##_t + +/* + * And this declares the whole FIFO, including the pass-by-value functions + */ +#define DEFINE_FIFO(__type, __name) \ +DEFINE_PTR_FIFO(__type, __name); \ +FIFO_DECL FIFO_INLINE FIFO_BOOL_TYPE __name##_write(__name##_t * c, __type b)\ +{\ + FIFO_CURSOR_TYPE now = c->write;\ + FIFO_CURSOR_TYPE next = (now + 1) & (__name##_fifo_size-1);\ + if (c->read != next) { \ + c->buffer[now] = b;\ + FIFO_SYNC; \ + c->write = next;\ + return 1;\ + }\ + return 0;\ +}\ +FIFO_DECL FIFO_INLINE __type __name##_read(__name##_t * c)\ +{\ + __type res = FIFO_ZERO_INIT; \ + FIFO_CURSOR_TYPE read = c->read;\ + if (read == c->write)\ + return res;\ + res = c->buffer[read];\ + FIFO_SYNC; \ + c->read = (read + 1) & (__name##_fifo_size-1);\ + return res;\ +}\ +FIFO_DECL FIFO_INLINE __type __name##_read_at(__name##_t *c, FIFO_CURSOR_TYPE o)\ +{\ + return c->buffer[(c->read + o) & (__name##_fifo_size-1)];\ +}\ +FIFO_DECL FIFO_INLINE void __name##_write_at(__name##_t *c, FIFO_CURSOR_TYPE o, __type b)\ +{\ + c->buffer[(c->write + o) & (__name##_fifo_size-1)] = b;\ +}\ +struct __name##_t + +#ifdef __cplusplus +}; +#endif + +#endif diff --git a/libmish/src/minipt.h b/libmish/src/minipt.h new file mode 100644 index 0000000..8ca7d21 --- /dev/null +++ b/libmish/src/minipt.h @@ -0,0 +1,138 @@ +/* + * minipt.h + * + * Created on: 1 Apr 2018 + * Copyright (C) 2020 Michel Pollet + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef MPTOOLS_INCLUDE_MINIPT_H_ +#define MPTOOLS_INCLUDE_MINIPT_H_ + +/* + * Mini Protothread. + * + * A thread or a coroutine would use a stack; this won't, + * Use an old gcc trick of being able to goto and indirect label. + * There are a few caveats: no persistent local variables, as you can't + * have a consistent stack frame. It's easy to work around tho. + */ +#define _CONCAT2(s1, s2) s1##s2 +#define _CONCAT(s1, s2) _CONCAT2(s1, s2) + +/* this wierd thing with the union is for gcc 12, which doesn't like us + * storing the address of a 'local variable' (which is the label!) */ +static inline void _set_gcc_ptr_workaround(void **d, void *s) { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdangling-pointer" + *d = s; +#pragma GCC diagnostic pop +} +#define pt_start(_pt) do { \ + if (_pt) goto *_pt; \ + } while (0); +#define pt_end(_pt) do { \ + (_pt) = NULL; \ + _pt_exit: ; \ + } while(0); +#define pt_yield(_pt) do { \ + _set_gcc_ptr_workaround(&(_pt), &&_CONCAT(_label, __LINE__));\ + goto _pt_exit;\ + _CONCAT(_label, __LINE__): ; \ + } while (0); + +#define pt_wait(_pt, _condition) do { \ + while (!(_condition)) \ + pt_yield(_pt); \ + } while (0); + + +#ifdef NEVER +/* + * This version is superior as it allows calling functions and keeping + * a context, but I never actually had a /need/ for this, yet + */ + +struct pt_t { + unsigned int sp; + void * st[32]; + void * ctx[32]; +} pt_t; + +#define pt_start(_pt) do { \ + if ((_pt)->st[(_pt)->sp]) goto *((_pt)->st[(_pt)->sp]); \ + } while (0); +#define pt_end(_pt) do { (_pt)->st[(_pt)->sp] = NULL; return; } while(0); +#define pt_yield(_pt) do { \ + (_pt)->st[(_pt)->sp] = &&_CONCAT(_label, __LINE__);\ + return;\ + _CONCAT(_label, __LINE__): ; \ + } while (0); +#define pt_wait(_pt, _condition) do { \ + while (!(_condition)) \ + pt_yield(_pt); \ + } while (0); +#define pt_call(_pt, _func) do { \ + (_pt)->sp++; \ + (_pt)->st[(_pt)->sp] = NULL; \ + do { \ + _func(_pt); \ + } while ((_pt)->st[(_pt)->sp]); \ + (_pt)->sp--; \ + } while (0); +#define pt_ctx(_pt) ((_pt)->ctx[(_pt)->sp]) + +void my_minit_func(struct pt_t * p) { + pt_start(p); + pt_ctx(p) = calloc(1, sizeof(int)); + printf("%s start %p\n", __func__, pt_ctx(p)); + pt_yield(p); + int * ctx = pt_ctx(p); + printf("%s loop %p\n", __func__, pt_ctx(p)); + for (; *ctx < 10; ctx[0]++) { + printf(" loop %d\n", *ctx); + pt_yield(p); + ctx = pt_ctx(p); + } + printf("%s done %p\n", __func__, pt_ctx(p)); + free(pt_ctx(p)); + pt_ctx(p) = NULL; + pt_end(p); +} + +void my_minit(struct pt_t * p) { + pt_start(p); + printf("%s start\n", __func__); + pt_call(p, my_minit_func); + printf("%s done\n", __func__); + pt_end(p); +} + +int main() { + struct pt_t pt = {}; + + pt_call(&pt, my_minit); +} +/* +tcc -run pt_call_test.c +my_minit start +my_minit_func start 0x555a68d970b0 +my_minit_func loop 0x555a68d970b0 + loop 0 + loop 1 + loop 2 + loop 3 + loop 4 + loop 5 + loop 6 + loop 7 + loop 8 + loop 9 +my_minit_func done 0x555a68d970b0 +my_minit done +*/ + +#endif // NEVER + +#endif /* MPTOOLS_INCLUDE_MINIPT_H_ */ diff --git a/libmish/src/mish.h b/libmish/src/mish.h new file mode 100644 index 0000000..d12e4d4 --- /dev/null +++ b/libmish/src/mish.h @@ -0,0 +1,113 @@ +/* + * mish.h + * + * Copyright (C) 2020 Michel Pollet + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef LIBMISH_SRC_MISH_H_ +#define LIBMISH_SRC_MISH_H_ + +#ifndef _LIBMISH_HAS_CMD_HANDLER_ +/* + * If you register with a non NULL parameter, you get that, otherwise + * you get an (opaque) mish_client_p + */ +typedef void (*mish_cmd_handler_p)( + void * param, + int argc, + const char *argv[]); +#endif + +enum { + MISH_CAP_NO_STDERR = (1 << 0), + MISH_CAP_NO_TELNET = (1 << 2), + MISH_CAP_FORCE_PTY = (1 << 1), +}; + +/*! + * Starts the mish thread, recover the stdout/err discriptor, and starts + * displaying a prompt for your process. + */ +struct mish_t * +mish_prepare( + unsigned long caps ); +//! Returns the flags you passed to mish_prepare() +unsigned long +mish_get_flags( + struct mish_t * m); +/*! + * This is normally called automatically at exit() time + */ +void +mish_terminate( + struct mish_t * m); + +/* + * Register a command; please use the macros, don't call this directly. + * + * Symbol is weak, so you can have mish commands in a dynamic library, + * without having to drag libmish into programs that use it; the commands + * won't register, but if you then link with a program that uses libmish, + * they will. + */ +void +mish_register_cmd( + const char ** cmd_names, + const char ** cmd_help, + mish_cmd_handler_p cmd_handler, + void * handler_param, + int safe) __attribute__((weak)); +/*! + * Poll the mish threads for pending commands, and call their handlers. + * This is only necessary for 'safe' commands that needs to be run on the + * main thread + */ +int +mish_cmd_poll(); + +/* + * This is how to add a command to your program: + * + * #include + * + * static void _my_command(void * yours, int argc, const char * argv[] ) { + * // do something here, like in main() + * } + * + * MISH_CMD_NAMES(_my_cmd, "cmd", "cmd_alias"); + * MISH_CMD_HELP(_my_cmd, "Short help one liner", "Extra help for help ") + * MISH_CMD_REGISTER(_my_cmd, _my_command); + * + * That's it! + */ + +#define MISH_CMD_NAMES(_n, args...) \ + static const char * _cmd_##_n[] = { args, 0 } +#define MISH_CMD_HELP(_n, args...) \ + static const char * _help_##_n[] = { args, 0 } +/* This gymnastic is required becase GCC has decided that it'll ignore + * ((weak)) symbols can be NULL, and throw me an error instead */ +static inline int _gcc_warning_false_pos_workaround(void * func) { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Waddress" + return func != NULL; +#pragma GCC diagnostic pop +} +//! These are called on libmish thread, immediately. +#define MISH_CMD_REGISTER(_d, _handler) \ + __attribute__((constructor,used)) \ + static void _mish_register_##_d() { \ + if (_gcc_warning_false_pos_workaround(mish_register_cmd)) \ + mish_register_cmd(_cmd_##_d,_help_##_d,_handler,0,0);\ + } +//! These are called when the main program calls mish_cmd_poll() +#define MISH_CMD_REGISTER_SAFE(_d, _handler) \ + __attribute__((constructor,used)) \ + static void _mish_register_##_d() { \ + if (_gcc_warning_false_pos_workaround(mish_register_cmd)) \ + mish_register_cmd(_cmd_##_d,_help_##_d,_handler,0,1);\ + } + +#endif /* LIBMISH_SRC_MISH_H_ */ diff --git a/libmish/src/mish_capture_select.c b/libmish/src/mish_capture_select.c new file mode 100644 index 0000000..cdde25a --- /dev/null +++ b/libmish/src/mish_capture_select.c @@ -0,0 +1,86 @@ +/* + * mish_capture_select.c + * + * Copyright (C) 2020 Michel Pollet + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include "mish_priv.h" +#include "mish.h" + +/* + * This is a select() based capture thread, it's not /ideal/ in terms of + * performances, but it's portable and should work on OSX/BSD Linux etc. + */ +void * +_mish_capture_select( + void *param) +{ + mish_p m = param; + + while (!(m->flags & MISH_QUIT)) { + mish_client_p c; + /* + * Call each client state machine, handle new output, + * new input, draw prompts etc etc. + * Also allow clients to tweak their 'output request' flag here + */ + TAILQ_FOREACH(c, &m->clients, self) + c->cr.process(m, c); + + fd_set r = m->select.read; + fd_set w = m->select.write; + struct timeval tv = { .tv_sec = 1 }; + int max = select(m->select.max, &r, &w, NULL, &tv); + if (max == 0) + continue; + if (max == -1) { + if (errno == EINTR || errno == EAGAIN) + continue; + // real error here? + continue; + } + /* check the telnet listen socket */ + mish_telnet_in_check(m, &r); + /* + * Get any input from the original terminals, it has been split + * into lines already and queue all into the main backlog. + */ + for (int i = 0; i < 1 + !(m->flags & MISH_CAP_NO_STDERR); i++) { + _mish_input_read(m, &r, &m->origin[i]); + + mish_line_p l; + while ((l = TAILQ_FIRST(&m->origin[i].backlog)) != NULL) { + l->err = i == 1; // mark stderr as such + TAILQ_REMOVE(&m->origin[i].backlog, l, self); + TAILQ_INSERT_TAIL(&m->backlog.log, l, self); + m->backlog.size++; + m->backlog.alloc += sizeof(*l) + l->size; + } + } + mish_client_p safe; + // check if any client has input, or was closed down, and remove them + TAILQ_FOREACH_SAFE(c, &m->clients, self, safe) { + _mish_input_read(m, &r, &c->input); + if (c->input.fd == -1 || (c->flags & MISH_CLIENT_DELETE)) + mish_client_delete(m, c); + } + } + if ((m->flags & MISH_CONSOLE_TTY) && + tcsetattr(0, TCSAFLUSH, &m->orig_termios)) + perror("thread tcsetattr"); + /* + * Try to be nice and tell all clients to cleanup + */ + mish_client_p c; + while ((c = TAILQ_FIRST(&m->clients)) != NULL) + mish_client_delete(m, c); + m->flags &= ~MISH_QUIT; + m->capture = 0; // mark the thread done + exit(0); // this calls mish_terminate, on main thread +// return NULL; +} diff --git a/libmish/src/mish_client.c b/libmish/src/mish_client.c new file mode 100644 index 0000000..1cd19cc --- /dev/null +++ b/libmish/src/mish_client.c @@ -0,0 +1,384 @@ +/* + * mish_client.c + * + * Copyright (C) 2020 Michel Pollet + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include +#include "mish_priv.h" +#include "mish.h" +#include "minipt.h" + + +mish_client_p +mish_client_new( + mish_p m, + int in, + int out, + int is_tty) +{ + mish_client_p c = (mish_client_p)calloc(1, sizeof(*c)); + + _mish_input_init(m, &c->input, in); + if (is_tty) { + c->input.process_char = _mish_client_vt_parse_input; + c->cr.process = _mish_client_interractive_cr; + } else { + c->cr.process = _mish_client_dumb_cr; + } + c->input.refcon = c; + c->output.fd = out; + c->mish = m; // pointer to parent + c->footer_height = 2; + /* + * Mark the in & out descriptors (could be the same, if a socket) + * as non blocking. + */ + int fds[2] = { in, out}; + for (int i = 0; i < 2; i++) { + int fd = fds[i]; + if (fd >= m->select.max - 1) + m->select.max = fd +1; + int flags = fcntl(fd, F_GETFL, NULL); + if (flags == 1) { + perror("mish: input F_GETFL"); + flags = 0; + } + if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1) + perror("mish: input F_SETFL"); + } + + TAILQ_INSERT_TAIL(&m->clients, c, self); + return c; +} + +void +mish_client_delete( + mish_p m, + mish_client_p c) +{ + /* + * Turn back synchronous IO here, I don't want to have to deal with EAGAIN + * when I'm actually trying to be nice and close as quickly as I can + */ + int fds[2] = { c->input.fd, c->output.fd }; + for (int i = 0; i < 2; i++) { + if (fds[i] == -1) + continue; + FD_CLR(fds[i], &m->select.read); + FD_CLR(fds[i], &m->select.write); + int flags; + if (fcntl(fds[i], F_GETFL, &flags) == 0) { + flags &= ~O_NONBLOCK; + if (fcntl(fds[i], F_SETFL, &flags)) + /* don't care */; + } + } + const char * restore = "\033[4l\033[;r\033[999;1H"; + if (write(c->output.fd, restore, strlen(restore))) + ; + close(c->output.fd); + + TAILQ_REMOVE(&m->clients, c, self); + if (c == m->console) + m->console = NULL; + _mish_input_clear(m, &c->input); + free(c); +} + +/* + * this calculates the number of glyphs in the prompt, it's needed + * so we know where to position the cursor when displaying the input line. + * Since prompt can have escape sequences like colors, or UTF8 glyphs + */ +static void +_mish_client_set_prompt( + mish_client_p c, + const char *p) +{ + if (p != c->prompt) + strncpy(c->prompt, p, sizeof(c->prompt)-1); + + mish_vt_sequence_t sq = {}; + char *s = c->prompt; + c->prompt_gc = 0; + while (*s) { + if (_mish_vt_sequence_char(&sq, *s)) + if (sq.glyph) + c->prompt_gc++; + s++; + } +} + +/* + * Remember, NO LOCALS in here -- this is a coroutine with no stack! + * + * Interactive 'client' prompt handling + */ +void +_mish_client_interractive_cr( + mish_p m, + mish_client_p c) +{ + pt_start(c->cr.state); + + if (c->input.is_telnet) + mish_telnet_send_init(c); + /* + * move cursor to 999;999 then asks the cursor position. That tells + * us the window size! (handy) + */ + _mish_send_queue(c, + "\033[999;999H\033[6n"); + while (_mish_send_flush(m, c)) + pt_yield(c->cr.state); + /* remember when we started */ + c->output.sqb->stamp = _mish_stamp_ms(); + /* Wait for the input handler to get the right sequence */ + /* can be either the terminal response OR the telnet sequence */ + while (!(c->flags & + (MISH_CLIENT_HAS_CURSOR_POS | MISH_CLIENT_HAS_WINDOW_SIZE)) && + (_mish_stamp_ms() - c->output.sqb->stamp) < (2 * 1000)) + pt_yield(c->cr.state); + + if (c->flags & MISH_CLIENT_HAS_CURSOR_POS) { + c->window_size.w = c->cursor_pos.x; + c->window_size.h = c->cursor_pos.y; + c->flags |= MISH_CLIENT_HAS_WINDOW_SIZE; + } + if (!(c->flags & MISH_CLIENT_HAS_WINDOW_SIZE)) { + printf("mish: no window size, falling back to dumb scrollback\n"); + c->cr.process = _mish_client_dumb_cr; + goto finish; + } + /* We are live scrolling, and we are at the last line of scrollback */ + c->flags |= MISH_CLIENT_INIT_SENT | MISH_CLIENT_SCROLLING; + c->bottom = TAILQ_LAST(&m->backlog.log, mish_line_queue_t); + /* + * This is where we arrive to draw the entire screen; to start up, + * and each time you do a control-l (TODO: or if the window is resized) + * Or use the scrollback (page Up/down etc) + */ +redraw: + c->flags |= MISH_CLIENT_UPDATE_PROMPT; + c->sending = c->bottom; + c->current_vpos = c->window_size.h - c->footer_height; + /* + * walk back from the 'bottom' line we want until we reach the top of the + * screen, or ran out of lines. + */ + while (c->sending && c->current_vpos >= 1) { + mish_line_p p = TAILQ_PREV(c->sending, mish_line_queue_t, self); + if (p) { + c->sending = p; + c->current_vpos--; + } else + break; + } + /* + * Now, we've just connected here, and there might be backlog, and we want + * just enough of that to fill our screen + */ + /* Set the scrolling region to all minus the 2 bottom lines */ + _mish_send_queue_fmt(c, "\033D\033[1;%dr", + c->window_size.h - c->footer_height); + _mish_send_queue_fmt(c, + "\033[%d;1H" + "\033[J", // clear to bottom of scrolling area + c->current_vpos); + do { + if (c->flags & MISH_CLIENT_UPDATE_WINDOW) { + c->flags &= ~MISH_CLIENT_UPDATE_WINDOW; + goto redraw; + } + /* + * If there isn't anything to send from the stdout/stderr, do + * prompt editing input handling. + */ + if (c->flags & MISH_CLIENT_UPDATE_PROMPT) { + c->flags &= ~MISH_CLIENT_UPDATE_PROMPT; + sprintf(c->prompt, ">>: "); + _mish_client_set_prompt(c, c->prompt); + + _mish_send_queue_fmt(c, + // "_" // draw a fake cursor and end of scrolling text + "\033[%d;1H" /* reposition the cursor to prompt area */ + "%s" // print prompt + "\033[J" // Clear to end of screen + "\033[4h", // Set insert mode + c->window_size.h - c->footer_height + 1, c->prompt); + if (c->cmd && c->cmd->len) { + _mish_send_queue_fmt(c, "%s", c->cmd->line); + /* if cursor is inside the line, move it back */ + if (c->cmd->len > c->cmd->done) + _mish_send_queue_fmt(c, "\033[%dD", + c->cmd->len - c->cmd->done); + } + } + /* + * Now, flush everything we had from the last iteration (inc prompt) + * from the scatter gather vector. + */ + if (c->output.count) { + while (_mish_send_flush(m, c)) + pt_yield(c->cr.state); + } else + pt_yield(c->cr.state); + + if (!c->sending) { + /* we're starting up, pool the backlog for a line to display */ + if (!c->bottom) { + c->bottom = TAILQ_LAST(&m->backlog.log, mish_line_queue_t); + c->sending = c->bottom; + } else { + // we WERE at the bottom, so find a possible next line + mish_line_p next = TAILQ_NEXT(c->bottom, self); + if (c->flags & MISH_CLIENT_SCROLLING) { + if (next) { + c->bottom = c->sending = next; + } + } + } + } + if (!c->sending) // bah, no new output, loop on + continue; + /* Remember you can't yield() until we're out of the while() loop */ + size_t start = c->output.total; + /* + * Now there is something to send, reposition the cursor in the + * scrolling area, and start sending backlog lines. + */ + _mish_send_queue_fmt(c, + "\033[s" /* Save cursor position (from the prompt area) */ + "\x8\033[%d;1H" /* pos cursor at bottom of scroll area */ + "\033[8l" /* replace mode */, + c->current_vpos); + /* + * Send until there's nothing else OR we sent a screen worth + * this allow a chance to service the input prompt + */ + size_t screen_worth = (c->window_size.h * c->window_size.w) / 1; + do { + if (c->sending->err) + _mish_send_queue(c, MISH_COLOR_RED); + _mish_send_queue_line(c, c->sending); + if (c->sending->err) + _mish_send_queue(c, "\033[m"); + // if we reach the bottom mark, stop + c->sending = c->sending == c->bottom ? + NULL : TAILQ_NEXT(c->sending, self); + } while (c->sending && + (c->output.total - start) <= screen_worth); + // update cursor position here -- SHOULD update it with each lines, + // to handle word wrapping, but for now it's OK + // TODO: Update cursor V pos handling line wrap + if (!c->sending) + c->current_vpos = c->window_size.h - c->footer_height; + /* Restore the cursor to the prompt area */ + _mish_send_queue(c, "\033[u"); + } while(1); +finish: + pt_end(c->cr.state); +} + +/* + * this is the dump pooler; just sends the lines, as is, as they appear. + * Still try to max up the buffer if possible, but that's about it. + */ +void +_mish_client_dumb_cr( + mish_p m, + mish_client_p c) +{ + pt_start(c->cr.state); + printf(MISH_COLOR_RED "mish: Started dumb console\n" MISH_COLOR_RESET); + do { + pt_yield(c->cr.state); + + if (!c->sending) { + /* we're starting up, pool the backlog for a line to display */ + if (!c->bottom) { + c->bottom = TAILQ_LAST(&m->backlog.log, mish_line_queue_t); + c->sending = c->bottom; + } else { + // we WERE at the bottom, so find a possible next line + mish_line_p next = TAILQ_NEXT(c->bottom, self); + if (next) { + c->sending = next; + c->bottom = TAILQ_LAST(&m->backlog.log, mish_line_queue_t); + } + } + } + if (!c->sending) // bah, no new output, loop on + continue; + + do { + _mish_send_queue_line(c, c->sending); + // if we reach the bottom mark, stop + c->sending = c->sending == c->bottom ? + NULL : TAILQ_NEXT(c->sending, self); + } while (c->sending); + + while (_mish_send_flush(m, c)) + pt_yield(c->cr.state); + } while(1); + + pt_end(c->cr.state); +} + +static void +_mish_cmd_history( + void * param, + int argc, + const char * argv[]) +{ + mish_client_p c = param; + mish_input_p in = &c->input; + mish_line_p l; + int i = 0; + TAILQ_FOREACH(l, &in->backlog, self) { + printf("%3d %s\n", i+1, l->line); + i++; + } + printf(MISH_COLOR_GREEN + "mish: %d history" + MISH_COLOR_RESET "\n", i); +} + +MISH_CMD_NAMES(history, "history"); +MISH_CMD_HELP(history, + "Display the history of commands."); +MISH_CMD_REGISTER(history, _mish_cmd_history); + + +static void +_mish_cmd_disconnect( + void * param, + int argc, + const char * argv[]) +{ + mish_client_p c = param; + + if (c == c->mish->console) { + printf(MISH_COLOR_RED + "mish: can't disconnect console" + MISH_COLOR_RESET "\n"); + return; + } + printf(MISH_COLOR_GREEN + "mish: telnet: logout" + MISH_COLOR_RESET "\n"); + c->flags |= MISH_CLIENT_DELETE; +} + +MISH_CMD_NAMES(disconnect, "dis", "disconnect", "logout"); +MISH_CMD_HELP(disconnect, + "Disconnect this telnet session. If appropriate"); +MISH_CMD_REGISTER(disconnect, _mish_cmd_disconnect); + diff --git a/libmish/src/mish_client_input.c b/libmish/src/mish_client_input.c new file mode 100644 index 0000000..b297fda --- /dev/null +++ b/libmish/src/mish_client_input.c @@ -0,0 +1,233 @@ +/* + * mish_client_input.c + * + * Copyright (C) 2020 Michel Pollet + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +#include "mish_priv.h" +#include "mish_priv_cmd.h" +#include "mish.h" + +/* + * Don't assume this handles every key combination in the world, it doesn't, + * it handles mostly the one I use most from bash! + * You like VI syntax, saaaaad story :-) + */ +//! Parse current input buffer +int +_mish_client_vt_parse_input( + struct mish_t *m, + struct mish_input_t *in, + uint8_t ich) +{ + mish_client_p c = in->refcon; + + /* + * if the sequence buffer is currently being flushed, we need to store + * the input until it's done. + * So lets store it into the input buffer, and once that output is finished + * we can process it as before. + */ + if (c->output.sqb->done) + return MISH_IN_STORE; + // now flush what was stored, plus the one we just received + for (int i = 0; i <= in->line->done; i++) { + uint8_t ch = i == in->line->done ? ich : in->line->line[i]; + + if (in->is_telnet) { + if (_mish_telnet_parse(c, ch)) + continue; + } + if (!_mish_vt_sequence_char(&c->vts, ch)) + continue; + // if no command is editing, create an empty one, add it to history + if (!c->cmd) { + _mish_line_reserve(&c->cmd, 4); + TAILQ_INSERT_TAIL(&in->backlog, c->cmd, self); + } else { + /* + * we need to detach the element if we're going to resize it, + * otherwise the list is completely fubar as the pointer changes + */ + if (c->cmd->size - c->cmd->len <= 4) { + mish_line_p next = TAILQ_NEXT(c->cmd, self); + TAILQ_REMOVE(&in->backlog, c->cmd, self); + _mish_line_reserve(&c->cmd, 4); + if (next) + TAILQ_INSERT_BEFORE(next, c->cmd, self); + else + TAILQ_INSERT_TAIL(&in->backlog, c->cmd, self); + } + } + switch (c->vts.seq) { + case MISH_VT_SEQ(CSI, '~'): { + mish_line_p cursor = c->bottom; + if (c->vts.p[0] == 1) // GNU screen HOME seq + goto kb_home; + else if (c->vts.p[0] == 4) // GNU screen END seq + goto kb_end; + if (c->vts.p[0] == 5) { // Page UP + for (int i = 0; i < c->window_size.h - 3 && cursor; i++) + cursor = TAILQ_PREV(cursor, mish_line_queue_t, self); + if (cursor) { + c->bottom = cursor; + c->flags |= MISH_CLIENT_UPDATE_WINDOW; + c->flags &= ~MISH_CLIENT_SCROLLING; + } + } else if (c->vts.p[0] == 6) { // down + for (int i = 0; i < c->window_size.h - 3 && cursor; i++) + cursor = TAILQ_NEXT(cursor, self); + c->bottom = cursor; + c->flags |= MISH_CLIENT_UPDATE_WINDOW; + if (!c->bottom) + c->flags |= MISH_CLIENT_SCROLLING; + } + } break; + case MISH_VT_SEQ(CSI, 'H'): { // Home +kb_home: + // don't bother if there's not enough backlog + if (m->backlog.size < c->window_size.h - 2) + break; + c->bottom = TAILQ_FIRST(&m->backlog.log); + for (i = 0; i < c->window_size.h - 2 - 1 && c->bottom; i++) + c->bottom = TAILQ_NEXT(c->bottom, self); + c->flags |= MISH_CLIENT_UPDATE_WINDOW; + if (c->bottom) + c->flags &= ~MISH_CLIENT_SCROLLING; + } break; + case MISH_VT_SEQ(CSI, 'F'): { // END +kb_end: + c->flags |= MISH_CLIENT_UPDATE_WINDOW | MISH_CLIENT_SCROLLING; + c->bottom = NULL; + } break; + case MISH_VT_SEQ(CSI, 'R'): + c->flags |= MISH_CLIENT_HAS_CURSOR_POS; + c->cursor_pos.y = c->vts.p[0]; + c->cursor_pos.x = c->vts.p[1]; + break; + case MISH_VT_SEQ(RAW, 16): { // CTRL-P Prev history + if (TAILQ_FIRST(&in->backlog) != c->cmd) { + c->flags |= MISH_CLIENT_UPDATE_PROMPT; + c->cmd = TAILQ_PREV(c->cmd, mish_line_queue_t, self); + } + } break; + case MISH_VT_SEQ(RAW, 14): // CTRL-N Next history + if (TAILQ_LAST(&in->backlog, mish_line_queue_t) != c->cmd) { + c->flags |= MISH_CLIENT_UPDATE_PROMPT; + c->cmd = TAILQ_NEXT(c->cmd, self); + } + break; + case MISH_VT_SEQ(RAW, 1): // CTRL-A Start of line + if (c->cmd->done) { + _mish_send_queue_fmt(c, "\033[%dD", c->cmd->done); + c->cmd->done = 0; + } + break; + case MISH_VT_SEQ(RAW, 5): // CTRL-E End of Line + if (c->cmd->done < c->cmd->len) { + _mish_send_queue_fmt(c, "\033[%dC", + c->cmd->len - c->cmd->done); + c->cmd->done = c->cmd->len; + } + break; + case MISH_VT_SEQ(RAW, 2): // CTRL-B Prev char + if (c->cmd->done) { + c->cmd->done--; + _mish_send_queue_fmt(c, "\033[%dD", 1); + } + break; + case MISH_VT_SEQ(RAW, 6): // CTRL-F Next Char + if (c->cmd->done < c->cmd->len) { + c->cmd->done++; + _mish_send_queue_fmt(c, "\033[%dC", 1); + } + break; + case MISH_VT_SEQ(RAW, 23): { // CTRL-W Delete prev word + int old_pos = c->cmd->done; + while (c->cmd->done && c->cmd->line[c->cmd->done-1] == ' ') + c->cmd->done--; + while (c->cmd->done && c->cmd->line[c->cmd->done-1] != ' ') + c->cmd->done--; + + if (old_pos - c->cmd->done) { + int del = old_pos - c->cmd->done; + memmove(c->cmd->line + c->cmd->done, + c->cmd->line + old_pos, + c->cmd->len - old_pos + 1); + c->cmd->len -= del; + // move back del characters, and delete them + _mish_send_queue_fmt(c, "\033[%dD\033[%dP", del, del); + } + } break; + case MISH_VT_SEQ(RAW, 0x7f): // DEL + case MISH_VT_SEQ(RAW, 8): // CTRL-H + if (c->cmd->done) { + c->cmd->done--; + memmove(c->cmd->line + c->cmd->done, + c->cmd->line + c->cmd->done + 1, + c->cmd->len - c->cmd->done + 1); + c->cmd->len--; + // backspace plus Delete (1) Character + _mish_send_queue(c, "\x8\033[P"); + } + break; + case MISH_VT_SEQ(RAW, 11): // CTRL-K Kill rest of line + c->cmd->len = c->cmd->done; + c->cmd->line[c->cmd->len] = 0; + _mish_send_queue(c, "\033[K"); + break; + case MISH_VT_SEQ(RAW, 12): // CTRL-L Redraw + c->flags |= MISH_CLIENT_UPDATE_WINDOW; + break; + case MISH_VT_SEQ(RAW, 13): // CTRL-M aka return + c->cmd->line[c->cmd->len] = 0; + if (0) { // debug + fprintf(stdout, "CMD: '%.*s", c->cmd->done, c->cmd->line); + fprintf(stdout, "\033[7m%.*s\033[0m", 1, + c->cmd->line + c->cmd->done); + if (c->cmd->done < c->cmd->len) + fprintf(stdout, "%s", c->cmd->line + c->cmd->done+1); + fprintf(stdout, "'\n"); + } + mish_cmd_call(c->cmd->line, c); + c->cmd = NULL; // new one + { // reuse the last empty one + mish_line_p last = TAILQ_LAST(&in->backlog, mish_line_queue_t); + if (last && last->len == 0) + c->cmd = last; + } + c->flags |= MISH_CLIENT_UPDATE_PROMPT; + break; + default: + if (c->vts.seq & ~0xff) { + printf(MISH_COLOR_RED + "mish: Unknown sequence: %08x ", c->vts.seq); + for (int i = 0; i < c->vts.pc; i++) + printf(":%d", c->vts.p[i]); + printf("'%c%c'", c->vts.seq >> 8, c->vts.seq & 0xff); + printf(MISH_COLOR_RESET "\n"); + } + break; + } + if (c->vts.glyph && c->vts.glyph >= ' ' && c->vts.glyph < 0x7f) { + memmove(c->cmd->line + c->cmd->done + 1, + c->cmd->line + c->cmd->done, + c->cmd->len - c->cmd->done); + c->cmd->line[c->cmd->done] = c->vts.glyph; + c->cmd->done++; + c->cmd->len++; + c->cmd->line[c->cmd->len] = 0; + // no need to explicitly insert, terminal should already be setup + _mish_send_queue_fmt(c, "%lc", c->vts.glyph); + } + } + // remove any buffered input. + in->line->len = 0; + return MISH_IN_SKIP; +} diff --git a/libmish/src/mish_cmd.c b/libmish/src/mish_cmd.c new file mode 100644 index 0000000..a4c9eed --- /dev/null +++ b/libmish/src/mish_cmd.c @@ -0,0 +1,307 @@ +/* + * mish_cmd.c + * + * Copyright (C) 2020 Michel Pollet + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include "mish_priv_cmd.h" +#include "mish_priv.h" +#include "mish.h" + +#include "fifo_declare.h" + + +#ifndef offsetof +#define offsetof(type, member) __builtin_offsetof (type, member) +#endif +#ifndef container_of +#define container_of(ptr, type, member) ({ \ + const char *__mptr = (const char *)(ptr); \ + (type *)(__mptr - offsetof(type, member) );}) +#endif + +typedef struct mish_cmd_t { + TAILQ_ENTRY(mish_cmd_t) self; + mish_cmd_handler_p cmd_cb; + void * param_cb; + uint32_t safe : 1; + + const char ** names; // list of aliases for the command + const char ** help; +} mish_cmd_t, *mish_cmd_p; + +typedef struct mish_cmd_call_t { + mish_cmd_p cmd; + char ** argv; + int argc; +} mish_cmd_call_t; + +DECLARE_FIFO(mish_cmd_call_t, mish_call_queue, 4); +DEFINE_FIFO(mish_cmd_call_t, mish_call_queue); + +static TAILQ_HEAD(,mish_cmd_t) _cmd_list = TAILQ_HEAD_INITIALIZER(_cmd_list); +static mish_call_queue_t _cmd_fifo = {0}; + +void __attribute__((weak)) +mish_register_cmd( + const char ** cmd_names, + const char ** cmd_help, + mish_cmd_handler_p cmd_handler, + void * handler_param, + int safe) +{ + if (!cmd_names || !cmd_help || !cmd_handler) { + fprintf(stderr, "%s invalid parameters\n", __func__); + return; + } + mish_cmd_p cmd = calloc(1, sizeof(*cmd)); + + cmd->names = cmd_names; + cmd->help = cmd_help; + cmd->cmd_cb = cmd_handler; + cmd->param_cb = handler_param; + cmd->safe = safe; + + // keep the list roughtly sorted + mish_cmd_p c, s; + TAILQ_FOREACH_SAFE(c, &_cmd_list, self, s) { + if (strcmp(cmd_names[0], c->names[0]) < 0) { + TAILQ_INSERT_BEFORE(c, cmd, self); + return; + } + } + TAILQ_INSERT_TAIL(&_cmd_list, cmd, self); +} + +/* + * Returns the length of the first word of cmd_line + */ +static int +first_word_length( + const char * cmd_line) +{ + const char *d = cmd_line; + while (*d && *d != ' ') + d++; + return d - cmd_line; +} + +mish_cmd_p +mish_cmd_lookup( + const char * cmd_line) +{ + if (!cmd_line) + return NULL; + int l = first_word_length(cmd_line); + mish_cmd_p cmd; + TAILQ_FOREACH(cmd, &_cmd_list, self) { + for (int i = 0; cmd->names && cmd->names[i]; i++) + if (!strncmp(cmd->names[i], cmd_line, l)) + return cmd; + } + return NULL; +} + +typedef struct _mish_argv_t { + char * line; + int ac; + char * av[0]; +} _mish_argv_t; + +/* + * Duplicate 'line', split it into words, store word pointers in an array, + * NULL terminate it. Also return the number of words in the array in argc. + * + * The returned value is made of two malloc()ed blocks. use mish_argv_free + * to free the memory. + * It's OK to change any of the pointers. But no not try to realloc() the + * vector as it hides a structure + */ +static char ** +mish_argv_make( + const char * line, + int * argc ) +{ + const char separator = ' '; + _mish_argv_t * r = calloc(1, sizeof(*r)); + r->line = strdup(line); + char *dup = r->line; + char quote; + enum { s_newarg = 0, s_startarg, s_copyquote, s_skip, s_copy }; + int state = s_newarg; + do { + switch (state) { + case s_newarg: + r = realloc(r, sizeof(*r) + ((r->ac + 2) * sizeof(char*))); + while (*dup == ' ' || *dup == separator) + dup++; + r->av[r->ac++] = dup; + state = s_startarg; + break; + case s_startarg: + if (*dup == '"' || *dup == '\'') { + quote = *dup++; + state = s_copyquote; + } else + state = s_copy; + break; + case s_copyquote: + if (*dup == '\\') + state = s_skip; + else if (*dup == quote) { + state = s_newarg; + dup++; + if (*dup) *dup++ = 0; + } else if (*dup) + dup++; + break; + case s_skip: + dup++; + state = s_copyquote; + break; + case s_copy: + if (*dup == 0) + break; + if (*dup != separator) + dup++; + else { + state = s_newarg; + if (*dup) *dup++ = 0; + } + break; + } + } while (*dup); + r->av[r->ac] = NULL; + if (argc) + *argc = r->ac; + return r->av; +} + +/* + * Free memory allocated by a mish_argv_make + */ +void +mish_argv_free( + char **_av) +{ + if (!_av) + return; + _mish_argv_t * r = container_of(_av, _mish_argv_t, av); + free((void*)r->line); + free((void*)r); +} + +int +mish_cmd_call( + const char * cmd_line, + void * c) +{ + if (!cmd_line || !*cmd_line) + return -1; + + mish_cmd_p cmd = mish_cmd_lookup(cmd_line); + if (!cmd) { + int l = first_word_length(cmd_line); + printf(MISH_COLOR_RED + "mish: '%.*s' not found. type 'help'." + MISH_COLOR_RESET "\n", + l, cmd_line); + return -1; + } + int ac = 0; + char ** av = mish_argv_make(cmd_line, &ac); + + if (cmd->safe) { + if (!mish_call_queue_isfull(&_cmd_fifo)) { + mish_cmd_call_t fe = { + .cmd = cmd, + .argv = av, + .argc = ac, + }; + mish_call_queue_write(&_cmd_fifo, fe); + } else { + fprintf(stderr, + "mish: cmd FIFO full, make sure to call mish_cmd_poll()!\n"); + } + } else { + cmd->cmd_cb(cmd->param_cb ? cmd->param_cb : c, ac, (const char**)av); + mish_argv_free(av); + } + return 0; +} + +int +mish_cmd_poll() +{ + int res = 0; + + while (!mish_call_queue_isempty(&_cmd_fifo)) { + mish_cmd_call_t c = mish_call_queue_read(&_cmd_fifo); + + c.cmd->cmd_cb( + c.cmd->param_cb, c.argc, (const char**)c.argv); + mish_argv_free(c.argv); + res++; + } + return res; +} + +static const char *_help[] = { + "A few of the typical EMACS keys work for editing commands.", + "like, ^A-^E, ^W, ^K - ^P,^N to navigate history and ^L to", + "redraw.", + "BEG/PGUP/DOWN/END to change the view of the backlog buffer.", + 0, +}; +static void +_mish_cmd_help( + void * param, + int argc, + const char * argv[]) +{ + mish_cmd_p cmd; + + if (argc < 2) { + printf(MISH_COLOR_GREEN "mish: Key binding\n"); + for (int i = 0; _help[i]; i++) + printf(" %s\n", _help[i]); + printf(MISH_COLOR_GREEN "List of commands\n"); + + TAILQ_FOREACH(cmd, &_cmd_list, self) { + printf(" "); + for (int i = 0; cmd->names && cmd->names[i]; i++) + printf("%s%s", i > 0 ? "," : "", cmd->names[i]); + printf(" - %s\n", cmd->help[0]); + } + printf(MISH_COLOR_RESET); + } else { + for (int i = 1; i < argc; i++) { + mish_cmd_p cmd = mish_cmd_lookup(argv[i]); + + if (!cmd) { + printf(MISH_COLOR_RED + "mish: Unknown command '%s'" + MISH_COLOR_RESET "\n", argv[i]); + continue; + } + printf(MISH_COLOR_GREEN); + for (int i = 0; cmd->names && cmd->names[i]; i++) + printf("%s%s", i > 0 ? "," : "", cmd->names[i]); + printf("\n"); + for (int i = 0; cmd->help && cmd->help[i]; i++) + printf(" %s\n", cmd->help[i]); + printf(MISH_COLOR_RESET); + } + } +} + +MISH_CMD_NAMES(help, "help"); +MISH_CMD_HELP(help, + "[cmd...] - Display command list, or help for commands", + "(optional) [cmd...] will display all the help for [cmd]"); +MISH_CMD_REGISTER(help, _mish_cmd_help); diff --git a/libmish/src/mish_cmd_env.c b/libmish/src/mish_cmd_env.c new file mode 100644 index 0000000..26dfa3c --- /dev/null +++ b/libmish/src/mish_cmd_env.c @@ -0,0 +1,72 @@ +/* + * mish_cmd_env.c + * + * Copyright (C) 2020 Michel Pollet + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include "mish.h" + +extern char ** environ; + +static void +_mish_cmd_env( + void * param, + int argc, + const char * argv[]) +{ + if (argc < 2) { + for (int i = 0; environ[i]; i++) + if (strncmp(environ[i], "LS_COLORS=", 10)) + printf("%s\n", environ[i]); + return; + } + for (int i = 0; environ[i]; i++) + for (int ei = 1; ei < argc; ei++) { + int l = strlen(argv[ei]); + if (!strncmp(environ[i], argv[ei], l)) + printf("%s\n", environ[i]); + } +} + +MISH_CMD_NAMES(env, "env"); +MISH_CMD_HELP(env, + "[names ...] display all environment, or variables", + "Apart from LS_COLORS: that is just spam.", + "If you specify names it'll just show the ones whose name", + "start with that prefix"); +MISH_CMD_REGISTER(env, _mish_cmd_env); + +static void +_mish_cmd_setenv( + void * param, + int argc, + const char * argv[]) +{ + for (int ei = 1; ei < argc; ei++) { + char *equal = strchr(argv[ei], '='); + if (!equal) { + printf("mish: setenv: '%s' requires an '='\n", argv[ei]); + return; + } + *equal++ = 0; + printf("mish: %s%s%s%s\n", *equal ? "" : "unset ", + argv[ei], *equal ? " = ": "", + *equal ? equal : ""); + if (!*equal) + unsetenv(argv[ei]); + else + setenv(argv[ei], equal, 1); + } +} + +MISH_CMD_NAMES(setenv, "setenv"); +MISH_CMD_HELP(setenv, + "[=...] set/clear environment variable(s)", + "Set to .. if is omitted, clears it.", + "The '=' is required, even when clearing."); +MISH_CMD_REGISTER(setenv, _mish_cmd_setenv); diff --git a/libmish/src/mish_input.c b/libmish/src/mish_input.c new file mode 100644 index 0000000..964c1d5 --- /dev/null +++ b/libmish/src/mish_input.c @@ -0,0 +1,139 @@ +/* + * mish_input.c + * + * Copyright (C) 2020 Michel Pollet + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include +#include +#include "mish_priv.h" +#include "mish_priv_line.h" + +#ifdef MISH_INPUT_TEST +#define D(_w) _w +#else +#define D(_w) +#endif + +void +_mish_input_init( + mish_p m, + mish_input_p in, + int fd) +{ + TAILQ_INIT(&in->backlog); +// fprintf(stderr, "%s %d\n", __func__, fd); + in->fd = fd; + in->line = NULL; + FD_SET(in->fd, &m->select.read); + if (in->fd >= m->select.max - 1) + m->select.max = in->fd +1; + + int flags = fcntl(fd, F_GETFL, NULL); + if (flags == 1) { + perror("mish: input F_GETFL"); + flags = 0; + } + if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1) + perror("mish: input F_SETFL"); +} + +void +_mish_input_clear( + mish_p m, + mish_input_p in) +{ + mish_line_p l; + while ((l = TAILQ_FIRST(&in->backlog)) != NULL) { + TAILQ_REMOVE(&in->backlog, l, self); + free(l); + } + if (in->line) + free(in->line); + in->line = NULL; + if (in->fd != -1) { + FD_CLR(in->fd, &m->select.read); + FD_CLR(in->fd, &m->select.write); + close(in->fd); + in->fd = -1; + } +} + +int +_mish_input_read( + mish_p m, + fd_set * fds, + mish_input_p in) +{ + if (!FD_ISSET(in->fd, fds)) + return 0; + do { + if (_mish_line_reserve(&in->line, 80)) { + D(printf(" reserve bailed us\n");) + break; + } + ssize_t rd = read(in->fd, + in->line->line + in->line->len, + in->line->size - in->line->len - 1); + if (rd == -1 && (errno == EWOULDBLOCK || errno == EAGAIN)) + break; + if (rd <= 0) { + close(in->fd); + FD_CLR(in->fd, &m->select.read); + FD_CLR(in->fd, &m->select.write); + in->fd = -1; + printf(MISH_COLOR_RED "mish: telnet: disconnected" + MISH_COLOR_RESET "\n"); + return -1; + } + in->line->len += rd; + } while (1); + uint8_t * s = (uint8_t*) in->line->line + in->line->done; + uint8_t * d = s; + int added = in->line->len - in->line->done; + D(printf(" buffer added %d done %d len %d size %d\n", added, + (int)in->line->done, (int)in->line->len, (int)in->line->size); + if (in->line->done) + printf(" buffer: '%.*s'\n", in->line->done, in->line->line);) + /* + * This loop re-parse the data, passes it to the optional handler, + * and then store processed lines into the backlog. This is not super + * optimal in the case there isn't a process_char() callback, so perhaps + * I should make another less 'generic' input parser that doesn't copy + * stuff around (in place, often). + */ + while (added) { + int r = MISH_IN_STORE; + if (in->process_char) + r = in->process_char(m, in, *s); + else + r = *s == '\n' ? MISH_IN_SPLIT : MISH_IN_STORE; + + if (r == MISH_IN_STORE || r == MISH_IN_SPLIT) { + *d++ = *s; + in->line->done++; + } + if (r == MISH_IN_SPLIT) { + D(printf(" split size %d remains %d : '%.*s'\n", in->line->done, + (int)added, in->line->done-1, in->line->line);) + _mish_line_add(&in->backlog, in->line->line, in->line->done); + d = (uint8_t*)in->line->line; + in->line->len = in->line->done = 0; + } + s++; added--; + } + *d = 0; // NUL terminate for debug purpose! + D(printf(" exit added %d done %d len %d size %d\n", added, + (int)in->line->done, (int)in->line->len, (int)in->line->size); + in->line->len = in->line->done; + if (in->line->done) + printf(" buffer: '%s'\n", in->line->line);) + + return TAILQ_FIRST(&in->backlog) != NULL; +} diff --git a/libmish/src/mish_line.c b/libmish/src/mish_line.c new file mode 100644 index 0000000..69b17bb --- /dev/null +++ b/libmish/src/mish_line.c @@ -0,0 +1,59 @@ +/* + * mish_line.c + * + * Copyright (C) 2020 Michel Pollet + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include "mish_priv.h" +#include "mish_priv_line.h" + +static const mish_line_t zero = {}; + +mish_line_p +_mish_line_add( + mish_line_queue_t * q, + char * buffer, + size_t length ) +{ + size_t l = length + 1; + mish_line_p nl = (mish_line_p)malloc(sizeof(*nl) + l); + *nl = zero; + nl->size = l; + nl->len = length; + memcpy(nl->line, buffer, length); + nl->line[l] = 0; + nl->stamp = _mish_stamp_ms(); + TAILQ_INSERT_TAIL(q, nl, self); + return nl; +} + +int +_mish_line_reserve( + mish_line_p *line, + uint32_t count) +{ + if (!line) + return -1; + mish_line_p l = *line; + if (count < 40) + count = 40; + if (!l) { + l = (mish_line_p)calloc(1, sizeof(mish_line_t) + count); + *l = zero; + l->size = count; + *line = l; + } + if (l->size + count >= MISH_MAX_LINE_SIZE) + return 1; + if (l->size - l->len < count) { + l = (mish_line_p)realloc(l, + sizeof(mish_line_t) + l->size + count); + l->size += count; + *line = l; + } + return 0; +} diff --git a/libmish/src/mish_priv.h b/libmish/src/mish_priv.h new file mode 100644 index 0000000..1509ae3 --- /dev/null +++ b/libmish/src/mish_priv.h @@ -0,0 +1,273 @@ +/* + * mish_priv.h + * + * Copyright (C) 2020 Michel Pollet + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef LIBMISH_SRC_MISH_PRIV_H_ +#define LIBMISH_SRC_MISH_PRIV_H_ + +#include +#include +#include +#include +#include "bsd_queue.h" +#include "mish_priv_vt.h" +#include "mish_priv_line.h" + +struct mish_t; + +/* + * The process_char callback of mish_input_t returns one of these. + */ +enum { + MISH_IN_SKIP = 0, // skip current character (don't store) + MISH_IN_STORE, // store current character in input buffer + MISH_IN_SPLIT, // store current line, add it to backlog +}; + +/* + * This receives stuff from a file descriptor, 'processes' it, and split it + * into lines to eventually store new lines into the 'backlog'. + */ +typedef struct mish_input_t { + // lines read from fd are queued in here when \n has been received + mish_line_queue_t backlog; + uint32_t is_telnet : 1, flush_on_nl : 1; + + // return 1 for the character to be stored, 0 for it to be skipped + int (*process_char)( + struct mish_t *m, + struct mish_input_t *i, + uint8_t ch); + void * refcon; // reference constant, for the callbacks + int fd; + mish_line_p line; +} mish_input_t, *mish_input_p; + +/* various internal states for the client */ +enum { + MISH_CLIENT_INIT_SENT = (1 << 0), + MISH_CLIENT_HAS_WINDOW_SIZE = (1 << 1), + MISH_CLIENT_HAS_CURSOR_POS = (1 << 2), + MISH_CLIENT_UPDATE_PROMPT = (1 << 3), + MISH_CLIENT_UPDATE_WINDOW = (1 << 4), + MISH_CLIENT_SCROLLING = (1 << 5), + MISH_CLIENT_DELETE = (1 << 6), +}; + +typedef struct mish_client_t { + TAILQ_ENTRY(mish_client_t) self; + struct mish_t * mish; + uint32_t flags; + + // "coroutine" processing received lines from the stdout/err + struct { + void * state; // state for the prompt coroutine + // _mish_client_interractive_cr() or _mish_client_dumb_cr() + void (*process)( + struct mish_t * m, + struct mish_client_t* c); + } cr; + int footer_height; // # static lines at bottom of screen + int current_vpos; + mish_line_p bottom; + // Line we are currently sending (or NULL) + mish_line_p sending; + + /* + * Output sent to the client is made of bits we want to send to move + * the cursor and so on, and, the actual lines we captured from the program. + * So a vector list is built as the output is built, and it's made of bits + * we've copied in "sqb" as well as lines from the mish backlog. + * Once we deem a good time to output stuff, we send that vector and wait + * until it's all gone before starting again. + */ + struct { + int fd; // index of fd we writev to + struct iovec *v; // starts at NULL + int count;// how many are filled in + int size; // how many are allocated + // temporary sequence buffer, for composite output. + mish_line_p sqb; + size_t total; // total bytes we sent + } output; + + char prompt[64]; + /* Since the prompt will contains more bytes than displayed glyphs, + * we keep track of the number of glyphs so we can reposition the + * cursor accurately. */ + int prompt_gc; // prompt real glyph count + + /* + * Unfiltered console input from the client. This get stored in there + * until the input code notices any output has been sent. Then it is + * passed down to 'vts' + */ + mish_input_t input; + /* + * this handles the vt sequences received at the command prompt, + * like direction keys etc -also handles UTF8 sequences- (but doesn't do + * anything with them). It is also subverted by the telnet decoder to + * do it's own things, separately. + * Sequences coming out are processed in mish_client_input. + */ + mish_vt_sequence_t vts; + /* + * Stuff received from 'input' side gets filtered via 'vts' and + * stored in this. + * Once a command has been validated, it is added back to the input + * backlog to make this client 'history' + */ + mish_line_p cmd; + + struct { + int w, h; } window_size; // valid if MISH_CLIENT_HAS_WINDOW_SIZE + struct { + int x, y; } cursor_pos; // valid if MISH_CLIENT_HAS_CURSOR_POS +} mish_client_t, *mish_client_p; + +// supplement the public ones from mish.h +enum { + MISH_QUIT = (1 << 31), + // the process console we started was a tty, so has terminal settings + MISH_CONSOLE_TTY = (1 << 30), +}; + +typedef struct mish_t { + uint32_t flags; + struct termios orig_termios; // original terminal settings + int originals[2]; // backup the original 1,2 fds + /* These are the ones we use to read the output from the main program. */ + mish_input_t origin[2]; + uint64_t stamp_start; + + TAILQ_HEAD(, mish_client_t) clients; + mish_client_p console; // client that is also the original terminal. + + pthread_t capture; // libmish main thread + pthread_t main; // todo: allow pause/stop/resume? + + struct { + mish_line_queue_t log; + unsigned int size; // number of lines in backlog + size_t alloc; // number of bytes in the backlog + } backlog; + struct { + int listen; // listen socket + int port; // port we're listening on + } telnet; + // Used by the select thread in mish_capture_select.c + struct { + fd_set read, write; + int max; + } select; +} mish_t, *mish_p; + +mish_client_p +mish_client_new( + mish_p m, + int in, + int out, + int is_tty); +void +mish_client_delete( + mish_p m, + mish_client_p c); + +/* + * Sequence buffer handling + */ +int +_mish_send_flush( + mish_p m, + mish_client_p c); +void +_mish_send_queue( + mish_client_p c, + const char * b); +void +_mish_send_queue_fmt( + mish_client_p c, + const char *fmt, ...); +void +_mish_send_queue_line( + mish_client_p c, + mish_line_p line ); + +//! Parse current input buffer fro VT sequences, like keys. +int +_mish_client_vt_parse_input( + struct mish_t *m, + struct mish_input_t *in, + uint8_t ich); + +/* + * This is the main interactive client coroutine. This one is interesting. + */ +void +_mish_client_interractive_cr( + mish_p m, + mish_client_p c); +void +_mish_client_dumb_cr( + mish_p m, + mish_client_p c); + +uint64_t +_mish_stamp_ms(); + +/* + * telnet handling + */ +int +mish_telnet_prepare( + mish_p m, + uint16_t port); +int +mish_telnet_in_check( + mish_p m, + fd_set * r); +void +mish_telnet_send_init( + mish_client_p c); +int +_mish_telnet_parse( + mish_client_p c, + uint8_t ch); + +/* + * input handling + */ +void +_mish_input_init( + mish_p m, + mish_input_p in, + int fd); +void +_mish_input_clear( + mish_p m, + mish_input_p in); +int +_mish_input_read( + mish_p m, + fd_set * fds, + mish_input_p in); + +/* + * Capture thread function + */ +void * +_mish_capture_select( + void *param); + +/* + * https://en.wikipedia.org/wiki/ANSI_escape_code#Terminal_output_sequences + */ +#define MISH_COLOR_RED "\033[38;5;125m" +#define MISH_COLOR_GREEN "\033[38;5;28m" +#define MISH_COLOR_RESET "\033[0m" + +#endif /* LIBMISH_SRC_MISH_PRIV_H_ */ diff --git a/libmish/src/mish_priv_cmd.h b/libmish/src/mish_priv_cmd.h new file mode 100644 index 0000000..7542580 --- /dev/null +++ b/libmish/src/mish_priv_cmd.h @@ -0,0 +1,37 @@ +/* + * mish_priv_cmd.h + * + * Copyright (C) 2020 Michel Pollet + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef LIBMISH_SRC_MISH_PRIV_CMD_H_ +#define LIBMISH_SRC_MISH_PRIV_CMD_H_ + +/* + * I decided that the command list would't be attached to the mish_t, + * + * In any other API I would, for consistency sake, but here I'm more + * interested in having a convenient way to add commands, regardless of the + * state of mish_t, and have macro that register them before main() is called + * and that sort of things. + * + * In the same vein, I also don't provide a way to remove a command, I don't + * think it's terribly necessary at the minute + */ +#include "bsd_queue.h" + +typedef void (*mish_cmd_handler_p)( + void * param, + int argc, + const char *argv[]); +#define _LIBMISH_HAS_CMD_HANDLER_ + +int +mish_cmd_call( + const char * cmd_line, + void * c); + + +#endif /* LIBMISH_SRC_MISH_PRIV_CMD_H_ */ diff --git a/libmish/src/mish_priv_line.h b/libmish/src/mish_priv_line.h new file mode 100644 index 0000000..c7dcbb5 --- /dev/null +++ b/libmish/src/mish_priv_line.h @@ -0,0 +1,47 @@ +/* + * mish_priv_line.h + * + * Copyright (C) 2020 Michel Pollet + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef LIBMISH_SRC_MISH_PRIV_LINE_H_ +#define LIBMISH_SRC_MISH_PRIV_LINE_H_ + +#include +#include "bsd_queue.h" + +#define MISH_MAX_LINE_SIZE 0xffff + +struct mish_line_t { + TAILQ_ENTRY(mish_line_t) self; + /* The stamp is made with _mish_get_stamp, which returns epoch + * milliseconds, so we don't need the 64 bits for the stamp here, + * lets say 34 bits seconds + 10 bits milliseconds + */ + uint64_t stamp : 44; + uint64_t err: 1, use: 4, draw_stamp: 1, + size : 16, len: 16, // len <= size + done: 16; // done <= len + char line[0]; +}; + +typedef struct mish_line_t mish_line_t, *mish_line_p; + +typedef TAILQ_HEAD(mish_line_queue_t, mish_line_t) mish_line_queue_t; + +/* + * mish_line tools + */ +int +_mish_line_reserve( + mish_line_p *line, + uint32_t count); +mish_line_p +_mish_line_add( + mish_line_queue_t * q, + char * buffer, + size_t length ); + +#endif /* LIBMISH_SRC_MISH_PRIV_LINE_H_ */ diff --git a/libmish/src/mish_priv_vt.h b/libmish/src/mish_priv_vt.h new file mode 100644 index 0000000..4ca1fdd --- /dev/null +++ b/libmish/src/mish_priv_vt.h @@ -0,0 +1,48 @@ +/* + * mish_priv_vt.h + * + * Copyright (C) 2020 Michel Pollet + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef LIBMISH_SRC_MISH_PRIV_VT_H_ +#define LIBMISH_SRC_MISH_PRIV_VT_H_ + +#include + +/* + * Input sequence decoder, deals with all the ESC bits and + * any UTF8 bits that gets encountered + */ +#define MISH_VT_RAW 0 +#define MISH_VT_TELNET (0xff) +#define MISH_VT_ESC (0x1b) +#define MISH_VT_CSI ((MISH_VT_ESC << 8) | ('[')) +#define MISH_VT_CSIQ ((MISH_VT_CSI << 8) | ('?')) +#define MISH_VT_UTF8 0x80 + +// allow writing MISH_VT_SEQ(CSI, 'H') +#define MISH_VT_SEQ(_kind, _ch) (((MISH_VT_ ## _kind) << 8) | (_ch)) + +typedef struct mish_vt_sequence_t { + uint32_t seq; // ESC, CSI, CSI? + int p[8]; + union { + struct { + uint32_t pc : 4, // CSI; parameter count + seq_want : 4, // how many more bytes we want (UTF8) + done : 1, // sequence is done + error : 1; // sequence was not valid + }; + uint32_t flags; + }; + uint32_t glyph; // for RAW and UTF8 +} mish_vt_sequence_t, *mish_vt_sequence_p; + +int +_mish_vt_sequence_char( + mish_vt_sequence_p s, + uint8_t ch); + +#endif /* LIBMISH_SRC_MISH_PRIV_VT_H_ */ diff --git a/libmish/src/mish_send.c b/libmish/src/mish_send.c new file mode 100644 index 0000000..7bb417f --- /dev/null +++ b/libmish/src/mish_send.c @@ -0,0 +1,200 @@ +/* + * mish_send.c + * + * Copyright (C) 2020 Michel Pollet + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include +#include +#include "mish_priv.h" +#include "mish_priv_line.h" + +/* + * We arrive here with an array of iovec buffers already prepared by + * _mish_send_queue_*(); + * This is called repeatedly, and we continually call writev, gather how + * many bytes have been written, and mark each corresponding buffer as done. + * Once all the iovec buffers have been filled, we're done! + * + * All of this is made to reduce to the max the number of 'write' system + * calls. + * + * There are two kinds of buffers in the vectors: + * 1) the "backlog" lines themselves. These have a pointer, all is well and good. + * 2) sequences we are making up on the fly, like prompt, colors etc; these + * are allocated in a 'sqb' (sequence buffer) which can grow (via realloc) + * as more stuff is added. + * Therefore, we can't pre-populate the vector array with the iov_base + * pointers, we keep these to NULL, and in this function, the first thing + * we do is derivate the pointers from their 'iov_len' in the current 'sqb'. + * + * Oh and we "lock" sqb to prevent any other things to be added. + */ +int +_mish_send_flush( + mish_p m, + mish_client_p c) +{ + /* If it's a new sequence, 'lock' it and prepare it's iovec pointers */ + if (c->output.sqb) { + if (!c->output.sqb->done) { + /* + * Here we construct the base address of out character buffers. + * They start with a NULL address as the sqb could grow when + * adding sequences. + * So once we are ready to send, we need to compute the + * base addresses of everyone that ought to point into the sqb, + * then we 'lock' it by marking it 'done'. + */ + char * base = c->output.sqb->line; + for (int i = 0; i < c->output.count; i++) { + if (!c->output.v[i].iov_base) { + c->output.v[i].iov_base = base; + base += c->output.v[i].iov_len; + } + } + c->output.sqb->done = 1; // "lock" the sqb until all is sent. + } + } + if (!c->output.count) + return 0; + /* if we don't have 'permission' to write yet, ask for it */ + if (!FD_ISSET(c->output.fd, &m->select.write)) { + FD_SET(c->output.fd, &m->select.write); + return 1; + } + /* skip what we've already done */ + struct iovec * io = c->output.v; + int ioc = c->output.count; + while (io->iov_len == 0 && ioc) { + io++; ioc--; + } + int res = 1; + if (ioc) { + ssize_t got = writev(c->output.fd, io, ioc); + if (got == -1) { + if (errno != EAGAIN && errno != EWOULDBLOCK) { + // we've been close down? + FD_CLR(c->output.fd, &m->select.write); + goto done; + } + } + /* fill up vectors with what was written */ + while (got > 0) { + ssize_t b = got > io->iov_len ? io->iov_len : got; + io->iov_len -= b; + io->iov_base += b; + if (io->iov_len == 0) { + io++; + ioc--; + } + got -= b; + } + } + if (ioc == 0) { // done! +done: + res = 0; + c->output.count = 0; + // also flush out temporary buffers, and unlock it + if (c->output.sqb) { + c->output.sqb->done = 0; + c->output.sqb->len = 0; + } + /* if nothing else is ready to send, clear us from the select loop */ + if (!c->sending) + FD_CLR(c->output.fd, &m->select.write); + } + return res; +} + +/* + * Add up a bit of output to something we want to send as a sequence + */ +static char * +_mish_send_prep( + mish_client_p c, + size_t l) +{ + if (c->output.sqb && c->output.sqb->done) { + fprintf(stderr, "%s problem\n", __func__); + abort(); + } + c->output.total += l; + /* allocate enough in the character buffer */ + _mish_line_reserve(&c->output.sqb, l + 1); + /* allocate enough in the vector buffer */ + if (c->output.count == c->output.size) { + c->output.size += 8; + c->output.v = realloc(c->output.v, c->output.size * sizeof(c->output.v[0])); + } + /* this is where the calling function will copy it's data */ + char * res = (char*)c->output.sqb->line + c->output.sqb->len; + c->output.sqb->len += l; + /* try to concatenate buffers together, if they are 'ours' */ + if (c->output.count && c->output.v[c->output.count-1].iov_base == NULL) { + struct iovec *v = c->output.v + c->output.count - 1; + v->iov_len += l; + } else { + struct iovec *v = c->output.v + c->output.count; + v->iov_base = NULL; // important, see top of the file for details + v->iov_len = l; + v++; + c->output.count++; + } + return res; +} + +/* + * Add up a bit of output to something we want to send as a sequence + */ +void +_mish_send_queue( + mish_client_p c, + const char * b) +{ + int l = strlen(b); + char *d = _mish_send_prep(c, l); + + strcpy(d, b); +} + +/* + * Same as above, but with formatting. + */ +void +_mish_send_queue_fmt( + mish_client_p c, + const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + int l = vsnprintf(NULL, 0, fmt, ap); + va_end(ap); + char *d = _mish_send_prep(c, l); + va_start(ap, fmt); + vsnprintf(d, l + 1, fmt, ap); + va_end(ap); +} + +void +_mish_send_queue_line( + mish_client_p c, + mish_line_p line ) +{ + /* allocate enough in the vector buffer */ + if (c->output.count == c->output.size) { + c->output.size += 8; + c->output.v = realloc(c->output.v, c->output.size * sizeof(c->output.v[0])); + } + struct iovec *v = c->output.v + c->output.count; + v->iov_base = line->line; + v->iov_len = line->len; + c->output.count++; + c->output.total += line->len; +} diff --git a/libmish/src/mish_session.c b/libmish/src/mish_session.c new file mode 100644 index 0000000..47228ae --- /dev/null +++ b/libmish/src/mish_session.c @@ -0,0 +1,282 @@ +/* + * mish_session.c + * + * Copyright (C) 2020 Michel Pollet + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include // for isatty etc + +#ifdef __MACH__ +#include +#include +#include // for openpty +#endif + +#ifdef __linux__ +#include +#endif + +#include "mish_priv.h" +#include "mish.h" + +/* + * get a localtime equivalent, with milliseconds added + */ +uint64_t +_mish_stamp_ms() +{ + struct timespec tim; +#ifdef __MACH__ + clock_serv_t cclock; + mach_timespec_t mts; + host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock); + clock_get_time(cclock, &mts); + mach_port_deallocate(mach_task_self(), cclock); + tim.tv_sec = mts.tv_sec; + tim.tv_nsec = mts.tv_nsec; +#else + clock_gettime(CLOCK_REALTIME, &tim); +#endif + + uint64_t res = (tim.tv_sec * 1000) + (tim.tv_nsec / 1000000); + return res; +} + +/* + * need to keep this around for atexit() + */ +static mish_p _mish = NULL; + +static void +_mish_atexit() +{ + if (_mish) + mish_terminate(_mish); +} + +mish_p +mish_prepare( + unsigned long caps ) +{ + /* In production, of if you want to make sure mish is disabled without + * re-linking, set this env variable. + */ + if (getenv("MISH_OFF")) { + if (atoi(getenv("MISH_OFF"))) { + unsetenv("MISH_TELNET_PORT"); + printf("mish: Disabled my MISH_OFF\n"); + return NULL; + } + } + + mish_p m = (mish_p)calloc(1, sizeof(*m)); + + FD_ZERO(&m->select.read); + FD_ZERO(&m->select.write); + TAILQ_INIT(&m->backlog.log); + TAILQ_INIT(&m->clients); + m->flags = caps; + int tty = 0; + if (getenv("MISH_TTY")) { + tty = atoi(getenv("MISH_TTY")); + } else + tty = (isatty(0) && isatty(1) && isatty(2)) || + (caps & MISH_CAP_FORCE_PTY); + int io[2]; // stdout pipe + int ie[2]; // stderr pipe +#if !defined(__wasm__) + { + char pty[80]; + if (openpty(&io[0], &io[1], pty, NULL, NULL) == -1) { + perror("openpty"); + goto error; + } + if (!(caps & MISH_CAP_NO_STDERR)) { + if (openpty(&ie[0], &ie[1], pty, NULL, NULL) == -1) { + perror("openpty"); + goto error; + } + } + if (tty) + m->flags |= MISH_CONSOLE_TTY; + if (tcgetattr(0, &m->orig_termios)) + perror("tcgetattr"); + struct termios raw = m->orig_termios; + raw.c_iflag &= ~(ICRNL | IXON); + raw.c_lflag &= ~(ECHO | ICANON | IEXTEN); // ISIG + if (tcsetattr(0, TCSAFLUSH, &raw)) + perror("tcsetattr"); + } +#endif + if (!(caps & MISH_CAP_NO_TELNET)) { + uint16_t port = 0; // suggested telnet port + if (getenv("MISH_TELNET_PORT")) + port = atoi(getenv("MISH_TELNET_PORT")); + + if (mish_telnet_prepare(m, port) == 0) { + char port[8]; + snprintf(port, sizeof(port), "%d", m->telnet.port); + setenv("MISH_TELNET_PORT", port, 1); + } else + unsetenv("MISH_TELNET_PORT"); + } + + // backup the existing descriptors, to make a 'client', we replace + // the original 1,2 with out own pipe/pty + m->originals[0] = dup(1); + m->originals[1] = dup(2); + // we do another dup(0,1) here, as that client will close() them + m->console = mish_client_new(m, dup(0), dup(1), tty); + m->stamp_start = _mish_stamp_ms(); + + _mish_input_init(m, &m->origin[0], io[0]); + if (dup2(io[1], 1) == -1) { + perror("dup2"); + goto error; + } + if (!(caps & MISH_CAP_NO_STDERR)) { + _mish_input_init(m, &m->origin[1], ie[0]); + if (dup2(ie[1], 2) == -1) { + perror("dup2"); + goto error; + } + } + atexit(_mish_atexit); +// m->main = pthread_self(); + // TODO: Make an epoll polling thread for linux + pthread_create(&m->capture, NULL, _mish_capture_select, m); + + _mish = m; + return m; +error: + if (io[0]) { + close(io[0]); + close(io[1]); + } + if (ie[0]) { + close(ie[0]); + close(ie[1]); + } + free(m); + return NULL; +} + +unsigned long +mish_get_flags( + struct mish_t *m) +{ + return m ? m->flags : 0; +} + +/* + * This can be called at any time; if the thread is running, tell it to + * close everything and exit... then wait for a little bit for it to + * terminate, then restore the terminal. + */ +void +mish_terminate( + mish_p m) +{ + if (!_mish) + return; + // restore normal IOs + dup2(m->originals[0], 1); + dup2(m->originals[1], 2); + // the thread does this, but we also do it in case this function is + // called from another exit(x) +#if !defined(__wasm__) + if ((m->flags & MISH_CONSOLE_TTY) && + tcsetattr(0, TCSAFLUSH, &m->orig_termios)) + perror("mish_terminate tcsetattr"); +#endif + close(m->originals[0]); close(m->originals[1]); + if (m->capture) { + m->flags |= MISH_QUIT; + // this will wake the select() call from sleep + if (write(1, "\n", 1)) + ; + + time_t start = time(NULL); + time_t now; + while (((now = time(NULL)) - start < 2) && m->capture) + usleep(1000); + } + printf("\033[4l\033[;r\033[999;1H"); fflush(stdout); + printf("%s done\n", __func__); + free(m); + _mish = NULL; +} + +static void +_mish_cmd_quit( + void * param, + int argc, + const char * argv[]) +{ + printf(MISH_COLOR_RED + "mish: Quitting." + MISH_COLOR_RESET "\n"); + + mish_p m = ((mish_client_p)param)->mish; + m->flags |= MISH_QUIT; +} + +MISH_CMD_NAMES(quit, "q", "quit"); +MISH_CMD_HELP(quit, + "exit running program", + "Close all clients and exit(0)"); +MISH_CMD_REGISTER(quit, _mish_cmd_quit); + +#define VT_COL(_c) "\033[" #_c "G" + +static void +_mish_cmd_mish( + void * param, + int argc, + const char * argv[]) +{ + printf(MISH_COLOR_RED + "mish: mish command." + MISH_COLOR_RESET "\n"); + + mish_p m = ((mish_client_p)param)->mish; + printf("Backlog: %6d lines (%5dKB)" VT_COL(40) "Telnet Port: %5d\n", + m->backlog.size, + (int)m->backlog.alloc / 1024, + m->telnet.port); +#if 0 + printf(" read: "); + for (int i = 0; i < m->select.max; i++) + if (FD_ISSET(i, &m->select.read)) printf("%d ", i); + printf(VT_COL(40) " write: "); + for (int i = 0; i < m->select.max; i++) + if (FD_ISSET(i, &m->select.write)) printf("%d ", i); + printf("\n"); +#endif + mish_client_p c; + TAILQ_FOREACH(c, &m->clients, self) { + printf(" Client: r: %d w: %d %s %s\n", + c->input.fd, c->output.fd, + c->input.is_telnet ? "telnet session" : + c == m->console ? "console" : "*unknown*", + c == m->console ? + m->flags & MISH_CONSOLE_TTY ? "(tty)": "(dumb)" + : ""); + printf(" max sizes: vector: %d input: %d\n", + c->output.size, c->input.line ? c->input.line->size : 0); + } + +} + +MISH_CMD_NAMES(mish, "mish"); +MISH_CMD_HELP(mish, + "Displays mish status.", + "Show status and a few bits of internals."); +MISH_CMD_REGISTER(mish, _mish_cmd_mish); + diff --git a/libmish/src/mish_telnet.c b/libmish/src/mish_telnet.c new file mode 100644 index 0000000..febd93c --- /dev/null +++ b/libmish/src/mish_telnet.c @@ -0,0 +1,241 @@ +/* + * mish_telnet.c + * + * Copyright (C) 2020 Michel Pollet + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "mish_priv.h" + +#ifdef DEBUG_TELNET +#define TELCMDS +#define TELOPTS +#define TV(w) w +#else +#define TV(w) +#endif +#include + +/* + * Ask remote telnet client to turn off echo, and send us the NAWS + */ +void +mish_telnet_send_init( + mish_client_p c) +{ + const unsigned char init[] = { + IAC, DO, TELOPT_ECHO, + IAC, DO, TELOPT_NAWS, + IAC, WILL, TELOPT_ECHO, + IAC, WILL, TELOPT_SGA, + 0, + }; + _mish_send_queue(c, (char*)init); +} + +/* + * This looks for the TELNET IAC prefix, and handles /some/ of them. + * The one we're really interested in anyway is the NAWS aka Window Size + * sequence. + * All the other ones are ignored, but parsed. Ish. + */ +int +_mish_telnet_parse( + mish_client_p c, + uint8_t ch) +{ + TV(printf("%02x(%d) %s (seq %06x)\n", + ch, ch, ch >= xEOF ? telcmds[ch-xEOF] : "", + c->vts.seq);) + /* + * To handle telnet sequences, we pause the VT decoder + */ + switch (c->vts.seq) { + case MISH_VT_RAW: + if (ch == IAC) { + c->vts.seq = MISH_VT_TELNET; + return 1; + } + break; + case MISH_VT_TELNET: { + switch (ch) { + case WILL: + case WONT: + case DO: + case DONT: + case SB: + c->vts.seq = c->vts.seq << 8 | ch; + return 1; + default: + case SE: + c->vts.seq = MISH_VT_RAW; + return 1; + } + } break; + case MISH_VT_SEQ(TELNET, IAC): + TV(printf("IAC %d %s\n\n", ch, telopts[ch]);) + c->vts.seq = MISH_VT_RAW; + break; // let this one thru!!! + case MISH_VT_SEQ(TELNET, WILL): + TV(printf("WILL %d %s\n\n", ch, telopts[ch]);) + c->vts.seq = MISH_VT_RAW; + return 1; + case MISH_VT_SEQ(TELNET, WONT): + TV(printf("WONT %d %s\n", ch, telopts[ch]);) + c->vts.seq = MISH_VT_RAW; + return 1; + case MISH_VT_SEQ(TELNET, DO): + TV(printf("DO %d %s\n", ch, telopts[ch]);) + c->vts.seq = MISH_VT_RAW; + return 1; + case MISH_VT_SEQ(TELNET, DONT): + TV(printf("DONT %d %s\n", ch, telopts[ch]);) + c->vts.seq = MISH_VT_RAW; + return 1; + case MISH_VT_SEQ(TELNET, SB): + TV(printf("SB %d %s\n", ch, telopts[ch]);) + c->vts.seq_want = 0; + c->vts.p[0] = 0; + switch (ch) { + case TELOPT_NAWS: + c->vts.seq = c->vts.seq << 8 | ch; + return 1; + default: + if (ch == IAC) { + c->vts.seq = MISH_VT_TELNET; + return 1; + } + } + return 1; + case (MISH_VT_SEQ(TELNET, SB) << 8 | (TELOPT_NAWS)): { + switch (c->vts.seq_want++) { + case 0: + c->vts.p[0] = 0; + c->vts.p[1] = ch; + return 1; + case 1: c->vts.p[1] = (c->vts.p[1] << 8) | ch; return 1; + case 2: c->vts.p[0] = ch; return 1; + case 3: c->vts.p[0] = (c->vts.p[0] << 8) | ch; /* fallthru */ + } + if (c->vts.seq_want == 4) { + TV(printf("GOT NAWS: %dx%d\n", c->vts.p[0], c->vts.p[1]);) + c->window_size.h = c->vts.p[0]; + c->window_size.w = c->vts.p[1]; + c->flags |= MISH_CLIENT_HAS_WINDOW_SIZE | + MISH_CLIENT_UPDATE_WINDOW; + c->vts.seq = MISH_VT_RAW; + c->vts.done = 1; + return 1; + } + } return 1; + } + return 0; +} + +extern const char *__progname; + +/* + * not going to go thru all the bits regarding sockets here, you know it. + * + * We allocate a random port, and listen to it, then add it to the + * main select() thread. + */ +int +mish_telnet_prepare( + mish_p m, + uint16_t port) +{ + m->telnet.listen = socket(AF_INET, SOCK_STREAM, 0); + int flag = 1; + + signal(SIGPIPE, SIG_IGN); + if (setsockopt(m->telnet.listen, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof(flag))) + perror("SO_REUSEADDR"); + + struct sockaddr_in b = { + .sin_family = AF_INET, + .sin_addr.s_addr = htonl(INADDR_LOOPBACK), + }; + // attempts to generate a pseudo random port based on the executable name + // before having to rely on random(). This gives a chance of 'unique' ports + // per programs. + if (port == 0) { + for (int i = 0; __progname[i]; i++) + port += __progname[i] + i; + if (port < 1024) + port += 1024; + port = port & 0x3fff; + } + + int tries = 5; + do { + b.sin_port = htons(port); + if (bind(m->telnet.listen, (struct sockaddr *)&b, sizeof(b)) == -1) { + fprintf(stderr, "%s can't bind %d\n", __func__, ntohs(b.sin_port)); + port = port + (random() & 0x3ff); + continue; + } + m->telnet.port = ntohs(b.sin_port); + printf(MISH_COLOR_GREEN + "mish: telnet port on %d" + MISH_COLOR_RESET "\n", + m->telnet.port); + break; + } while (tries-- > 0); + if (tries) { + if (listen(m->telnet.listen, 2) == -1) { + perror("mish_telnet_prepare listen"); + goto error; + } + FD_SET(m->telnet.listen, &m->select.read); + return 0; + } + fprintf(stderr, "mish: %s failed\n", __func__); +error: + close(m->telnet.listen); + m->telnet.listen = -1; + return -1; +} + +/* + * Accept a new connection from the telnet port, add a new client + */ +int +mish_telnet_in_check( + mish_p m, + fd_set * r) +{ + if (!FD_ISSET(m->telnet.listen, r)) + return 0; + + struct sockaddr_in a = {}; + socklen_t al = sizeof(a); + int tf = accept(m->telnet.listen, (struct sockaddr *) &a, &al); + if (tf < 0) { + perror(__func__); + return -1; + } + /* + * it is necessary to have TWO file descriptors here, otherwise + * the FD_SET/FD_CLR logic could be confusing as using the same bits. + * a dup() isn't terribly expensive and guarantees we don't have to + * worry about it. + */ + mish_client_p c = mish_client_new(m, tf, dup(tf), 1 /* tty */); + c->input.is_telnet = 1; + + printf(MISH_COLOR_GREEN + "mish: telnet: connected." + MISH_COLOR_RESET "\n"); + + return 0; +} diff --git a/libmish/src/mish_vt.c b/libmish/src/mish_vt.c new file mode 100644 index 0000000..61d4864 --- /dev/null +++ b/libmish/src/mish_vt.c @@ -0,0 +1,105 @@ +/* + * mish_vt.c + * + * Copyright (C) 2020 Michel Pollet + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include "mish_priv_vt.h" + +#ifndef ARRAY_SIZE +#define ARRAY_SIZE(_a) (sizeof(_a) / sizeof((_a)[0])) +#endif + +/* + * Handle sequences of VT100 and UTF8 chars. + * + * Uses the sequence 's' as temporary buffer, and returns 1 when a complete + * sequence OR a glyph has been decoded. + */ +int +_mish_vt_sequence_char( + mish_vt_sequence_p s, + uint8_t ch) +{ + // if previous sequence was done, reset it. + if (s->done) + s->flags = s->seq = s->glyph = s->pc = s->p[0] = 0; + switch (s->seq) { + case MISH_VT_RAW: { + switch (ch) { + case 0x1b: + s->seq = MISH_VT_ESC; + break; + default: { + if (ch & 0x80) { // UTF8 !??! + int mask = 0x40; + s->seq_want = 0; + while ((ch & mask) && s->seq_want < 5) { + s->seq_want++; + mask >>= 1; + } + // clear header bits (ought to be 2; 1 allows encoding of 0xffffff) + s->glyph = ch & (0xff >> (s->seq_want + 1)); + s->seq = MISH_VT_UTF8; + } else { + s->seq = (s->seq << 8) | ch; + s->glyph = ch; // technically it's a glyph + s->done = 1; + } + } + } + } break; + case MISH_VT_ESC: { + if (ch == '[') + s->seq = MISH_VT_CSI; + else { + s->seq = (s->seq << 8) | ch; + s->done = 1; + } + } break; + case MISH_VT_CSIQ: + case MISH_VT_CSI: { + switch (ch) { + case '?': { + // note this would still accept somelike like CSI ? 00?; 1 + if ((s->seq == MISH_VT_CSIQ) || s->pc) { + s->done = s->error = 1; + } else + s->seq = MISH_VT_CSIQ; + } break; + case '0' ... '9': + s->p[s->pc] = (s->p[s->pc] * 10) + (ch - '0'); + break; + case ';': { + if (s->pc < ARRAY_SIZE(s->p)) { + s->pc++; + s->p[s->pc] = 0; + } else { + s->done = s->error = 1; + } + } break; + default: + if (s->p[s->pc]) + s->pc++; + s->seq = (s->seq << 8) | ch; + s->done = 1; + break; + } + } break; + case MISH_VT_UTF8: { + s->glyph = (s->glyph << 6) | (ch & 0x3f); + if (s->seq_want) s->seq_want--; + s->done = s->seq_want == 0; + } break; + } +#ifdef MISH_VT_DEBUG + if (s->done) + fprintf(stderr, "in %x(%c) state %x done:%d error:%d pc:%d/%d\n", + ch, ch < ' '?'.':ch,s->seq, s->done, s->error, + s->pc, (int)ARRAY_SIZE(s->p)); +#endif + return s->done; +} diff --git a/libmish/tests/mish_argv_make_test.c b/libmish/tests/mish_argv_make_test.c new file mode 100644 index 0000000..3fabd23 --- /dev/null +++ b/libmish/tests/mish_argv_make_test.c @@ -0,0 +1,95 @@ +// small test unit for mish_argv_make +#include +#include +#include + + +typedef struct _mish_argv_t { + char * line; + int ac; + char * av[0]; +} _mish_argv_t; +/* + * Duplicate 'line', split it into words, store word pointers in an array, + * NULL terminate it. Also return the number of words in the array in argc. + * + * The returned value is made of two malloc()ed blocks. use mish_argv_free + * to free the memory. + * It's OK to change any of the pointers. But no not try to realloc() the + * vector as it hides a structure + */ +static char ** +mish_argv_make( + const char * line, + int * argc ) +{ + const char separator = ' '; + _mish_argv_t * r = calloc(1, sizeof(*r)); + r->line = strdup(line); + char *dup = r->line; + char quote; + enum { s_newarg = 0, s_startarg, s_copyquote, s_skip, s_copy }; + int state = s_newarg; + do { + switch (state) { + case s_newarg: + r = realloc(r, sizeof(*r) + ((r->ac + 2) * sizeof(char*))); + while (*dup == ' ' || *dup == separator) + dup++; + r->av[r->ac++] = dup; + state = s_startarg; + break; + case s_startarg: + if (*dup == '"' || *dup == '\'') { + quote = *dup++; + state = s_copyquote; + } else + state = s_copy; + break; + case s_copyquote: + if (*dup == '\\') + state = s_skip; + else if (*dup == quote) { + state = s_newarg; + dup++; + if (*dup) *dup++ = 0; + } else if (*dup) + dup++; + break; + case s_skip: + dup++; + state = s_copyquote; + break; + case s_copy: + if (*dup == 0) + break; + if (*dup != separator) + dup++; + else { + state = s_newarg; + if (*dup) *dup++ = 0; + } + break; + } + } while (*dup); + r->av[r->ac] = NULL; + if (argc) + *argc = r->ac; + return r->av; +} + +int main() { + int argc = 0; + char **argv = mish_argv_make("testing \"one escape two\" lala ", &argc); + + printf("argc = %d\n", argc); + for (int i = 0; argv[i]; i++) + printf("%2d:'%s'\n", i, argv[i]); + + argv = mish_argv_make("command with some \" quoted\\\"words \" should work\n", &argc); + + printf("argc = %d\n", argc); + for (int i = 0; argv[i]; i++) + printf("%2d:'%s'\n", i, argv[i]); + +} diff --git a/libmish/tests/mish_cmd_test.c b/libmish/tests/mish_cmd_test.c new file mode 100644 index 0000000..d48de73 --- /dev/null +++ b/libmish/tests/mish_cmd_test.c @@ -0,0 +1,20 @@ +/* + * mish_cmd_test.c + * + * Copyright (C) 2020 Michel Pollet + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "mish_cmd.c" + +int main() +{ + int argc; + char ** argv = mish_argv_make( + "command with some \" quoted\\\"words \" should work\n", &argc); + + for (int i = 0; i < argc; i++) + printf("%2d: '%s'\n", i, argv[i]); + mish_argv_free(argv); +} diff --git a/libmish/tests/mish_debug_test.c b/libmish/tests/mish_debug_test.c new file mode 100644 index 0000000..c32e559 --- /dev/null +++ b/libmish/tests/mish_debug_test.c @@ -0,0 +1,94 @@ +/* + * mish_debug_test.c + * + * Copyright (C) 2020 Michel Pollet + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/* + * NOTE this program is made for debug purpose only, it basically give you + * telnet command access remotely + * IT IS JUST MADE TO DEBUG LIBMISH, DO NOT USE IN PROD! + */ +#define _GNU_SOURCE // for asprintf +#include +#include +#include +#include +#include +#include +#include +#include "mish.h" + +static void +sigchld_handler(int s) +{ + int status = 0; + pid_t pid = waitpid(-1, &status, WNOHANG); + if (pid > 0) { + if (WIFEXITED(status) && WEXITSTATUS(status)) + fprintf(stderr, "pid %d returned %d\n", (int)pid, WEXITSTATUS(status)); + if (WIFSIGNALED(status)) + fprintf(stderr, "pid %d terminated with %s\n", + (int)pid, strsignal(WTERMSIG(status))); + } +} + +int main() +{ + signal(SIGCHLD, sigchld_handler); + mish_prepare(0); + + while (1) { + sleep(1); + } +} + +static const char * +_shell_which( + const char * cmd) +{ + if (cmd[0] == '.' || cmd[0] == '/') + return strdup(cmd); + char * path = strdup(getenv("PATH")); + char * cur = path, *e; + while ((e = strsep(&cur, ":")) != NULL) { + char *pe; + asprintf(&pe, "%s/%s", e, cmd); + struct stat st = {}; + if (stat(pe, &st) == 0) { + return pe; + } + free(pe); + } + fprintf(stderr, "%s: command not found\n", cmd); + return NULL; +} + +static void +_test_shell_cnt( + void * param, + int argc, + const char * argv[]) +{ + const char * av[argc + 1]; + av[0] = _shell_which(argv[1]); + if (av[0] == NULL) + return; + for (int ai = 1; ai <= argc; ai++) + av[ai] = argv[ai+1]; + pid_t pid = fork(); + if (pid == 0) { + execv(av[0], (void*)av); + perror(av[0]); + close(0);close(1);close(2); + exit(1); + } +} + +MISH_CMD_NAMES(shell, "shell"); +MISH_CMD_HELP(shell, + "run a shell command", + "test command for libmish!"); +MISH_CMD_REGISTER(shell, _test_shell_cnt); diff --git a/libmish/tests/mish_input_test.c b/libmish/tests/mish_input_test.c new file mode 100644 index 0000000..3cf0aea --- /dev/null +++ b/libmish/tests/mish_input_test.c @@ -0,0 +1,146 @@ +/* + * This is a stress/scenario test for the mish_input_read function + */ +#define MISH_INPUT_TEST + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "mish.h" + +static uint8_t *words = NULL; +static size_t words_size = 0; +static size_t words_offset = 0; + +static int ccount = 0; + +static ssize_t _test_read(int fd, void *w, size_t count) { + errno = 0; + + if (!(ccount++ % 17)) { + errno = EAGAIN; + printf("%s fake EAGAIN\n", __func__); + return -1; + } + + if (words_offset + count > words_size) + count = words_size - words_offset; + + memcpy(w, words + words_offset, count); + words_offset += count; + if (!count) { + printf("%s all input sent\n", __func__); + } + return count; +} + +#define read(_a,_b,_c) _test_read(_a,_b,_c) + +#include "mish_input.c" +#include "mish_line.c" + +#undef read + +/* duplicate from mish_session.c */ +/* + * get a localtime equivalent, with milliseconds added + */ +uint64_t +_mish_stamp_ms() +{ + return 0; +} + + +int main() +{ + const char *filen = "/usr/share/dict/american-english"; + struct stat st; + int fd; + if ((lstat(filen, &st) == -1) || (fd = open(filen, O_RDONLY)) == -1) { + perror(filen); + exit(1); + } + words_size = st.st_size; + words = malloc(words_size + 1); + if (read(fd, words, st.st_size) != st.st_size) { + perror("EOF unexpected"); + exit(1); + } + words[words_size] = 0; + printf("File %s read\n", filen); + + /* That's not needed for the test, but init() relies on it */ + mish_t mish = {}; + mish_p m = &mish; + FD_ZERO(&m->select.read); + FD_ZERO(&m->select.write); + TAILQ_INIT(&m->backlog.log); + TAILQ_INIT(&m->clients); + + /* we don't need the file descriptor as we bypass "read" but the + * init function relies on it so here is a socketpair for it to play + * with */ + int sk[2]; + if (socketpair(AF_UNIX, SOCK_STREAM, 0, sk)) { + perror("socketpair"); + exit(1); + } + mish_input_t input = {}; + _mish_input_init(m, &input, sk[0]); + + uint8_t *cursor = words; + int linec = 0; + mish_line_p ln = NULL; + + /* + * Right so now we can actually test the function. We keep a running + * pointer on the source data, and the "last" line we compared, and + * compared line's content with the source buffer. If all goes + * well, they should match exactly. + */ + do { + _mish_input_read(m, &m->select.read, &input); + printf(" read up to o: %d/%d\n", (int)words_offset, (int)words_size); + + if (!ln) + ln = TAILQ_FIRST(&input.backlog); + else if (TAILQ_NEXT(ln, self)) + ln = TAILQ_NEXT(ln, self); + else + continue; + while (ln) { + linec++; + // printf("line %4d: %s", linec, ln->line); + + uint8_t * l = (uint8_t*)ln->line; + for (int ic = 0; ic < ln->len; ic++, cursor++) { + if (l[ic] != *cursor) { + printf("ERROR: Mismatch Offset %ld char #%d/%d (%x/%x) line %d: %s\n", + cursor - words, ic, + ln->len, + l[ic], *cursor, + linec, l); + goto done; + } + } + + if (TAILQ_LAST(&input.backlog, mish_line_queue_t) == ln) + break; + ln = TAILQ_NEXT(ln, self); + } + } while (words_offset < words_size); + printf("%d lines were read and compared\n", linec); +done: + exit(0); + +} + diff --git a/libmish/tests/mish_test.c b/libmish/tests/mish_test.c new file mode 100644 index 0000000..2ce0306 --- /dev/null +++ b/libmish/tests/mish_test.c @@ -0,0 +1,43 @@ +/* + * mish_test.c + * + * Copyright (C) 2020 Michel Pollet + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +#include "mish.h" + +int cnt = 0; + +int main() +{ + mish_prepare(0); + + while (1) { + sleep(1); + printf("Count %d\n", cnt++); + } +} + + +/* And here is a command line action that can reset the 'cnt' variable */ +static void _test_set_cnt(void * param, int argc, const char * argv[]) +{ + if (argc > 1) { + cnt = atoi(argv[1]); + } else { + fprintf(stderr, + "%s: syntax 'set XXX' to set the variable\n", argv[0]); + } +} + +MISH_CMD_NAMES(set, "set"); +MISH_CMD_HELP(set, + "set 'cnt' variable", + "test command for libmish!"); +MISH_CMD_REGISTER(set, _test_set_cnt); diff --git a/libmish/tests/mish_vt_test.c b/libmish/tests/mish_vt_test.c new file mode 100644 index 0000000..19f3fd6 --- /dev/null +++ b/libmish/tests/mish_vt_test.c @@ -0,0 +1,33 @@ +/* + * mish_vt_test.c + * + * Copyright (C) 2020 Michel Pollet + * + * SPDX-License-Identifier: Apache-2.0 + */ + + +#include +#include +#include "../src/mish_vt.c" + +/* small test unit for the VT decoder, mostly for UTF8 */ +int main() +{ + const char * input = "Hello 😈 \033[1mThere\033[0m"; + + mish_vt_sequence_t sq = {}; + + printf("%s\n", input); + const char *s = input; + int cg = 0; + while (*s) { + if (_mish_vt_sequence_char(&sq, *s)) { + printf("glyph s:%08x g:%08x\n", sq.seq, sq.glyph); + if (sq.glyph) + cg++; + } + s++; + } + printf("%d glyphs in string\n", cg); +} diff --git a/nuklear/mii_emu.c b/nuklear/mii_emu.c new file mode 100644 index 0000000..a7f88ee --- /dev/null +++ b/nuklear/mii_emu.c @@ -0,0 +1,322 @@ +/* + * mii_emu.c + * + * Copyright (C) 2023 Michel Pollet + * + * SPDX-License-Identifier: MIT + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define NK_INCLUDE_FIXED_TYPES +#define NK_INCLUDE_STANDARD_IO +#define NK_INCLUDE_STANDARD_VARARGS +#define NK_INCLUDE_DEFAULT_ALLOCATOR +#define NK_INCLUDE_VERTEX_BUFFER_OUTPUT +#define NK_INCLUDE_FONT_BAKING +#define NK_INCLUDE_DEFAULT_FONT +#define NK_BUTTON_TRIGGER_ON_RELEASE +#include "nuklear.h" + +#define NK_XLIB_GL3_IMPLEMENTATION +#define NK_XLIB_LOAD_OPENGL_EXTENSIONS +#include "nuklear_xlib_gl3.h" + +#include "mii.h" +#include "mish.h" + +#define WINDOW_WIDTH 1280 +#define WINDOW_HEIGHT 720 // (10 + (192) * 3) + +#define MAX_VERTEX_BUFFER 512 * 1024 +#define MAX_ELEMENT_BUFFER 128 * 1024 + +void +mii_nuklear( + mii_t *mii, + struct nk_context *ctx); +void +mii_nuklear_init( + mii_t *mii, + struct nk_context *ctx); +/* =============================================================== + * + * DEMO + * + * ===============================================================*/ +struct XWindow { + Display *dpy; + Window win; + XVisualInfo *vis; + Colormap cmap; + XSetWindowAttributes swa; + XWindowAttributes attr; + GLXFBConfig fbc; + Atom wm_delete_window; + int width, height; +}; +static int gl_err = nk_false; +static int gl_error_handler(Display *dpy, XErrorEvent *ev) +{NK_UNUSED(dpy); NK_UNUSED(ev); gl_err = nk_true;return 0;} + +static void +die(const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); + fputs("\n", stderr); + exit(EXIT_FAILURE); +} + +static int +has_extension(const char *string, const char *ext) +{ + const char *start, *where, *term; + where = strchr(ext, ' '); + if (where || *ext == '\0') + return nk_false; + + for (start = string;;) { + where = strstr((const char*)start, ext); + if (!where) break; + term = where + strlen(ext); + if (where == start || *(where - 1) == ' ') { + if (*term == ' ' || *term == '\0') + return nk_true; + } + start = term; + } + return nk_false; +} + +struct nk_font *nk_main_font = NULL; + +/* global now, mish commands use it */ +mii_t g_mii = {}; + +int +main( + int argc, + const char *argv[]) +{ + /* Platform */ + int running = 1; + struct XWindow win; + GLXContext glContext; + struct nk_context *ctx; + struct nk_colorf bg; + + mii_init(&g_mii); + int idx = 0; + uint32_t flags = MII_INIT_DEFAULT; + int r = mii_argv_parse(&g_mii, argc, argv, &idx, &flags); + if (r == 0) { + printf("mii: Invalid argument %s, skipped\n", argv[idx]); + } else if (r == -1) + exit(1); + mii_prepare(&g_mii, flags); + mish_prepare(1); + printf("MISH_TELNET_PORT = %s\n", getenv("MISH_TELNET_PORT")); + + memset(&win, 0, sizeof(win)); + win.dpy = XOpenDisplay(NULL); + if (!win.dpy) die("Failed to open X display\n"); + { + /* check glx version */ + int glx_major, glx_minor; + if (!glXQueryVersion(win.dpy, &glx_major, &glx_minor)) + die("[X11]: Error: Failed to query OpenGL version\n"); + if ((glx_major == 1 && glx_minor < 3) || (glx_major < 1)) + die("[X11]: Error: Invalid GLX version!\n"); + } + { + /* find and pick matching framebuffer visual */ + int fb_count; + static GLint attr[] = { + GLX_X_RENDERABLE, True, + GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, + GLX_RENDER_TYPE, GLX_RGBA_BIT, + GLX_X_VISUAL_TYPE, GLX_TRUE_COLOR, + GLX_RED_SIZE, 8, + GLX_GREEN_SIZE, 8, + GLX_BLUE_SIZE, 8, + GLX_ALPHA_SIZE, 8, + GLX_DEPTH_SIZE, 24, + GLX_STENCIL_SIZE, 8, + GLX_DOUBLEBUFFER, True, + None + }; + GLXFBConfig *fbc; + fbc = glXChooseFBConfig(win.dpy, DefaultScreen(win.dpy), attr, &fb_count); + if (!fbc) die("[X11]: Error: failed to retrieve framebuffer configuration\n"); + { + /* pick framebuffer with most samples per pixel */ + int i; + int fb_best = -1, best_num_samples = -1; + for (i = 0; i < fb_count; ++i) { + XVisualInfo *vi = glXGetVisualFromFBConfig(win.dpy, fbc[i]); + if (vi) { + int sample_buffer, samples; + glXGetFBConfigAttrib(win.dpy, fbc[i], GLX_SAMPLE_BUFFERS, &sample_buffer); + glXGetFBConfigAttrib(win.dpy, fbc[i], GLX_SAMPLES, &samples); + if ((fb_best < 0) || (sample_buffer && samples > best_num_samples)) + fb_best = i, best_num_samples = samples; + XFree(vi); + } + } + win.fbc = fbc[fb_best]; + XFree(fbc); + win.vis = glXGetVisualFromFBConfig(win.dpy, win.fbc); + } + } + { + /* create window */ + win.cmap = XCreateColormap(win.dpy, RootWindow(win.dpy, win.vis->screen), win.vis->visual, AllocNone); + win.swa.colormap = win.cmap; + win.swa.background_pixmap = None; + win.swa.border_pixel = 0; + win.swa.event_mask = + ExposureMask | KeyPressMask | KeyReleaseMask | + ButtonPress | ButtonReleaseMask| ButtonMotionMask | + Button1MotionMask | Button3MotionMask | Button4MotionMask | Button5MotionMask| + PointerMotionMask| StructureNotifyMask; + win.win = XCreateWindow(win.dpy, RootWindow(win.dpy, win.vis->screen), 0, 0, + WINDOW_WIDTH, WINDOW_HEIGHT, 0, win.vis->depth, InputOutput, + win.vis->visual, CWBorderPixel|CWColormap|CWEventMask, &win.swa); + if (!win.win) die("[X11]: Failed to create window\n"); + XFree(win.vis); + + char title[128]; + sprintf(title, "MII //e Emulator"); + char *telnet = getenv("MISH_TELNET_PORT"); + if (telnet) + sprintf(title + strlen(title), " (telnet port %s)", telnet); + else + sprintf(title + strlen(title), " (telnet disabled)"); + XStoreName(win.dpy, win.win, title); + XMapWindow(win.dpy, win.win); + win.wm_delete_window = XInternAtom(win.dpy, "WM_DELETE_WINDOW", False); + XSetWMProtocols(win.dpy, win.win, &win.wm_delete_window, 1); + } + { + /* create opengl context */ + typedef GLXContext(*glxCreateContext)(Display*, GLXFBConfig, GLXContext, Bool, const int*); + int(*old_handler)(Display*, XErrorEvent*) = XSetErrorHandler(gl_error_handler); + const char *extensions_str = glXQueryExtensionsString(win.dpy, DefaultScreen(win.dpy)); + glxCreateContext create_context = (glxCreateContext) + glXGetProcAddressARB((const GLubyte*)"glXCreateContextAttribsARB"); + + gl_err = nk_false; + if (!has_extension(extensions_str, "GLX_ARB_create_context") || !create_context) { + fprintf(stdout, "[X11]: glXCreateContextAttribARB() not found...\n"); + fprintf(stdout, "[X11]: ... using old-style GLX context\n"); + glContext = glXCreateNewContext(win.dpy, win.fbc, GLX_RGBA_TYPE, 0, True); + } else { + GLint attr[] = { + GLX_CONTEXT_MAJOR_VERSION_ARB, 3, + GLX_CONTEXT_MINOR_VERSION_ARB, 0, + None + }; + glContext = create_context(win.dpy, win.fbc, 0, True, attr); + XSync(win.dpy, False); + if (gl_err || !glContext) { + /* Could not create GL 3.0 context. Fallback to old 2.x context. + * If a version below 3.0 is requested, implementations will + * return the newest context version compatible with OpenGL + * version less than version 3.0.*/ + attr[1] = 1; attr[3] = 0; + gl_err = nk_false; + fprintf(stdout, "[X11] Failed to create OpenGL 3.0 context\n"); + fprintf(stdout, "[X11] ... using old-style GLX context!\n"); + glContext = create_context(win.dpy, win.fbc, 0, True, attr); + } + } + XSync(win.dpy, False); + XSetErrorHandler(old_handler); + if (gl_err || !glContext) + die("[X11]: Failed to create an OpenGL context\n"); + glXMakeCurrent(win.dpy, win.win, glContext); + } +//extern const unsigned char mii_proggy_data[]; +//extern const unsigned int mii_proggy_size; +extern const unsigned char mii_droid_data[]; +extern const unsigned int mii_droid_size; + + ctx = nk_x11_init(win.dpy, win.win); + /* Load Fonts: if none of these are loaded a default font will be used */ + { + struct nk_font_atlas *atlas; + nk_x11_font_stash_begin(&atlas); + struct nk_font_config cfg = nk_font_config(0); +#if 0 + nk_rune ranges[] = { + 0x0020, 0x007E, /* Ascii */ + 0x00A1, 0x00FF, /* Symbols + Umlaute */ + 0 + }; +#endif + cfg.range = nk_font_default_glyph_ranges(); + cfg.oversample_h = cfg.oversample_v = 1; + cfg.pixel_snap = true; + nk_main_font = nk_font_atlas_add_from_memory(atlas, + (void*)mii_droid_data, mii_droid_size, 20, &cfg); + nk_x11_font_stash_end(); + /*nk_style_load_all_cursors(ctx, atlas->cursors);*/ + if (nk_main_font) + nk_style_set_font(ctx, &nk_main_font->handle); + } + + mii_nuklear_init(&g_mii, ctx); + + bg.r = 0.0f; bg.g = 0.0f; bg.b = 0.0f; bg.a = 1.0f; +// bg.r = 0.8f; bg.g = 0.8f; bg.b = 0.8f; bg.a = 1.0f; + while (running) { + /* Input */ + XEvent evt; + nk_input_begin(ctx); + while (XPending(win.dpy)) { + XNextEvent(win.dpy, &evt); + if (evt.type == ClientMessage) goto cleanup; + if (XFilterEvent(&evt, win.win)) continue; + nk_x11_handle_event(&evt); + } + nk_input_end(ctx); + + /* GUI */ + mii_nuklear(&g_mii, ctx); + + /* Draw */ + XGetWindowAttributes(win.dpy, win.win, &win.attr); + glViewport(0, 0, win.width, win.height); + glClear(GL_COLOR_BUFFER_BIT); + glClearColor(bg.r, bg.g, bg.b, bg.a); + /* IMPORTANT: `nk_x11_render` modifies some global OpenGL state + * with blending, scissor, face culling, depth test and viewport and + * defaults everything back into a default state. + * Make sure to either a.) save and restore or b.) reset your own state after + * rendering the UI. */ + nk_x11_render(NK_ANTI_ALIASING_ON, MAX_VERTEX_BUFFER, MAX_ELEMENT_BUFFER); + glXSwapBuffers(win.dpy, win.win); + } + +cleanup: + nk_x11_shutdown(); + glXMakeCurrent(win.dpy, 0, 0); + glXDestroyContext(win.dpy, glContext); + XUnmapWindow(win.dpy, win.win); + XFreeColormap(win.dpy, win.cmap); + XDestroyWindow(win.dpy, win.win); + XCloseDisplay(win.dpy); + return 0; + +} diff --git a/nuklear/mii_fonts.c b/nuklear/mii_fonts.c new file mode 100644 index 0000000..c6cc735 --- /dev/null +++ b/nuklear/mii_fonts.c @@ -0,0 +1,9 @@ + + +#define INCBIN_STYLE INCBIN_STYLE_SNAKE +#define INCBIN_PREFIX mii_ +#include "incbin.h" + +INCBIN(proggy, "fonts/ProggyClean.ttf"); +INCBIN(droid, "fonts/DroidSans.ttf"); + diff --git a/nuklear/mii_mish.c b/nuklear/mii_mish.c new file mode 100644 index 0000000..c8c9c0c --- /dev/null +++ b/nuklear/mii_mish.c @@ -0,0 +1,436 @@ +/* + * mii_mish.c + * + * Copyright (C) 2023 Michel Pollet + * + * SPDX-License-Identifier: MIT + */ + +#include +#include +#include +#include +#include +#include + +#include "mii.h" +#include "mii_bank.h" +#include "mii_sw.h" +#include "mii_65c02_ops.h" +#include "mii_65c02_disasm.h" + +extern mii_t g_mii; + +void +_mii_mish_text( + void * param, + int argc, + const char * argv[]) +{ + // load 0x400, calculate the 24 line addresses from the code in video + // and show the 40 or 80 chars, depending on col80 + mii_t * mii = &g_mii; + uint16_t a = 0x400; + int page2 = mii_read_one(mii, SWPAGE2); +// int col80 = mii_read_one(mii, SW80COL); + for (int li = 0; li < 24; li++) { + int i = li; + a = (0x400 + (0x400 * page2)); + a += ((i & 0x07) << 7) | ((i >> 3) << 5) | ((i >> 3) << 3); + printf("%04x: ", a); + for (int ci = 0; ci < 40; ci++) { + uint8_t c = (mii_read_one(mii, a++) & 0x3f); + printf("%c", c >= 0x20 && c < 0x7f ? c : '.'); + } + printf("\n"); + } +} + +static void +_mii_mish_cmd( + void * param, + int argc, + const char * argv[]) +{ + const char * state[] = { "RUNNING", "STOPPED", "STEP" }; + mii_t * mii = &g_mii; + if (!argv[1]) { +show_state: + printf("mii: %s Target speed: %.3fMHz Current: %.3fMHz\n", + state[mii->state], mii->speed, mii->speed_current); + mii_dump_run_trace(mii); + mii_dump_trace_state(mii); + + mii_bank_t * main = &mii->bank[MII_BANK_MAIN]; + bool text = !!mii_bank_peek(main, SWTEXT); + bool page2 = !!mii_bank_peek(main, SWPAGE2); + bool col80 = !!mii_bank_peek(main, SW80COL); + bool mixed = !!mii_bank_peek(main, SWMIXED); + bool hires = !!mii_bank_peek(main, SWHIRES); + bool dhires = !!mii_bank_peek(main, SWRDDHIRES); + + printf("text:%d page2:%d col80:%d mixed:%d hires:%d dhires:%d\n", + text, page2, col80, mixed, hires, dhires); + return; + } + if (!strcmp(argv[1], "reset")) { + mii_reset(mii, 0); + return; + } + if (!strcmp(argv[1], "mem")) { + for (int i = 0; i < 16; i++) { + printf("%02x: ", i * 16); + for (int j = 0; j < 16; j++) + printf("%d:%d ", mii->mem[(i * 16) + j].read, + mii->mem[(i * 16) + j].write); + printf("\n"); + } + return; + } + if (!strcmp(argv[1], "trace")) { + mii->trace_cpu = !mii->trace_cpu; + printf("trace_cpu %d\n", mii->trace_cpu); + return; + } + if (!strcmp(argv[1], "poke")) { + if (argc < 4) { + printf("poke: missing argument\n"); + return; + } + uint16_t addr = strtol(argv[2], NULL, 16); + uint8_t val = strtol(argv[3], NULL, 16); + mii_mem_access(mii, addr, &val, false, true); + return; + } + if (!strcmp(argv[1], "peek")) { + if (argc < 3) { + printf("peek: missing argument\n"); + return; + } + uint16_t addr = strtol(argv[2], NULL, 16); + uint8_t val; + mii_mem_access(mii, addr, &val, false, false); + printf("%04x: %02x\n", addr, val); + return; + } + if (!strcmp(argv[1], "speed")) { + if (argc < 3) { + printf("speed: missing argument\n"); + return; + } + float speed = atof(argv[2]); + if (speed < 0.1 || speed > 30.0) { + printf("speed: speed must be between 0.0 and 30.0\n"); + return; + } + mii->speed = speed; + printf("speed: %.3fMHz\n", speed); + return; + } + if (!strcmp(argv[1], "stop")) { + mii->state = MII_STOPPED; + goto show_state; + } + printf("mii: unknown command %s\n", argv[1]); +} + +void +_mii_mish_bp( + void * param, + int argc, + const char * argv[]) +{ + mii_t * mii = &g_mii; + if (!argv[1] || !strcmp(argv[1], "list")) { + printf("breakpoints: map %04x\n", mii->debug.bp_map); + for (int i = 0; i < (int)sizeof(mii->debug.bp_map)*8; i++) { + printf("%2d %c %04x %c%c%c size:%2d\n", i, + (mii->debug.bp_map & (1 << i)) ? '*' : ' ', + mii->debug.bp[i].addr, + (mii->debug.bp[i].kind & MII_BP_R) ? 'r' : '-', + (mii->debug.bp[i].kind & MII_BP_W) ? 'w' : '-', + (mii->debug.bp[i].kind & MII_BP_STICKY) ? 's' : '-', + mii->debug.bp[i].size); + } + return; + } + const char *p = argv[1]; + if (p[0] == '+') { + p++; + int addr = strtol(p, NULL, 16); + int kind = 0; + if (strchr(p, 'r')) + kind |= MII_BP_R; + if (strchr(p, 'w')) + kind |= MII_BP_W; + if (strchr(p, 's')) + kind |= MII_BP_STICKY; + if (!kind || kind == MII_BP_STICKY) + kind |= MII_BP_R; + int size = 1; + if (argv[2]) + size = strtol(argv[2], NULL, 16); + if (!size) size++; + for (int i = 0; i < (int)sizeof(mii->debug.bp_map)*8; i++) { + if (!(mii->debug.bp_map & (1 << i)) || mii->debug.bp[i].addr == addr) { + mii->debug.bp_map |= 1 << i; + mii->debug.bp[i].addr = addr; + mii->debug.bp[i].kind = kind; + mii->debug.bp[i].size = size; + printf("breakpoint %d set at %04x size %d\n", i, addr, size); + break; + } + } + return; + } + if (p[0] == '-') { + p++; + int idx = strtol(p, NULL, 10); + if (idx >= 0 && idx < 7) { + mii->debug.bp_map &= ~(1 << idx); + printf("breakpoint %d cleared\n", idx); + } + } +} + + +static void +_mii_mish_il( + void * param, + int argc, + const char * argv[]) +{ + static uint16_t addr = 0x800; + if (argv[1]) { + addr = strtol(argv[1], NULL, 16); + if (addr >= 0xffff) + addr = 0xfff0; + } + mii_t * mii = &g_mii; + + for (int li = 0; li < 20; li++) { + uint8_t op[16]; + for (int bi = 0; bi < 4; bi++) + mii_mem_access(mii, addr + bi, op + bi, false, false); + char dis[64]; + addr += mii_cpu_disasm_one(op, addr, dis, sizeof(dis), + MII_DUMP_DIS_PC | MII_DUMP_DIS_DUMP_HEX); + printf("%s\n", dis); + } +} + +static void +_mii_mish_dm( + void * param, + int argc, + const char * argv[]) +{ + static uint16_t addr = 0x800; + if (argv[1]) { + addr = strtol(argv[1], NULL, 16); + if (addr >= 0xffff) + addr = 0xfff0; + } + mii_t * mii = &g_mii; + if (!strcmp(argv[0], "dm")) { + printf("dm: %04x\n", addr); + for (int i = 0; i < 8; i++) { + printf("%04x: ", addr); + for (int j = 0; j < 16; j++) + printf("%02x ", mii_read_one(mii, addr++)); + printf("\n"); + } + return; + } + if (!strcmp(argv[0], "db")) { + printf("%s: %04x: ", argv[0], addr); + printf("%02x ", mii_read_one(mii, addr++)); + printf("\n"); + return; + } + if (!strcmp(argv[0], "dw") || !strcmp(argv[0], "da")) { + printf("%s: %04x: ", argv[0], addr); + uint8_t l = mii_read_one(mii, addr++); + uint8_t h = mii_read_one(mii, addr++); + printf("%02x%02x", h, l); + printf("\n"); + return; + } +} + + +static void +_mii_mish_step( + void * param, + int argc, + const char * argv[]) +{ + if (argv[0][0] == 's') { + mii_t * mii = &g_mii; + if (argv[1]) { + int n = strtol(argv[1], NULL, 10); + mii->trace.step_inst = n; + } else + mii->trace.step_inst = 1; + mii->state = MII_STEP; + return; + } + if (argv[0][0] == 'n') { + mii_t * mii = &g_mii; + // read current opcode, find how how many bytes it take, + // then put a temporary breakpoint to the next PC. + // all of that if this is not a relative branch of course, in + // which case we use a normal 'step' behaviour + uint8_t op; + mii_mem_access(mii, mii->cpu.PC, &op, false, false); + if (op == 0x20) { + // set a temp breakpoint on reading 3 bytes from PC + for (int i = 0; i < (int)sizeof(mii->debug.bp_map) * 8; i++) { + if ((mii->debug.bp_map & (1 << i))) + continue; + mii->debug.bp[i].addr = mii->cpu.PC + 3; + mii->debug.bp[i].kind = MII_BP_R; + mii->debug.bp[i].size = 1; + mii->debug.bp[i].silent = 1; + mii->debug.bp_map |= 1 << i; + mii->state = MII_RUNNING; + return; + } + printf("no more breakpoints available\n"); + } else { + mii->trace.step_inst = 1; + mii->state = MII_STEP; + } + return; + } + if (argv[0][0] == 'c') { + mii_t * mii = &g_mii; + mii->trace.step_inst = 0; + mii->state = MII_RUNNING; + return; + } + if (argv[0][0] == 'h') { + mii_t * mii = &g_mii; + mii->trace.step_inst = 0; + mii->state = MII_STOPPED; + return; + } +} + +extern int g_mii_audio_record_fd; + +#include + +static void +_mii_mish_audio( + void * param, + int argc, + const char * argv[]) +{ + if (argc < 2) { + printf("audio: missing argument\n"); + return; + } + if (!strcmp(argv[1], "record")) { + if (g_mii_audio_record_fd != -1) { + close(g_mii_audio_record_fd); + g_mii_audio_record_fd = -1; + printf("audio: stop recording\n"); + } else { + g_mii_audio_record_fd = open("audio.raw", + O_WRONLY | O_CREAT | O_TRUNC, 0644); + printf("audio: start recording\n"); + } + } else if (!strcmp(argv[1], "mute")) { + if (argv[2] && !strcmp(argv[2], "off")) + g_mii.speaker.muted = false; + else if (argv[2] && !strcmp(argv[2], "on")) + g_mii.speaker.muted = true; + else if (!argv[2] || (argv[2] && !strcmp(argv[2], "toggle"))) + g_mii.speaker.muted = !g_mii.speaker.muted; + printf("audio: %s\n", g_mii.speaker.muted ? "muted" : "unmuted"); + } else if (!strcmp(argv[1], "volume")) { + if (argc < 3) { + printf("audio: missing volume\n"); + return; + } + // convert a linear volume from 0 to 10 into a float from 0.0 to 1.0 + float vol = atof(argv[2]); + if (vol < 0) vol = 0; + else if (vol > 10) vol = 10; + mii_speaker_volume(&g_mii.speaker, vol); + printf("audio: volume %.3f (amp: %.4f)\n", + vol, g_mii.speaker.vol_multiplier); + } else { + printf("audio: unknown command %s\n", argv[1]); + } +} + +#include "mish.h" + +MISH_CMD_NAMES(mii, "mii"); +MISH_CMD_HELP(mii, + "mii: access internals, trace, reset, speed, etc", + " : dump current state", + " reset : reset the cpu", + " t|trace : toggle trace_cpu (WARNING HUGE traces!))", + " mem : dump memory and bank map", + " poke : poke a value in memory (respect SW)", + " peek : peek a value in memory (respect SW)", + " speed : set speed in MHz", + " stop : stop the cpu" + ); +MISH_CMD_REGISTER(mii, _mii_mish_cmd); + +MISH_CMD_NAMES(bp, "bp"); +MISH_CMD_HELP(bp, + "mii: breakpoints. 'sticky' means the breakpoint is re-armed after hit", + " : dump state", + " +[r|w][s] [size]: add at for read/write, sticky", + " - : disable (don't clear) breakpoint " + ); +MISH_CMD_REGISTER(bp, _mii_mish_bp); + +MISH_CMD_NAMES(il, "il"); +MISH_CMD_HELP(il, + "mii: disassembly", + " : list next 20 instructions.", + " [addr]: start at address addr" + ); +MISH_CMD_REGISTER(il, _mii_mish_il); + +MISH_CMD_NAMES(dm, "dm","db","dw","da"); +MISH_CMD_HELP(dm, + "mii: dump memory, byte, word, address", + " |dm : dump 64 bytes.", + " db []: dump one byte.", + " dw []: dump one word.", + " da []: dump one address.", + " [addr]: start at address addr" + ); +MISH_CMD_REGISTER(dm, _mii_mish_dm); + +MISH_CMD_NAMES(step, "s","step","n","next","cont","h","halt"); +MISH_CMD_HELP(step, + "mii: step instructions", + " s|step [num]: step [num, or one] instruction.", + " n|next : step one instruction, skip subroutines.", + " cont : continue execution." + ); +MISH_CMD_REGISTER(step, _mii_mish_step); + +MISH_CMD_NAMES(text, "text"); +MISH_CMD_HELP(text, + "mii: show text page [buggy]", + " : that's it" + ); +MISH_CMD_REGISTER(text, _mii_mish_text); + +MISH_CMD_NAMES(audio, "audio"); +MISH_CMD_HELP(audio, + "audio: audio control/debug", + " record: record/stop debug file.", + " mute: mute/unmute audio.", + " volume: set volume (0.0 to 1.0)." + ); +MISH_CMD_REGISTER(audio, _mii_mish_audio); diff --git a/nuklear/mii_mish_dd.c b/nuklear/mii_mish_dd.c new file mode 100644 index 0000000..42d7052 --- /dev/null +++ b/nuklear/mii_mish_dd.c @@ -0,0 +1,46 @@ +/* + * mii_mish_dd.c + * + * Copyright (C) 2023 Michel Pollet + * + * SPDX-License-Identifier: MIT + */ + +#include +#include +#include +#include + +#include "mii.h" + +extern mii_t g_mii; + + +static void +_mii_mish_dd( + void * param, + int argc, + const char * argv[]) +{ + if (!argv[1] || !strcmp(argv[1], "list")) { + mii_dd_t *d = g_mii.dd.drive; + printf(" ID %-16s %-20s\n", "Card", "Name"); + while (d) { + printf("%d:%d %-16s %-20s : %s\n", + d->slot_id, d->drive, + d->slot->drv->desc, + d->name, d->file ? d->file->pathname : "*empty*"); + d = d->next; + } + return; + } +} + +#include "mish.h" + +MISH_CMD_NAMES(dd, "dd", "disk"); +MISH_CMD_HELP(dd, + "mii: disk commands", + " |list: list all disk drives" + ); +MISH_CMD_REGISTER(dd, _mii_mish_dd); \ No newline at end of file diff --git a/nuklear/mii_nuklear.c b/nuklear/mii_nuklear.c new file mode 100644 index 0000000..935f857 --- /dev/null +++ b/nuklear/mii_nuklear.c @@ -0,0 +1,626 @@ +/* + * mii_nuklear.c + * + * Copyright (C) 2023 Michel Pollet + * + * SPDX-License-Identifier: MIT + */ + +#include +#include +#include +#include +#include +#include + +#include "mii.h" +#include "mii_bank.h" +#include "mii_sw.h" + +#define NK_INCLUDE_FIXED_TYPES +#define NK_INCLUDE_STANDARD_IO +#define NK_INCLUDE_STANDARD_VARARGS +#define NK_INCLUDE_DEFAULT_ALLOCATOR +#define NK_INCLUDE_VERTEX_BUFFER_OUTPUT +#define NK_INCLUDE_FONT_BAKING +#define NK_INCLUDE_DEFAULT_FONT +#define NK_BUTTON_TRIGGER_ON_RELEASE +#include "nuklear.h" +#include "nuklear_xlib_gl3.h" +//#include "stb_image_write.h" +#include +#include + +#define _NK_RGBA(_r,_g,_b,_a) {.r=_r,.g=_g,.b=_b,.a=_a} +static const struct nk_color style[NK_COLOR_COUNT] = { + [NK_COLOR_TEXT] = _NK_RGBA(0, 0, 0, 255), + [NK_COLOR_WINDOW] = _NK_RGBA(175, 175, 175, 255), + [NK_COLOR_HEADER] = _NK_RGBA(175, 175, 175, 255), + [NK_COLOR_BORDER] = _NK_RGBA(0, 0, 0, 255), + [NK_COLOR_BUTTON] = _NK_RGBA(185, 185, 185, 255), + [NK_COLOR_BUTTON_HOVER] = _NK_RGBA(170, 170, 170, 255), + [NK_COLOR_BUTTON_ACTIVE] = _NK_RGBA(160, 160, 160, 255), + [NK_COLOR_TOGGLE] = _NK_RGBA(150, 150, 150, 255), + [NK_COLOR_TOGGLE_HOVER] = _NK_RGBA(120, 120, 120, 255), + [NK_COLOR_TOGGLE_CURSOR] = _NK_RGBA(175, 175, 175, 255), + [NK_COLOR_SELECT] = _NK_RGBA(190, 190, 190, 255), + [NK_COLOR_SELECT_ACTIVE] = _NK_RGBA(175, 175, 175, 255), + [NK_COLOR_SLIDER] = _NK_RGBA(190, 190, 190, 255), + [NK_COLOR_SLIDER_CURSOR] = _NK_RGBA(80, 80, 80, 255), + [NK_COLOR_SLIDER_CURSOR_HOVER] = _NK_RGBA(70, 70, 70, 255), + [NK_COLOR_SLIDER_CURSOR_ACTIVE] = _NK_RGBA(60, 60, 60, 255), + [NK_COLOR_PROPERTY] = _NK_RGBA(175, 175, 175, 255), + [NK_COLOR_EDIT] = _NK_RGBA(150, 150, 150, 255), + [NK_COLOR_EDIT_CURSOR] = _NK_RGBA(0, 0, 0, 255), + [NK_COLOR_COMBO] = _NK_RGBA(175, 175, 175, 255), + [NK_COLOR_CHART] = _NK_RGBA(160, 160, 160, 255), + [NK_COLOR_CHART_COLOR] = _NK_RGBA(45, 45, 45, 255), + [NK_COLOR_CHART_COLOR_HIGHLIGHT] = _NK_RGBA( 255, 0, 0, 255), + [NK_COLOR_SCROLLBAR] = _NK_RGBA(180, 180, 180, 255), + [NK_COLOR_SCROLLBAR_CURSOR] = _NK_RGBA(140, 140, 140, 255), + [NK_COLOR_SCROLLBAR_CURSOR_HOVER] = _NK_RGBA(150, 150, 150, 255), + [NK_COLOR_SCROLLBAR_CURSOR_ACTIVE] = _NK_RGBA(160, 160, 160, 255), + [NK_COLOR_TAB_HEADER] = _NK_RGBA(180, 180, 180, 255), +}; + +static GLuint screen_texture; +static struct nk_image screen_nk; + + +#include + +typedef uint64_t mii_time_t; +enum { + MII_TIME_RES = 1, + MII_TIME_SECOND = 1000000, + MII_TIME_MS = (MII_TIME_SECOND/1000), +}; +mii_time_t +mii_get_time() +{ + struct timespec tim; + clock_gettime(CLOCK_MONOTONIC_RAW, &tim); + uint64_t time = ((uint64_t)tim.tv_sec) * (1000000 / MII_TIME_RES) + + tim.tv_nsec / (1000 * MII_TIME_RES); + return time; +} + +#include +#include "fifo_declare.h" + +static pthread_t mii_thread; +static bool mii_thread_running = false; +//static mii_trace_t mii_trace = {}; +float default_fps = 60; + +enum { + SIGNAL_RESET, + SIGNAL_STOP, + SIGNAL_STEP, + SIGNAL_RUN, +}; + +typedef struct { + uint8_t cmd; + uint8_t data; +} signal_t; + +DECLARE_FIFO(signal_t, signal_fifo, 16); +DEFINE_FIFO(signal_t, signal_fifo); + +signal_fifo_t signal_fifo; + +static void *mii_thread_func(void *arg) +{ + mii_t *mii = (mii_t *) arg; + mii_thread_running = true; + __uint128_t last_cycles = mii->cycles; + uint32_t running = 1; + unsigned long target_fps_us = 1000000 / default_fps; + long sleep_time = target_fps_us; + + //mii_time_t base = mii_get_time(NULL); + uint32_t last_frame = mii->video.frame_count; + mii_time_t last_frame_stamp = mii_get_time(); + while (mii_thread_running) { + signal_t sig; + while (!signal_fifo_isempty(&signal_fifo)) { + sig = signal_fifo_read(&signal_fifo); + switch (sig.cmd) { + case SIGNAL_RESET: + mii_reset(mii, sig.data); + break; + case SIGNAL_STOP: + mii_dump_run_trace(mii); + mii_dump_trace_state(mii); + mii->state = MII_STOPPED; + break; + case SIGNAL_STEP: + mii->state = MII_STEP; + running = 1; + break; + case SIGNAL_RUN: + mii->state = MII_RUNNING; + last_frame_stamp = mii_get_time(); + running = 1; + break; + } + } + if (mii->state != MII_STOPPED) + mii_run(mii); + + switch (mii->state) { + case MII_STOPPED: + usleep(1000); + break; + case MII_STEP: + if (running) { + running--; + mii_dump_trace_state(mii); + usleep(1000); + running = 1; + if (mii->trace.step_inst) + mii->trace.step_inst--; + if (mii->trace.step_inst == 0) + mii->state = MII_STOPPED; + } + break; + case MII_RUNNING: + break; + } + + if (mii->video.frame_count != last_frame) { + sleep_time = target_fps_us; + mii_time_t now = mii_get_time(); + if (mii->state == MII_RUNNING) { + mii_time_t delta = now - last_frame_stamp; + // printf("frame time %d/%d sleep time %d\n", + // (int)delta, (int)target_fps_us, + // (int)target_fps_us - delta); + sleep_time = target_fps_us - delta; + if (sleep_time < 0) + sleep_time = 0; + last_frame = mii->video.frame_count; + while (last_frame_stamp <= now) + last_frame_stamp += target_fps_us; + + // calculate the MHz + __uint128_t cycles = mii->cycles; + __uint128_t delta_cycles = cycles - last_cycles; + last_cycles = cycles; + mii->speed_current = delta_cycles / (float)target_fps_us; + } + usleep(sleep_time); + } + } + return NULL; +} + +extern struct nk_font *nk_main_font; +struct nk_font *nk_mono_font = NULL; + +extern const unsigned char mii_proggy_data[]; +extern const unsigned int mii_proggy_size; +extern const unsigned char mii_droid_data[]; +extern const unsigned int mii_droid_size; + +void +mii_nuklear_init( + mii_t *mii, + struct nk_context *ctx) +{ + nk_style_from_table(ctx, style); + + { + struct nk_font_atlas *atlas; + nk_x11_font_stash_begin(&atlas); + struct nk_font_config cfg = nk_font_config(0); + #if 0 + nk_rune ranges[] = { + 0x0020, 0x007E, /* Ascii */ + 0x00A1, 0x00FF, /* Symbols + Umlaute */ + 0 + }; + #endif + cfg.range = nk_font_default_glyph_ranges(); + cfg.oversample_h = cfg.oversample_v = 1; + cfg.pixel_snap = true; + struct nk_font *nkf = nk_font_atlas_add_from_memory(atlas, + (void*)mii_proggy_data, mii_proggy_size, 20, &cfg); + nk_x11_font_stash_end(); + nk_mono_font = nkf; + } + + glGenTextures(1, &screen_texture); + glBindTexture(GL_TEXTURE_2D, screen_texture); + + glTexImage2D(GL_TEXTURE_2D, 0, 4, + MII_VRAM_WIDTH, + MII_VRAM_HEIGHT, 0, GL_RGBA, + GL_UNSIGNED_BYTE, + mii->video.pixels); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); +// printf("%s texture created %d\n", __func__, screen_texture); +// display opengl error + GLenum err = glGetError(); + if (err != GL_NO_ERROR) { + printf("Error creating texture: %d\n", err); + } + screen_nk = nk_subimage_id( + screen_texture, MII_VRAM_WIDTH, MII_VRAM_HEIGHT, + nk_rect(0, 0, MII_VIDEO_WIDTH, MII_VIDEO_HEIGHT)); + + /* start the thread */ + pthread_create(&mii_thread, NULL, mii_thread_func, mii); + +} + + +extern int disk2_debug; +int show_zero_page = 0; + +static void +mii_nuklear_handle_input( + mii_t *mii, + struct nk_context *ctx) +{ + struct nk_input *in = &ctx->input; + if (in->keyboard.text_len) { + // printf("INPUT %d %s\n", in->keyboard.text_len, in->keyboard.text); + if (in->keyboard.text_len < 4) { + mii_keypress(mii, in->keyboard.text[0]); + } else if (in->keyboard.text_len > 1) { + uint32_t *raw = ((uint32_t *) in->keyboard.text); + for (int ki = 0; ki < in->keyboard.text_len / 4; ki ++) { + uint32_t key = (raw[ki] >> 16) & 0xffff; + uint8_t down = raw[ki] & 0xff; + printf("KEY %04x %s\n", key, down ? "down" : "up"); + if (down) { + if (key == 0xffc9) { // F12 + if (nk_input_is_key_down(in, NK_KEY_CTRL)) { + signal_t sig = { + .cmd = SIGNAL_RESET, + .data = nk_input_is_key_down(in, NK_KEY_SHIFT) + }; + signal_fifo_write(&signal_fifo, sig); + printf("RESET\n"); + } + } else if (key == 0xffc8) { // F11 + if (nk_input_is_key_down(in, NK_KEY_CTRL)) { + signal_t sig = { + .cmd = SIGNAL_STOP, + }; + signal_fifo_write(&signal_fifo, sig); + printf("STOP\n"); + } + } else if (key == 0xffc7) { // F10 + if (nk_input_is_key_down(in, NK_KEY_CTRL)) { + signal_t sig = { + .cmd = SIGNAL_STEP, + }; + signal_fifo_write(&signal_fifo, sig); + printf("STEP\n"); + } + } else if (key == 0xffc6) { // F9 + if (nk_input_is_key_down(in, NK_KEY_CTRL)) { + signal_t sig = { + .cmd = SIGNAL_RUN, + }; + signal_fifo_write(&signal_fifo, sig); + printf("RUN\n"); + } + } else if (key == 0xffc2) { // F5 + mii->speed = 1.0; + printf("Speed Normal (1MHz)\n"); + } else if (key == 0xffc3) { // F6 + mii->speed = 4; + printf("Speed Fast (4MHz)\n"); + } + } + if (key == 0xffeb || key == 0xffec) { // super left/right + key -= 0xffeb; + mii_bank_t *bank = &mii->bank[MII_BANK_MAIN]; + uint8_t old = mii_bank_peek(bank, 0xc061 + key); + mii_bank_poke(bank, 0xc061 + key, down ? 0x80 : 0); + if (!!down != !!old) { + printf("Apple %s %s\n", key ? "Open" : "Close", + down ? "down" : "up"); + } + } + } + } + in->keyboard.text_len = 0; + } else { + signal_t sig = {.cmd = -1 }; + if (nk_input_is_key_pressed(in, NK_KEY_ENTER)) + sig.data = 0x0d; + else if (nk_input_is_key_pressed(in, NK_KEY_BACKSPACE)) + sig.data = 0x08; + else if (nk_input_is_key_pressed(in, NK_KEY_DEL)) + sig.data = 0x7f; + else if (nk_input_is_key_pressed(in, NK_KEY_UP)) + sig.data = 'K' - 'A' + 1; + else if (nk_input_is_key_pressed(in, NK_KEY_DOWN)) + sig.data = 'J' - 'A' + 1; + else if (nk_input_is_key_pressed(in, NK_KEY_LEFT)) + sig.data = 'H' - 'A' + 1; + else if (nk_input_is_key_pressed(in, NK_KEY_RIGHT)) + sig.data = 'U' - 'A' + 1; + else if (nk_input_is_key_pressed(in, NK_KEY_ESCAPE)) + sig.data = 0x1b; + if (sig.data) { + // signal_fifo_write(&signal_fifo, sig); + // printf("Key %d\n", sig.data); + mii_keypress(mii, sig.data); + } + } +} + +void +mii_nuklear( + mii_t *mii, + struct nk_context *ctx) +{ + if (mii->video.frame_count != mii->video.frame_drawn) { + mii->video.frame_drawn = mii->video.frame_count; + // update texture with new pixels; we only need 192 lines, the others + // are padding for the power of 2 texture + glBindTexture(GL_TEXTURE_2D, screen_texture); + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, + MII_VRAM_WIDTH, + MII_VIDEO_HEIGHT, GL_RGBA, + GL_UNSIGNED_BYTE, + mii->video.pixels); + } + mii_nuklear_handle_input(mii, ctx); + int height = 720 - 8; + int width = MII_VIDEO_WIDTH * (height / (float)MII_VIDEO_HEIGHT); + int xpos = 1280 / 2 - width / 2; + { + struct nk_style *s = &ctx->style; + nk_style_push_color(ctx, &s->window.background, + nk_rgba(0,0,0, 255)); + nk_style_push_style_item(ctx, &s->window.fixed_background, + nk_style_item_color(nk_rgba(0,0,0, 255))); + if (nk_begin(ctx, "Apple //e Enhanced", + nk_rect(xpos, 0, width + 10, height + 20), + NK_WINDOW_NO_SCROLLBAR)) { + nk_layout_row_static(ctx, height, width, 1); + static int was_in = -1; + if (nk_widget_is_hovered(ctx) && mii->mouse.enabled) { + if (was_in != 1) { + was_in = 1; + ctx->input.mouse.grab = 1; + // printf("IN\n"); + } + struct nk_rect bounds = nk_widget_bounds(ctx); + // normalize mouse coordinates + double x = ctx->input.mouse.pos.x - bounds.x; + double y = ctx->input.mouse.pos.y - bounds.y; + // get mouse button state + int button = ctx->input.mouse.buttons[NK_BUTTON_LEFT].down; + // clamp coordinates inside bounds + double vw = bounds.w; + double vh = bounds.h; + double mw = mii->mouse.max_x - mii->mouse.min_x; + double mh = mii->mouse.max_y - mii->mouse.min_y; + mii->mouse.x = mii->mouse.min_x + (x * mw / vw) + 0.5; + mii->mouse.y = mii->mouse.min_y + (y * mh / vh) + 0.5; + mii->mouse.button = button; + // printf("Mouse is %d %d\n", (int)mii->mouse.x, (int)mii->mouse.y); + } else { + if (was_in == 1) { + was_in = 0; + ctx->input.mouse.ungrab = 1; + // printf("OUT\n"); + } + } + nk_image(ctx, screen_nk); + nk_end(ctx); + nk_style_pop_color(ctx); + nk_style_pop_style_item(ctx); + } + } + + struct nk_rect bounds = { .x = 0, .y = 0, .w = xpos, .h = height }; +// nk_window_get_bounds(ctx); + bool in = nk_input_is_mouse_hovering_rect(&ctx->input, bounds); + static bool menu_open = false; + + if (in || menu_open) { + struct nk_style *s = &ctx->style; + nk_style_push_color(ctx, &s->window.background, + nk_rgba(175, 175, 175, 255)); + nk_style_push_style_item(ctx, &s->window.fixed_background, + nk_style_item_color(nk_rgba(175, 175, 175, 255))); + + if (nk_begin(ctx, "Left Bar", + nk_rect(0, 0, xpos, height + 20), + NK_WINDOW_NO_SCROLLBAR)) { +#if 0 + nk_menubar_begin(ctx); + nk_layout_row_begin(ctx, NK_STATIC, 25, 2); + nk_layout_row_push(ctx, 60); + bool menu = false; + if (nk_menu_begin_label(ctx, "MII", NK_TEXT_LEFT, + nk_vec2(140, 200))) { + static size_t prog = 40; + static float slider = 0.5; + static int check = nk_true; + nk_layout_row_dynamic(ctx, 25, 1); + if (nk_menu_item_label(ctx, "Hide", NK_TEXT_LEFT)) + ;//show_menu = nk_false; + if (nk_menu_item_label(ctx, "About", NK_TEXT_LEFT)) + ;//show_app_about = nk_true; + nk_progress(ctx, &prog, 100, NK_MODIFIABLE); + nk_slider_float(ctx, 0.01, &slider, 1.0, 0.05); + nk_checkbox_label(ctx, "Mute", &check); + nk_menu_end(ctx); + menu = true; + } + menu_open = menu; + nk_menubar_end(ctx); + nk_layout_space_end(ctx); +#endif + int rw = xpos - 8; + // nk_layout_row_dynamic(ctx, 4, 1); + // nk_spacing(ctx, 1); + + nk_layout_row_static(ctx, 30, rw, 1); + if (nk_button_label(ctx, "C-RESET")) + mii_reset(mii, false); + if (nk_button_label(ctx, "C-OA-RESET")) + mii_reset(mii, true); +// nk_layout_row_dynamic(ctx, 0, 1); + nk_layout_row_begin(ctx, NK_STATIC, 30, 2); + nk_layout_row_push(ctx, 20); + nk_label(ctx, "V:", NK_TEXT_LEFT); + nk_layout_row_push(ctx, rw - 20 - 4); + const char *video_modes[] = { + "Color", + "Green", + "Amber", + }; + mii->video.color_mode = nk_combo(ctx, + video_modes, NK_LEN(video_modes), + mii->video.color_mode, 25, nk_vec2(80,200)); + nk_layout_space_end(ctx); + + nk_layout_row_begin(ctx, NK_STATIC, 30, 1); + nk_layout_row_push(ctx, rw); + const char *speed[] = { + "1 MHz", + "Slow", + "Fast", + }; + nk_label(ctx, "Speed:", NK_TEXT_LEFT); + nk_layout_row_push(ctx, 100); + int spi = 0; + spi = nk_combo(ctx, + speed, NK_LEN(speed), + spi, 25, nk_vec2(80,200)); + nk_layout_space_end(ctx); + + } + nk_end(ctx); + nk_style_pop_color(ctx); + nk_style_pop_style_item(ctx); + } + if ( 0 && nk_begin(ctx, "Controls", + nk_rect(width, 0, 350, 10 + 192 * 3), + NK_WINDOW_NO_SCROLLBAR)) { + nk_layout_row_static(ctx, 30, 110, 2); + if (nk_button_label(ctx, "C-RESET")) + mii_reset(mii, false); + if (nk_button_label(ctx, "C-OA-RESET")) + mii_reset(mii, true); + #if 0 + if (nk_button_label(ctx, "Screenshot")) { + stbi_write_png("screen.png", + MII_VIDEO_WIDTH, MII_VIDEO_HEIGHT, 4, mii->video.pixels, + MII_VRAM_WIDTH * 4); + printf("Screenshot taken\n"); + } + #endif + nk_layout_row_dynamic(ctx, 30, 4); + nk_label(ctx, "Speed:", NK_TEXT_CENTERED); + if (nk_option_label(ctx, "Slow", mii->speed < 0.9)) mii->speed = 0.2; + if (nk_option_label(ctx, "1 MHz", mii->speed > .95 && mii->speed < 1.05)) mii->speed = 1.0; + if (nk_option_label(ctx, "Fast", mii->speed > 1.1 && mii->speed < 4.1)) mii->speed = 4.0; + + nk_layout_row_dynamic(ctx, 30, 4); + nk_label(ctx, "Video:", NK_TEXT_CENTERED); + if (nk_option_label(ctx, "Color", mii->video.color_mode == MII_VIDEO_COLOR)) + mii->video.color_mode = MII_VIDEO_COLOR; + if (nk_option_label(ctx, "Green", mii->video.color_mode == MII_VIDEO_GREEN)) + mii->video.color_mode = MII_VIDEO_GREEN; + if (nk_option_label(ctx, "Amber", mii->video.color_mode == MII_VIDEO_AMBER)) + mii->video.color_mode = MII_VIDEO_AMBER; + +#if 0 + nk_layout_row_dynamic(ctx, 20, 1); + nk_style_set_font(ctx, &nk_mono_font->handle); + struct nk_color save = ctx->style.window.background; + + ctx->style.window.background = (struct nk_color)_NK_RGBA(0, 0, 0, 255); + struct nk_color fore = (struct nk_color)_NK_RGBA(0, 255, 0, 255); + char label[64]; + mii_dasm_t _dasm = {}; + mii_dasm_t *dasm = &_dasm; + mii_dasm_init(dasm, mii, 0); + dasm->mii = mii; + // display the last few cycles up to the PC + for (int di = 0; di < 3; di++) { + int pci = (mii_trace.idx + MII_PC_LOG_SIZE - 3 + di) % MII_PC_LOG_SIZE; + dasm->pc = mii_trace.log[pci]; + mii_dasm_step(dasm, label, sizeof(label)); + if (di == 2) + label[0] = '*'; + nk_label_colored(ctx, label, NK_TEXT_LEFT, fore); + } + // and the (potentially) next instruction here + mii_dasm_step(dasm, label, sizeof(label)); + nk_label_colored(ctx, label, NK_TEXT_LEFT, fore); + + sprintf(label, "A:%02X X:%02X Y:%02X S:%02X", + mii->cpu.A, mii->cpu.X, mii->cpu.Y, mii->cpu.S); + nk_label_colored(ctx, label, NK_TEXT_CENTERED, fore); + char n[] = {'C','Z','I','D','B','V','N'}; + label[0] = 0; + sprintf(label, "%04x ", mii->cpu.PC); + for (int i = 0; i < 7; i++) + sprintf(label + strlen(label), "%c%d ", n[i], + mii->cpu.P.P[i]); + nk_label_colored(ctx, label, NK_TEXT_CENTERED, fore); + + ctx->style.window.background = save; + nk_style_set_font(ctx, &nk_main_font->handle); +#endif + nk_layout_row_static(ctx, 30, 30, 3); + + if (nk_button_symbol(ctx, NK_SYMBOL_RECT_SOLID)) { + signal_fifo_write(&signal_fifo, (signal_t){.cmd = SIGNAL_STOP}); + } + if (nk_button_symbol(ctx, NK_SYMBOL_PLUS)) { + signal_fifo_write(&signal_fifo, (signal_t){.cmd = SIGNAL_STEP}); + } + if (nk_button_symbol(ctx, NK_SYMBOL_TRIANGLE_RIGHT)) { + signal_fifo_write(&signal_fifo, (signal_t){.cmd = SIGNAL_RUN}); + } + nk_layout_row_dynamic(ctx, 20, 3); + { + char label[32]; + sprintf(label, "CPU: %.1fMHz", mii->speed_current); + nk_label(ctx, label, NK_TEXT_CENTERED); + } +#if 0 + nk_layout_row_dynamic(ctx, 20, 2); + nk_checkbox_label(ctx, "Disk II Debug", &disk2_debug); + nk_checkbox_label(ctx, "Slowmo", &mii_SLOW); +// nk_checkbox_label(ctx, "Zero Page", &show_zero_page); +#endif + nk_end(ctx); + } + if (show_zero_page) { + if (nk_begin(ctx, "Zero Page", + nk_rect(0, 10 + 192 * 3, 600, 10 + 16 * 20), + 0 )) { + nk_layout_row_dynamic(ctx, 20, 1); + nk_style_set_font(ctx, &nk_mono_font->handle); + struct nk_color fore = (struct nk_color)_NK_RGBA(0, 255, 0, 255); + uint8_t *zp = mii->bank[0].mem; + char label[128]; + for (int ri = 0; ri < (256 / 16); ri++) { + sprintf(label, "%02x: ", ri * 16); + for (int ci = 0; ci < 16; ci++) { + sprintf(label + strlen(label), "%02X ", + zp[ri * 16 + ci]); + } + nk_label_colored(ctx, label, NK_TEXT_LEFT, fore); + } + nk_style_set_font(ctx, &nk_main_font->handle); + nk_end(ctx); + } + } +} diff --git a/nuklear/mii_stb_implement.c b/nuklear/mii_stb_implement.c new file mode 100644 index 0000000..32fa1f8 --- /dev/null +++ b/nuklear/mii_stb_implement.c @@ -0,0 +1,22 @@ +/* + * mii_stb.h + * + * Copyright (C) 2023 Michel Pollet + * + * SPDX-License-Identifier: MIT + */ + + +#define NK_INCLUDE_FIXED_TYPES +#define NK_INCLUDE_STANDARD_IO +#define NK_INCLUDE_STANDARD_VARARGS +#define NK_INCLUDE_DEFAULT_ALLOCATOR +#define NK_INCLUDE_VERTEX_BUFFER_OUTPUT +#define NK_INCLUDE_FONT_BAKING +#define NK_INCLUDE_DEFAULT_FONT +#define NK_BUTTON_TRIGGER_ON_RELEASE +#define NK_IMPLEMENTATION +#include "nuklear.h" + +#define STB_IMAGE_WRITE_IMPLEMENTATION +#include "stb_image_write.h" diff --git a/nuklear/nuklear.h b/nuklear/nuklear.h new file mode 100644 index 0000000..4012fda --- /dev/null +++ b/nuklear/nuklear.h @@ -0,0 +1,30034 @@ +/* +/// # Nuklear +/// ![](https://cloud.githubusercontent.com/assets/8057201/11761525/ae06f0ca-a0c6-11e5-819d-5610b25f6ef4.gif) +/// +/// ## Contents +/// 1. About section +/// 2. Highlights section +/// 3. Features section +/// 4. Usage section +/// 1. Flags section +/// 2. Constants section +/// 3. Dependencies section +/// 5. Example section +/// 6. API section +/// 1. Context section +/// 2. Input section +/// 3. Drawing section +/// 4. Window section +/// 5. Layouting section +/// 6. Groups section +/// 7. Tree section +/// 8. Properties section +/// 7. License section +/// 8. Changelog section +/// 9. Gallery section +/// 10. Credits section +/// +/// ## About +/// This is a minimal state immediate mode graphical user interface toolkit +/// written in ANSI C and licensed under public domain. It was designed as a simple +/// embeddable user interface for application and does not have any dependencies, +/// a default renderbackend or OS window and input handling but instead provides a very modular +/// library approach by using simple input state for input and draw +/// commands describing primitive shapes as output. So instead of providing a +/// layered library that tries to abstract over a number of platform and +/// render backends it only focuses on the actual UI. +/// +/// ## Highlights +/// - Graphical user interface toolkit +/// - Single header library +/// - Written in C89 (a.k.a. ANSI C or ISO C90) +/// - Small codebase (~18kLOC) +/// - Focus on portability, efficiency and simplicity +/// - No dependencies (not even the standard library if not wanted) +/// - Fully skinnable and customizable +/// - Low memory footprint with total memory control if needed or wanted +/// - UTF-8 support +/// - No global or hidden state +/// - Customizable library modules (you can compile and use only what you need) +/// - Optional font baker and vertex buffer output +/// - [Code available on github](https://github.com/Immediate-Mode-UI/Nuklear/) +/// +/// ## Features +/// - Absolutely no platform dependent code +/// - Memory management control ranging from/to +/// - Ease of use by allocating everything from standard library +/// - Control every byte of memory inside the library +/// - Font handling control ranging from/to +/// - Use your own font implementation for everything +/// - Use this libraries internal font baking and handling API +/// - Drawing output control ranging from/to +/// - Simple shapes for more high level APIs which already have drawing capabilities +/// - Hardware accessible anti-aliased vertex buffer output +/// - Customizable colors and properties ranging from/to +/// - Simple changes to color by filling a simple color table +/// - Complete control with ability to use skinning to decorate widgets +/// - Bendable UI library with widget ranging from/to +/// - Basic widgets like buttons, checkboxes, slider, ... +/// - Advanced widget like abstract comboboxes, contextual menus,... +/// - Compile time configuration to only compile what you need +/// - Subset which can be used if you do not want to link or use the standard library +/// - Can be easily modified to only update on user input instead of frame updates +/// +/// ## Usage +/// This library is self contained in one single header file and can be used either +/// in header only mode or in implementation mode. The header only mode is used +/// by default when included and allows including this header in other headers +/// and does not contain the actual implementation.

+/// +/// The implementation mode requires to define the preprocessor macro +/// NK_IMPLEMENTATION in *one* .c/.cpp file before #including this file, e.g.: +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~C +/// #define NK_IMPLEMENTATION +/// #include "nuklear.h" +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Also optionally define the symbols listed in the section "OPTIONAL DEFINES" +/// below in header and implementation mode if you want to use additional functionality +/// or need more control over the library. +/// +/// !!! WARNING +/// Every time nuklear is included define the same compiler flags. This very important not doing so could lead to compiler errors or even worse stack corruptions. +/// +/// ### Flags +/// Flag | Description +/// --------------------------------|------------------------------------------ +/// NK_PRIVATE | If defined declares all functions as static, so they can only be accessed inside the file that contains the implementation +/// NK_INCLUDE_FIXED_TYPES | If defined it will include header `` for fixed sized types otherwise nuklear tries to select the correct type. If that fails it will throw a compiler error and you have to select the correct types yourself. +/// NK_INCLUDE_DEFAULT_ALLOCATOR | If defined it will include header `` and provide additional functions to use this library without caring for memory allocation control and therefore ease memory management. +/// NK_INCLUDE_STANDARD_IO | If defined it will include header `` and provide additional functions depending on file loading. +/// NK_INCLUDE_STANDARD_VARARGS | If defined it will include header and provide additional functions depending on file loading. +/// NK_INCLUDE_STANDARD_BOOL | If defined it will include header `` for nk_bool otherwise nuklear defines nk_bool as int. +/// NK_INCLUDE_VERTEX_BUFFER_OUTPUT | Defining this adds a vertex draw command list backend to this library, which allows you to convert queue commands into vertex draw commands. This is mainly if you need a hardware accessible format for OpenGL, DirectX, Vulkan, Metal,... +/// NK_INCLUDE_FONT_BAKING | Defining this adds `stb_truetype` and `stb_rect_pack` implementation to this library and provides font baking and rendering. If you already have font handling or do not want to use this font handler you don't have to define it. +/// NK_INCLUDE_DEFAULT_FONT | Defining this adds the default font: ProggyClean.ttf into this library which can be loaded into a font atlas and allows using this library without having a truetype font +/// NK_INCLUDE_COMMAND_USERDATA | Defining this adds a userdata pointer into each command. Can be useful for example if you want to provide custom shaders depending on the used widget. Can be combined with the style structures. +/// NK_BUTTON_TRIGGER_ON_RELEASE | Different platforms require button clicks occurring either on buttons being pressed (up to down) or released (down to up). By default this library will react on buttons being pressed, but if you define this it will only trigger if a button is released. +/// NK_ZERO_COMMAND_MEMORY | Defining this will zero out memory for each drawing command added to a drawing queue (inside nk_command_buffer_push). Zeroing command memory is very useful for fast checking (using memcmp) if command buffers are equal and avoid drawing frames when nothing on screen has changed since previous frame. +/// NK_UINT_DRAW_INDEX | Defining this will set the size of vertex index elements when using NK_VERTEX_BUFFER_OUTPUT to 32bit instead of the default of 16bit +/// NK_KEYSTATE_BASED_INPUT | Define this if your backend uses key state for each frame rather than key press/release events +/// +/// !!! WARNING +/// The following flags will pull in the standard C library: +/// - NK_INCLUDE_DEFAULT_ALLOCATOR +/// - NK_INCLUDE_STANDARD_IO +/// - NK_INCLUDE_STANDARD_VARARGS +/// +/// !!! WARNING +/// The following flags if defined need to be defined for both header and implementation: +/// - NK_INCLUDE_FIXED_TYPES +/// - NK_INCLUDE_DEFAULT_ALLOCATOR +/// - NK_INCLUDE_STANDARD_VARARGS +/// - NK_INCLUDE_STANDARD_BOOL +/// - NK_INCLUDE_VERTEX_BUFFER_OUTPUT +/// - NK_INCLUDE_FONT_BAKING +/// - NK_INCLUDE_DEFAULT_FONT +/// - NK_INCLUDE_STANDARD_VARARGS +/// - NK_INCLUDE_COMMAND_USERDATA +/// - NK_UINT_DRAW_INDEX +/// +/// ### Constants +/// Define | Description +/// --------------------------------|--------------------------------------- +/// NK_BUFFER_DEFAULT_INITIAL_SIZE | Initial buffer size allocated by all buffers while using the default allocator functions included by defining NK_INCLUDE_DEFAULT_ALLOCATOR. If you don't want to allocate the default 4k memory then redefine it. +/// NK_MAX_NUMBER_BUFFER | Maximum buffer size for the conversion buffer between float and string Under normal circumstances this should be more than sufficient. +/// NK_INPUT_MAX | Defines the max number of bytes which can be added as text input in one frame. Under normal circumstances this should be more than sufficient. +/// +/// !!! WARNING +/// The following constants if defined need to be defined for both header and implementation: +/// - NK_MAX_NUMBER_BUFFER +/// - NK_BUFFER_DEFAULT_INITIAL_SIZE +/// - NK_INPUT_MAX +/// +/// ### Dependencies +/// Function | Description +/// ------------|--------------------------------------------------------------- +/// NK_ASSERT | If you don't define this, nuklear will use with assert(). +/// NK_MEMSET | You can define this to 'memset' or your own memset implementation replacement. If not nuklear will use its own version. +/// NK_MEMCPY | You can define this to 'memcpy' or your own memcpy implementation replacement. If not nuklear will use its own version. +/// NK_INV_SQRT | You can define this to your own inverse sqrt implementation replacement. If not nuklear will use its own slow and not highly accurate version. +/// NK_SIN | You can define this to 'sinf' or your own sine implementation replacement. If not nuklear will use its own approximation implementation. +/// NK_COS | You can define this to 'cosf' or your own cosine implementation replacement. If not nuklear will use its own approximation implementation. +/// NK_STRTOD | You can define this to `strtod` or your own string to double conversion implementation replacement. If not defined nuklear will use its own imprecise and possibly unsafe version (does not handle nan or infinity!). +/// NK_DTOA | You can define this to `dtoa` or your own double to string conversion implementation replacement. If not defined nuklear will use its own imprecise and possibly unsafe version (does not handle nan or infinity!). +/// NK_VSNPRINTF| If you define `NK_INCLUDE_STANDARD_VARARGS` as well as `NK_INCLUDE_STANDARD_IO` and want to be safe define this to `vsnprintf` on compilers supporting later versions of C or C++. By default nuklear will check for your stdlib version in C as well as compiler version in C++. if `vsnprintf` is available it will define it to `vsnprintf` directly. If not defined and if you have older versions of C or C++ it will be defined to `vsprintf` which is unsafe. +/// +/// !!! WARNING +/// The following dependencies will pull in the standard C library if not redefined: +/// - NK_ASSERT +/// +/// !!! WARNING +/// The following dependencies if defined need to be defined for both header and implementation: +/// - NK_ASSERT +/// +/// !!! WARNING +/// The following dependencies if defined need to be defined only for the implementation part: +/// - NK_MEMSET +/// - NK_MEMCPY +/// - NK_SQRT +/// - NK_SIN +/// - NK_COS +/// - NK_STRTOD +/// - NK_DTOA +/// - NK_VSNPRINTF +/// +/// ## Example +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// // init gui state +/// enum {EASY, HARD}; +/// static int op = EASY; +/// static float value = 0.6f; +/// static int i = 20; +/// struct nk_context ctx; +/// +/// nk_init_fixed(&ctx, calloc(1, MAX_MEMORY), MAX_MEMORY, &font); +/// if (nk_begin(&ctx, "Show", nk_rect(50, 50, 220, 220), +/// NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_CLOSABLE)) { +/// // fixed widget pixel width +/// nk_layout_row_static(&ctx, 30, 80, 1); +/// if (nk_button_label(&ctx, "button")) { +/// // event handling +/// } +/// +/// // fixed widget window ratio width +/// nk_layout_row_dynamic(&ctx, 30, 2); +/// if (nk_option_label(&ctx, "easy", op == EASY)) op = EASY; +/// if (nk_option_label(&ctx, "hard", op == HARD)) op = HARD; +/// +/// // custom widget pixel width +/// nk_layout_row_begin(&ctx, NK_STATIC, 30, 2); +/// { +/// nk_layout_row_push(&ctx, 50); +/// nk_label(&ctx, "Volume:", NK_TEXT_LEFT); +/// nk_layout_row_push(&ctx, 110); +/// nk_slider_float(&ctx, 0, &value, 1.0f, 0.1f); +/// } +/// nk_layout_row_end(&ctx); +/// } +/// nk_end(&ctx); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// ![](https://cloud.githubusercontent.com/assets/8057201/10187981/584ecd68-675c-11e5-897c-822ef534a876.png) +/// +/// ## API +/// +*/ +#ifndef NK_SINGLE_FILE + #define NK_SINGLE_FILE +#endif + +#ifndef NK_NUKLEAR_H_ +#define NK_NUKLEAR_H_ + +#ifdef __cplusplus +extern "C" { +#endif +/* + * ============================================================== + * + * CONSTANTS + * + * =============================================================== + */ +#define NK_UNDEFINED (-1.0f) +#define NK_UTF_INVALID 0xFFFD /* internal invalid utf8 rune */ +#define NK_UTF_SIZE 4 /* describes the number of bytes a glyph consists of*/ +#ifndef NK_INPUT_MAX + #define NK_INPUT_MAX 16 +#endif +#ifndef NK_MAX_NUMBER_BUFFER + #define NK_MAX_NUMBER_BUFFER 64 +#endif +#ifndef NK_SCROLLBAR_HIDING_TIMEOUT + #define NK_SCROLLBAR_HIDING_TIMEOUT 4.0f +#endif +/* + * ============================================================== + * + * HELPER + * + * =============================================================== + */ +#ifndef NK_API + #ifdef NK_PRIVATE + #if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199409L)) + #define NK_API static inline + #elif defined(__cplusplus) + #define NK_API static inline + #else + #define NK_API static + #endif + #else + #define NK_API extern + #endif +#endif +#ifndef NK_LIB + #ifdef NK_SINGLE_FILE + #define NK_LIB static + #else + #define NK_LIB extern + #endif +#endif + +#define NK_INTERN static +#define NK_STORAGE static +#define NK_GLOBAL static + +#define NK_FLAG(x) (1 << (x)) +#define NK_STRINGIFY(x) #x +#define NK_MACRO_STRINGIFY(x) NK_STRINGIFY(x) +#define NK_STRING_JOIN_IMMEDIATE(arg1, arg2) arg1 ## arg2 +#define NK_STRING_JOIN_DELAY(arg1, arg2) NK_STRING_JOIN_IMMEDIATE(arg1, arg2) +#define NK_STRING_JOIN(arg1, arg2) NK_STRING_JOIN_DELAY(arg1, arg2) + +#ifdef _MSC_VER + #define NK_UNIQUE_NAME(name) NK_STRING_JOIN(name,__COUNTER__) +#else + #define NK_UNIQUE_NAME(name) NK_STRING_JOIN(name,__LINE__) +#endif + +#ifndef NK_STATIC_ASSERT + #define NK_STATIC_ASSERT(exp) typedef char NK_UNIQUE_NAME(_dummy_array)[(exp)?1:-1] +#endif + +#ifndef NK_FILE_LINE +#ifdef _MSC_VER + #define NK_FILE_LINE __FILE__ ":" NK_MACRO_STRINGIFY(__COUNTER__) +#else + #define NK_FILE_LINE __FILE__ ":" NK_MACRO_STRINGIFY(__LINE__) +#endif +#endif + +#define NK_MIN(a,b) ((a) < (b) ? (a) : (b)) +#define NK_MAX(a,b) ((a) < (b) ? (b) : (a)) +#define NK_CLAMP(i,v,x) (NK_MAX(NK_MIN(v,x), i)) + +#ifdef NK_INCLUDE_STANDARD_VARARGS + #include + #if defined(_MSC_VER) && (_MSC_VER >= 1600) /* VS 2010 and above */ + #include + #define NK_PRINTF_FORMAT_STRING _Printf_format_string_ + #else + #define NK_PRINTF_FORMAT_STRING + #endif + #if defined(__GNUC__) + #define NK_PRINTF_VARARG_FUNC(fmtargnumber) __attribute__((format(__printf__, fmtargnumber, fmtargnumber+1))) + #define NK_PRINTF_VALIST_FUNC(fmtargnumber) __attribute__((format(__printf__, fmtargnumber, 0))) + #else + #define NK_PRINTF_VARARG_FUNC(fmtargnumber) + #define NK_PRINTF_VALIST_FUNC(fmtargnumber) + #endif +#endif + +/* + * =============================================================== + * + * BASIC + * + * =============================================================== + */ +#ifdef NK_INCLUDE_FIXED_TYPES + #include + #define NK_INT8 int8_t + #define NK_UINT8 uint8_t + #define NK_INT16 int16_t + #define NK_UINT16 uint16_t + #define NK_INT32 int32_t + #define NK_UINT32 uint32_t + #define NK_SIZE_TYPE uintptr_t + #define NK_POINTER_TYPE uintptr_t +#else + #ifndef NK_INT8 + #define NK_INT8 signed char + #endif + #ifndef NK_UINT8 + #define NK_UINT8 unsigned char + #endif + #ifndef NK_INT16 + #define NK_INT16 signed short + #endif + #ifndef NK_UINT16 + #define NK_UINT16 unsigned short + #endif + #ifndef NK_INT32 + #if defined(_MSC_VER) + #define NK_INT32 __int32 + #else + #define NK_INT32 signed int + #endif + #endif + #ifndef NK_UINT32 + #if defined(_MSC_VER) + #define NK_UINT32 unsigned __int32 + #else + #define NK_UINT32 unsigned int + #endif + #endif + #ifndef NK_SIZE_TYPE + #if defined(_WIN64) && defined(_MSC_VER) + #define NK_SIZE_TYPE unsigned __int64 + #elif (defined(_WIN32) || defined(WIN32)) && defined(_MSC_VER) + #define NK_SIZE_TYPE unsigned __int32 + #elif defined(__GNUC__) || defined(__clang__) + #if defined(__x86_64__) || defined(__ppc64__) || defined(__aarch64__) + #define NK_SIZE_TYPE unsigned long + #else + #define NK_SIZE_TYPE unsigned int + #endif + #else + #define NK_SIZE_TYPE unsigned long + #endif + #endif + #ifndef NK_POINTER_TYPE + #if defined(_WIN64) && defined(_MSC_VER) + #define NK_POINTER_TYPE unsigned __int64 + #elif (defined(_WIN32) || defined(WIN32)) && defined(_MSC_VER) + #define NK_POINTER_TYPE unsigned __int32 + #elif defined(__GNUC__) || defined(__clang__) + #if defined(__x86_64__) || defined(__ppc64__) || defined(__aarch64__) + #define NK_POINTER_TYPE unsigned long + #else + #define NK_POINTER_TYPE unsigned int + #endif + #else + #define NK_POINTER_TYPE unsigned long + #endif + #endif +#endif + +#ifndef NK_BOOL + #ifdef NK_INCLUDE_STANDARD_BOOL + #include + #define NK_BOOL bool + #else + #define NK_BOOL int /* could be char, use int for drop-in replacement backwards compatibility */ + #endif +#endif + +typedef NK_INT8 nk_char; +typedef NK_UINT8 nk_uchar; +typedef NK_UINT8 nk_byte; +typedef NK_INT16 nk_short; +typedef NK_UINT16 nk_ushort; +typedef NK_INT32 nk_int; +typedef NK_UINT32 nk_uint; +typedef NK_SIZE_TYPE nk_size; +typedef NK_POINTER_TYPE nk_ptr; +typedef NK_BOOL nk_bool; + +typedef nk_uint nk_hash; +typedef nk_uint nk_flags; +typedef nk_uint nk_rune; + +/* Make sure correct type size: + * This will fire with a negative subscript error if the type sizes + * are set incorrectly by the compiler, and compile out if not */ +NK_STATIC_ASSERT(sizeof(nk_short) == 2); +NK_STATIC_ASSERT(sizeof(nk_ushort) == 2); +NK_STATIC_ASSERT(sizeof(nk_uint) == 4); +NK_STATIC_ASSERT(sizeof(nk_int) == 4); +NK_STATIC_ASSERT(sizeof(nk_byte) == 1); +NK_STATIC_ASSERT(sizeof(nk_flags) >= 4); +NK_STATIC_ASSERT(sizeof(nk_rune) >= 4); +NK_STATIC_ASSERT(sizeof(nk_size) >= sizeof(void*)); +NK_STATIC_ASSERT(sizeof(nk_ptr) >= sizeof(void*)); +#ifdef NK_INCLUDE_STANDARD_BOOL +NK_STATIC_ASSERT(sizeof(nk_bool) == sizeof(bool)); +#else +NK_STATIC_ASSERT(sizeof(nk_bool) >= 2); +#endif + +/* ============================================================================ + * + * API + * + * =========================================================================== */ +struct nk_buffer; +struct nk_allocator; +struct nk_command_buffer; +struct nk_draw_command; +struct nk_convert_config; +struct nk_style_item; +struct nk_text_edit; +struct nk_draw_list; +struct nk_user_font; +struct nk_panel; +struct nk_context; +struct nk_draw_vertex_layout_element; +struct nk_style_button; +struct nk_style_toggle; +struct nk_style_selectable; +struct nk_style_slide; +struct nk_style_progress; +struct nk_style_scrollbar; +struct nk_style_edit; +struct nk_style_property; +struct nk_style_chart; +struct nk_style_combo; +struct nk_style_tab; +struct nk_style_window_header; +struct nk_style_window; + +enum {nk_false, nk_true}; +struct nk_color {nk_byte r,g,b,a;}; +struct nk_colorf {float r,g,b,a;}; +struct nk_vec2 {float x,y;}; +struct nk_vec2i {short x, y;}; +struct nk_rect {float x,y,w,h;}; +struct nk_recti {short x,y,w,h;}; +typedef char nk_glyph[NK_UTF_SIZE]; +typedef union {void *ptr; int id;} nk_handle; +struct nk_image {nk_handle handle; nk_handle unit; nk_ushort w, h; nk_ushort region[4];}; +struct nk_nine_slice {struct nk_image img; nk_ushort l, t, r, b;}; +struct nk_cursor {struct nk_image img; struct nk_vec2 size, offset;}; +struct nk_scroll {nk_uint x, y;}; + +enum nk_heading {NK_UP, NK_RIGHT, NK_DOWN, NK_LEFT}; +enum nk_button_behavior {NK_BUTTON_DEFAULT, NK_BUTTON_REPEATER}; +enum nk_modify {NK_FIXED = nk_false, NK_MODIFIABLE = nk_true}; +enum nk_orientation {NK_VERTICAL, NK_HORIZONTAL}; +enum nk_collapse_states {NK_MINIMIZED = nk_false, NK_MAXIMIZED = nk_true}; +enum nk_show_states {NK_HIDDEN = nk_false, NK_SHOWN = nk_true}; +enum nk_chart_type {NK_CHART_LINES, NK_CHART_COLUMN, NK_CHART_MAX}; +enum nk_chart_event {NK_CHART_HOVERING = 0x01, NK_CHART_CLICKED = 0x02}; +enum nk_color_format {NK_RGB, NK_RGBA}; +enum nk_popup_type {NK_POPUP_STATIC, NK_POPUP_DYNAMIC}; +enum nk_layout_format {NK_DYNAMIC, NK_STATIC}; +enum nk_tree_type {NK_TREE_NODE, NK_TREE_TAB}; + +typedef void*(*nk_plugin_alloc)(nk_handle, void *old, nk_size); +typedef void (*nk_plugin_free)(nk_handle, void *old); +typedef nk_bool(*nk_plugin_filter)(const struct nk_text_edit*, nk_rune unicode); +typedef void(*nk_plugin_paste)(nk_handle, struct nk_text_edit*); +typedef void(*nk_plugin_copy)(nk_handle, const char*, int len); + +struct nk_allocator { + nk_handle userdata; + nk_plugin_alloc alloc; + nk_plugin_free free; +}; +enum nk_symbol_type { + NK_SYMBOL_NONE, + NK_SYMBOL_X, + NK_SYMBOL_UNDERSCORE, + NK_SYMBOL_CIRCLE_SOLID, + NK_SYMBOL_CIRCLE_OUTLINE, + NK_SYMBOL_RECT_SOLID, + NK_SYMBOL_RECT_OUTLINE, + NK_SYMBOL_TRIANGLE_UP, + NK_SYMBOL_TRIANGLE_DOWN, + NK_SYMBOL_TRIANGLE_LEFT, + NK_SYMBOL_TRIANGLE_RIGHT, + NK_SYMBOL_PLUS, + NK_SYMBOL_MINUS, + NK_SYMBOL_MAX +}; +/* ============================================================================= + * + * CONTEXT + * + * =============================================================================*/ +/*/// ### Context +/// Contexts are the main entry point and the majestro of nuklear and contain all required state. +/// They are used for window, memory, input, style, stack, commands and time management and need +/// to be passed into all nuklear GUI specific functions. +/// +/// #### Usage +/// To use a context it first has to be initialized which can be achieved by calling +/// one of either `nk_init_default`, `nk_init_fixed`, `nk_init`, `nk_init_custom`. +/// Each takes in a font handle and a specific way of handling memory. Memory control +/// hereby ranges from standard library to just specifying a fixed sized block of memory +/// which nuklear has to manage itself from. +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// struct nk_context ctx; +/// nk_init_xxx(&ctx, ...); +/// while (1) { +/// // [...] +/// nk_clear(&ctx); +/// } +/// nk_free(&ctx); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// #### Reference +/// Function | Description +/// --------------------|------------------------------------------------------- +/// __nk_init_default__ | Initializes context with standard library memory allocation (malloc,free) +/// __nk_init_fixed__ | Initializes context from single fixed size memory block +/// __nk_init__ | Initializes context with memory allocator callbacks for alloc and free +/// __nk_init_custom__ | Initializes context from two buffers. One for draw commands the other for window/panel/table allocations +/// __nk_clear__ | Called at the end of the frame to reset and prepare the context for the next frame +/// __nk_free__ | Shutdown and free all memory allocated inside the context +/// __nk_set_user_data__| Utility function to pass user data to draw command + */ +#ifdef NK_INCLUDE_DEFAULT_ALLOCATOR +/*/// #### nk_init_default +/// Initializes a `nk_context` struct with a default standard library allocator. +/// Should be used if you don't want to be bothered with memory management in nuklear. +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// nk_bool nk_init_default(struct nk_context *ctx, const struct nk_user_font *font); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|--------------------------------------------------------------- +/// __ctx__ | Must point to an either stack or heap allocated `nk_context` struct +/// __font__ | Must point to a previously initialized font handle for more info look at font documentation +/// +/// Returns either `false(0)` on failure or `true(1)` on success. +/// +*/ +NK_API nk_bool nk_init_default(struct nk_context*, const struct nk_user_font*); +#endif +/*/// #### nk_init_fixed +/// Initializes a `nk_context` struct from single fixed size memory block +/// Should be used if you want complete control over nuklear's memory management. +/// Especially recommended for system with little memory or systems with virtual memory. +/// For the later case you can just allocate for example 16MB of virtual memory +/// and only the required amount of memory will actually be committed. +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// nk_bool nk_init_fixed(struct nk_context *ctx, void *memory, nk_size size, const struct nk_user_font *font); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// !!! Warning +/// make sure the passed memory block is aligned correctly for `nk_draw_commands`. +/// +/// Parameter | Description +/// ------------|-------------------------------------------------------------- +/// __ctx__ | Must point to an either stack or heap allocated `nk_context` struct +/// __memory__ | Must point to a previously allocated memory block +/// __size__ | Must contain the total size of __memory__ +/// __font__ | Must point to a previously initialized font handle for more info look at font documentation +/// +/// Returns either `false(0)` on failure or `true(1)` on success. +*/ +NK_API nk_bool nk_init_fixed(struct nk_context*, void *memory, nk_size size, const struct nk_user_font*); +/*/// #### nk_init +/// Initializes a `nk_context` struct with memory allocation callbacks for nuklear to allocate +/// memory from. Used internally for `nk_init_default` and provides a kitchen sink allocation +/// interface to nuklear. Can be useful for cases like monitoring memory consumption. +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// nk_bool nk_init(struct nk_context *ctx, struct nk_allocator *alloc, const struct nk_user_font *font); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|--------------------------------------------------------------- +/// __ctx__ | Must point to an either stack or heap allocated `nk_context` struct +/// __alloc__ | Must point to a previously allocated memory allocator +/// __font__ | Must point to a previously initialized font handle for more info look at font documentation +/// +/// Returns either `false(0)` on failure or `true(1)` on success. +*/ +NK_API nk_bool nk_init(struct nk_context*, struct nk_allocator*, const struct nk_user_font*); +/*/// #### nk_init_custom +/// Initializes a `nk_context` struct from two different either fixed or growing +/// buffers. The first buffer is for allocating draw commands while the second buffer is +/// used for allocating windows, panels and state tables. +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// nk_bool nk_init_custom(struct nk_context *ctx, struct nk_buffer *cmds, struct nk_buffer *pool, const struct nk_user_font *font); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|--------------------------------------------------------------- +/// __ctx__ | Must point to an either stack or heap allocated `nk_context` struct +/// __cmds__ | Must point to a previously initialized memory buffer either fixed or dynamic to store draw commands into +/// __pool__ | Must point to a previously initialized memory buffer either fixed or dynamic to store windows, panels and tables +/// __font__ | Must point to a previously initialized font handle for more info look at font documentation +/// +/// Returns either `false(0)` on failure or `true(1)` on success. +*/ +NK_API nk_bool nk_init_custom(struct nk_context*, struct nk_buffer *cmds, struct nk_buffer *pool, const struct nk_user_font*); +/*/// #### nk_clear +/// Resets the context state at the end of the frame. This includes mostly +/// garbage collector tasks like removing windows or table not called and therefore +/// used anymore. +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// void nk_clear(struct nk_context *ctx); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to a previously initialized `nk_context` struct +*/ +NK_API void nk_clear(struct nk_context*); +/*/// #### nk_free +/// Frees all memory allocated by nuklear. Not needed if context was +/// initialized with `nk_init_fixed`. +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// void nk_free(struct nk_context *ctx); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to a previously initialized `nk_context` struct +*/ +NK_API void nk_free(struct nk_context*); +#ifdef NK_INCLUDE_COMMAND_USERDATA +/*/// #### nk_set_user_data +/// Sets the currently passed userdata passed down into each draw command. +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// void nk_set_user_data(struct nk_context *ctx, nk_handle data); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|-------------------------------------------------------------- +/// __ctx__ | Must point to a previously initialized `nk_context` struct +/// __data__ | Handle with either pointer or index to be passed into every draw commands +*/ +NK_API void nk_set_user_data(struct nk_context*, nk_handle handle); +#endif +/* ============================================================================= + * + * INPUT + * + * =============================================================================*/ +/*/// ### Input +/// The input API is responsible for holding the current input state composed of +/// mouse, key and text input states. +/// It is worth noting that no direct OS or window handling is done in nuklear. +/// Instead all input state has to be provided by platform specific code. This on one hand +/// expects more work from the user and complicates usage but on the other hand +/// provides simple abstraction over a big number of platforms, libraries and other +/// already provided functionality. +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// nk_input_begin(&ctx); +/// while (GetEvent(&evt)) { +/// if (evt.type == MOUSE_MOVE) +/// nk_input_motion(&ctx, evt.motion.x, evt.motion.y); +/// else if (evt.type == [...]) { +/// // [...] +/// } +/// } nk_input_end(&ctx); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// #### Usage +/// Input state needs to be provided to nuklear by first calling `nk_input_begin` +/// which resets internal state like delta mouse position and button transitions. +/// After `nk_input_begin` all current input state needs to be provided. This includes +/// mouse motion, button and key pressed and released, text input and scrolling. +/// Both event- or state-based input handling are supported by this API +/// and should work without problems. Finally after all input state has been +/// mirrored `nk_input_end` needs to be called to finish input process. +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// struct nk_context ctx; +/// nk_init_xxx(&ctx, ...); +/// while (1) { +/// Event evt; +/// nk_input_begin(&ctx); +/// while (GetEvent(&evt)) { +/// if (evt.type == MOUSE_MOVE) +/// nk_input_motion(&ctx, evt.motion.x, evt.motion.y); +/// else if (evt.type == [...]) { +/// // [...] +/// } +/// } +/// nk_input_end(&ctx); +/// // [...] +/// nk_clear(&ctx); +/// } nk_free(&ctx); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// #### Reference +/// Function | Description +/// --------------------|------------------------------------------------------- +/// __nk_input_begin__ | Begins the input mirroring process. Needs to be called before all other `nk_input_xxx` calls +/// __nk_input_motion__ | Mirrors mouse cursor position +/// __nk_input_key__ | Mirrors key state with either pressed or released +/// __nk_input_button__ | Mirrors mouse button state with either pressed or released +/// __nk_input_scroll__ | Mirrors mouse scroll values +/// __nk_input_char__ | Adds a single ASCII text character into an internal text buffer +/// __nk_input_glyph__ | Adds a single multi-byte UTF-8 character into an internal text buffer +/// __nk_input_unicode__| Adds a single unicode rune into an internal text buffer +/// __nk_input_end__ | Ends the input mirroring process by calculating state changes. Don't call any `nk_input_xxx` function referenced above after this call +*/ +enum nk_keys { + NK_KEY_NONE, + NK_KEY_SHIFT, + NK_KEY_CTRL, + NK_KEY_ALT, + NK_KEY_DEL, + NK_KEY_ENTER, + NK_KEY_TAB, + NK_KEY_BACKSPACE, + NK_KEY_ESCAPE, + NK_KEY_COPY, + NK_KEY_CUT, + NK_KEY_PASTE, + NK_KEY_UP, + NK_KEY_DOWN, + NK_KEY_LEFT, + NK_KEY_RIGHT, + /* Shortcuts: text field */ + NK_KEY_TEXT_INSERT_MODE, + NK_KEY_TEXT_REPLACE_MODE, + NK_KEY_TEXT_RESET_MODE, + NK_KEY_TEXT_LINE_START, + NK_KEY_TEXT_LINE_END, + NK_KEY_TEXT_START, + NK_KEY_TEXT_END, + NK_KEY_TEXT_UNDO, + NK_KEY_TEXT_REDO, + NK_KEY_TEXT_SELECT_ALL, + NK_KEY_TEXT_WORD_LEFT, + NK_KEY_TEXT_WORD_RIGHT, + /* Shortcuts: scrollbar */ + NK_KEY_SCROLL_START, + NK_KEY_SCROLL_END, + NK_KEY_SCROLL_DOWN, + NK_KEY_SCROLL_UP, + NK_KEY_MAX +}; +enum nk_buttons { + NK_BUTTON_LEFT, + NK_BUTTON_MIDDLE, + NK_BUTTON_RIGHT, + NK_BUTTON_DOUBLE, + NK_BUTTON_MAX +}; +/*/// #### nk_input_begin +/// Begins the input mirroring process by resetting text, scroll +/// mouse, previous mouse position and movement as well as key state transitions, +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// void nk_input_begin(struct nk_context*); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to a previously initialized `nk_context` struct +*/ +NK_API void nk_input_begin(struct nk_context*); +/*/// #### nk_input_motion +/// Mirrors current mouse position to nuklear +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// void nk_input_motion(struct nk_context *ctx, int x, int y); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to a previously initialized `nk_context` struct +/// __x__ | Must hold an integer describing the current mouse cursor x-position +/// __y__ | Must hold an integer describing the current mouse cursor y-position +*/ +NK_API void nk_input_motion(struct nk_context*, int x, int y); +/*/// #### nk_input_key +/// Mirrors the state of a specific key to nuklear +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// void nk_input_key(struct nk_context*, enum nk_keys key, nk_bool down); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to a previously initialized `nk_context` struct +/// __key__ | Must be any value specified in enum `nk_keys` that needs to be mirrored +/// __down__ | Must be 0 for key is up and 1 for key is down +*/ +NK_API void nk_input_key(struct nk_context*, enum nk_keys, nk_bool down); +/*/// #### nk_input_button +/// Mirrors the state of a specific mouse button to nuklear +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// void nk_input_button(struct nk_context *ctx, enum nk_buttons btn, int x, int y, nk_bool down); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to a previously initialized `nk_context` struct +/// __btn__ | Must be any value specified in enum `nk_buttons` that needs to be mirrored +/// __x__ | Must contain an integer describing mouse cursor x-position on click up/down +/// __y__ | Must contain an integer describing mouse cursor y-position on click up/down +/// __down__ | Must be 0 for key is up and 1 for key is down +*/ +NK_API void nk_input_button(struct nk_context*, enum nk_buttons, int x, int y, nk_bool down); +/*/// #### nk_input_scroll +/// Copies the last mouse scroll value to nuklear. Is generally +/// a scroll value. So does not have to come from mouse and could also originate +/// TODO finish this sentence +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// void nk_input_scroll(struct nk_context *ctx, struct nk_vec2 val); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to a previously initialized `nk_context` struct +/// __val__ | vector with both X- as well as Y-scroll value +*/ +NK_API void nk_input_scroll(struct nk_context*, struct nk_vec2 val); +/*/// #### nk_input_char +/// Copies a single ASCII character into an internal text buffer +/// This is basically a helper function to quickly push ASCII characters into +/// nuklear. +/// +/// !!! Note +/// Stores up to NK_INPUT_MAX bytes between `nk_input_begin` and `nk_input_end`. +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// void nk_input_char(struct nk_context *ctx, char c); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to a previously initialized `nk_context` struct +/// __c__ | Must be a single ASCII character preferable one that can be printed +*/ +NK_API void nk_input_char(struct nk_context*, char); +/*/// #### nk_input_glyph +/// Converts an encoded unicode rune into UTF-8 and copies the result into an +/// internal text buffer. +/// +/// !!! Note +/// Stores up to NK_INPUT_MAX bytes between `nk_input_begin` and `nk_input_end`. +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// void nk_input_glyph(struct nk_context *ctx, const nk_glyph g); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to a previously initialized `nk_context` struct +/// __g__ | UTF-32 unicode codepoint +*/ +NK_API void nk_input_glyph(struct nk_context*, const nk_glyph); +/*/// #### nk_input_unicode +/// Converts a unicode rune into UTF-8 and copies the result +/// into an internal text buffer. +/// !!! Note +/// Stores up to NK_INPUT_MAX bytes between `nk_input_begin` and `nk_input_end`. +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// void nk_input_unicode(struct nk_context*, nk_rune rune); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to a previously initialized `nk_context` struct +/// __rune__ | UTF-32 unicode codepoint +*/ +NK_API void nk_input_unicode(struct nk_context*, nk_rune); +/*/// #### nk_input_end +/// End the input mirroring process by resetting mouse grabbing +/// state to ensure the mouse cursor is not grabbed indefinitely. +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// void nk_input_end(struct nk_context *ctx); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to a previously initialized `nk_context` struct +*/ +NK_API void nk_input_end(struct nk_context*); +/* ============================================================================= + * + * DRAWING + * + * =============================================================================*/ +/*/// ### Drawing +/// This library was designed to be render backend agnostic so it does +/// not draw anything to screen directly. Instead all drawn shapes, widgets +/// are made of, are buffered into memory and make up a command queue. +/// Each frame therefore fills the command buffer with draw commands +/// that then need to be executed by the user and his own render backend. +/// After that the command buffer needs to be cleared and a new frame can be +/// started. It is probably important to note that the command buffer is the main +/// drawing API and the optional vertex buffer API only takes this format and +/// converts it into a hardware accessible format. +/// +/// #### Usage +/// To draw all draw commands accumulated over a frame you need your own render +/// backend able to draw a number of 2D primitives. This includes at least +/// filled and stroked rectangles, circles, text, lines, triangles and scissors. +/// As soon as this criterion is met you can iterate over each draw command +/// and execute each draw command in a interpreter like fashion: +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// const struct nk_command *cmd = 0; +/// nk_foreach(cmd, &ctx) { +/// switch (cmd->type) { +/// case NK_COMMAND_LINE: +/// your_draw_line_function(...) +/// break; +/// case NK_COMMAND_RECT +/// your_draw_rect_function(...) +/// break; +/// case //...: +/// //[...] +/// } +/// } +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// In program flow context draw commands need to be executed after input has been +/// gathered and the complete UI with windows and their contained widgets have +/// been executed and before calling `nk_clear` which frees all previously +/// allocated draw commands. +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// struct nk_context ctx; +/// nk_init_xxx(&ctx, ...); +/// while (1) { +/// Event evt; +/// nk_input_begin(&ctx); +/// while (GetEvent(&evt)) { +/// if (evt.type == MOUSE_MOVE) +/// nk_input_motion(&ctx, evt.motion.x, evt.motion.y); +/// else if (evt.type == [...]) { +/// [...] +/// } +/// } +/// nk_input_end(&ctx); +/// // +/// // [...] +/// // +/// const struct nk_command *cmd = 0; +/// nk_foreach(cmd, &ctx) { +/// switch (cmd->type) { +/// case NK_COMMAND_LINE: +/// your_draw_line_function(...) +/// break; +/// case NK_COMMAND_RECT +/// your_draw_rect_function(...) +/// break; +/// case ...: +/// // [...] +/// } +/// nk_clear(&ctx); +/// } +/// nk_free(&ctx); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// You probably noticed that you have to draw all of the UI each frame which is +/// quite wasteful. While the actual UI updating loop is quite fast rendering +/// without actually needing it is not. So there are multiple things you could do. +/// +/// First is only update on input. This of course is only an option if your +/// application only depends on the UI and does not require any outside calculations. +/// If you actually only update on input make sure to update the UI two times each +/// frame and call `nk_clear` directly after the first pass and only draw in +/// the second pass. In addition it is recommended to also add additional timers +/// to make sure the UI is not drawn more than a fixed number of frames per second. +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// struct nk_context ctx; +/// nk_init_xxx(&ctx, ...); +/// while (1) { +/// // [...wait for input ] +/// // [...do two UI passes ...] +/// do_ui(...) +/// nk_clear(&ctx); +/// do_ui(...) +/// // +/// // draw +/// const struct nk_command *cmd = 0; +/// nk_foreach(cmd, &ctx) { +/// switch (cmd->type) { +/// case NK_COMMAND_LINE: +/// your_draw_line_function(...) +/// break; +/// case NK_COMMAND_RECT +/// your_draw_rect_function(...) +/// break; +/// case ...: +/// //[...] +/// } +/// nk_clear(&ctx); +/// } +/// nk_free(&ctx); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// The second probably more applicable trick is to only draw if anything changed. +/// It is not really useful for applications with continuous draw loop but +/// quite useful for desktop applications. To actually get nuklear to only +/// draw on changes you first have to define `NK_ZERO_COMMAND_MEMORY` and +/// allocate a memory buffer that will store each unique drawing output. +/// After each frame you compare the draw command memory inside the library +/// with your allocated buffer by memcmp. If memcmp detects differences +/// you have to copy the command buffer into the allocated buffer +/// and then draw like usual (this example uses fixed memory but you could +/// use dynamically allocated memory). +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// //[... other defines ...] +/// #define NK_ZERO_COMMAND_MEMORY +/// #include "nuklear.h" +/// // +/// // setup context +/// struct nk_context ctx; +/// void *last = calloc(1,64*1024); +/// void *buf = calloc(1,64*1024); +/// nk_init_fixed(&ctx, buf, 64*1024); +/// // +/// // loop +/// while (1) { +/// // [...input...] +/// // [...ui...] +/// void *cmds = nk_buffer_memory(&ctx.memory); +/// if (memcmp(cmds, last, ctx.memory.allocated)) { +/// memcpy(last,cmds,ctx.memory.allocated); +/// const struct nk_command *cmd = 0; +/// nk_foreach(cmd, &ctx) { +/// switch (cmd->type) { +/// case NK_COMMAND_LINE: +/// your_draw_line_function(...) +/// break; +/// case NK_COMMAND_RECT +/// your_draw_rect_function(...) +/// break; +/// case ...: +/// // [...] +/// } +/// } +/// } +/// nk_clear(&ctx); +/// } +/// nk_free(&ctx); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Finally while using draw commands makes sense for higher abstracted platforms like +/// X11 and Win32 or drawing libraries it is often desirable to use graphics +/// hardware directly. Therefore it is possible to just define +/// `NK_INCLUDE_VERTEX_BUFFER_OUTPUT` which includes optional vertex output. +/// To access the vertex output you first have to convert all draw commands into +/// vertexes by calling `nk_convert` which takes in your preferred vertex format. +/// After successfully converting all draw commands just iterate over and execute all +/// vertex draw commands: +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// // fill configuration +/// struct your_vertex +/// { +/// float pos[2]; // important to keep it to 2 floats +/// float uv[2]; +/// unsigned char col[4]; +/// }; +/// struct nk_convert_config cfg = {}; +/// static const struct nk_draw_vertex_layout_element vertex_layout[] = { +/// {NK_VERTEX_POSITION, NK_FORMAT_FLOAT, NK_OFFSETOF(struct your_vertex, pos)}, +/// {NK_VERTEX_TEXCOORD, NK_FORMAT_FLOAT, NK_OFFSETOF(struct your_vertex, uv)}, +/// {NK_VERTEX_COLOR, NK_FORMAT_R8G8B8A8, NK_OFFSETOF(struct your_vertex, col)}, +/// {NK_VERTEX_LAYOUT_END} +/// }; +/// cfg.shape_AA = NK_ANTI_ALIASING_ON; +/// cfg.line_AA = NK_ANTI_ALIASING_ON; +/// cfg.vertex_layout = vertex_layout; +/// cfg.vertex_size = sizeof(struct your_vertex); +/// cfg.vertex_alignment = NK_ALIGNOF(struct your_vertex); +/// cfg.circle_segment_count = 22; +/// cfg.curve_segment_count = 22; +/// cfg.arc_segment_count = 22; +/// cfg.global_alpha = 1.0f; +/// cfg.tex_null = dev->tex_null; +/// // +/// // setup buffers and convert +/// struct nk_buffer cmds, verts, idx; +/// nk_buffer_init_default(&cmds); +/// nk_buffer_init_default(&verts); +/// nk_buffer_init_default(&idx); +/// nk_convert(&ctx, &cmds, &verts, &idx, &cfg); +/// // +/// // draw +/// nk_draw_foreach(cmd, &ctx, &cmds) { +/// if (!cmd->elem_count) continue; +/// //[...] +/// } +/// nk_buffer_free(&cms); +/// nk_buffer_free(&verts); +/// nk_buffer_free(&idx); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// #### Reference +/// Function | Description +/// --------------------|------------------------------------------------------- +/// __nk__begin__ | Returns the first draw command in the context draw command list to be drawn +/// __nk__next__ | Increments the draw command iterator to the next command inside the context draw command list +/// __nk_foreach__ | Iterates over each draw command inside the context draw command list +/// __nk_convert__ | Converts from the abstract draw commands list into a hardware accessible vertex format +/// __nk_draw_begin__ | Returns the first vertex command in the context vertex draw list to be executed +/// __nk__draw_next__ | Increments the vertex command iterator to the next command inside the context vertex command list +/// __nk__draw_end__ | Returns the end of the vertex draw list +/// __nk_draw_foreach__ | Iterates over each vertex draw command inside the vertex draw list +*/ +enum nk_anti_aliasing {NK_ANTI_ALIASING_OFF, NK_ANTI_ALIASING_ON}; +enum nk_convert_result { + NK_CONVERT_SUCCESS = 0, + NK_CONVERT_INVALID_PARAM = 1, + NK_CONVERT_COMMAND_BUFFER_FULL = NK_FLAG(1), + NK_CONVERT_VERTEX_BUFFER_FULL = NK_FLAG(2), + NK_CONVERT_ELEMENT_BUFFER_FULL = NK_FLAG(3) +}; +struct nk_draw_null_texture { + nk_handle texture; /* texture handle to a texture with a white pixel */ + struct nk_vec2 uv; /* coordinates to a white pixel in the texture */ +}; +struct nk_convert_config { + float global_alpha; /* global alpha value */ + enum nk_anti_aliasing line_AA; /* line anti-aliasing flag can be turned off if you are tight on memory */ + enum nk_anti_aliasing shape_AA; /* shape anti-aliasing flag can be turned off if you are tight on memory */ + unsigned circle_segment_count; /* number of segments used for circles: default to 22 */ + unsigned arc_segment_count; /* number of segments used for arcs: default to 22 */ + unsigned curve_segment_count; /* number of segments used for curves: default to 22 */ + struct nk_draw_null_texture tex_null; /* handle to texture with a white pixel for shape drawing */ + const struct nk_draw_vertex_layout_element *vertex_layout; /* describes the vertex output format and packing */ + nk_size vertex_size; /* sizeof one vertex for vertex packing */ + nk_size vertex_alignment; /* vertex alignment: Can be obtained by NK_ALIGNOF */ +}; +/*/// #### nk__begin +/// Returns a draw command list iterator to iterate all draw +/// commands accumulated over one frame. +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// const struct nk_command* nk__begin(struct nk_context*); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | must point to an previously initialized `nk_context` struct at the end of a frame +/// +/// Returns draw command pointer pointing to the first command inside the draw command list +*/ +NK_API const struct nk_command* nk__begin(struct nk_context*); +/*/// #### nk__next +/// Returns draw command pointer pointing to the next command inside the draw command list +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// const struct nk_command* nk__next(struct nk_context*, const struct nk_command*); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct at the end of a frame +/// __cmd__ | Must point to an previously a draw command either returned by `nk__begin` or `nk__next` +/// +/// Returns draw command pointer pointing to the next command inside the draw command list +*/ +NK_API const struct nk_command* nk__next(struct nk_context*, const struct nk_command*); +/*/// #### nk_foreach +/// Iterates over each draw command inside the context draw command list +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// #define nk_foreach(c, ctx) +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct at the end of a frame +/// __cmd__ | Command pointer initialized to NULL +/// +/// Iterates over each draw command inside the context draw command list +*/ +#define nk_foreach(c, ctx) for((c) = nk__begin(ctx); (c) != 0; (c) = nk__next(ctx,c)) +#ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT +/*/// #### nk_convert +/// Converts all internal draw commands into vertex draw commands and fills +/// three buffers with vertexes, vertex draw commands and vertex indices. The vertex format +/// as well as some other configuration values have to be configured by filling out a +/// `nk_convert_config` struct. +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// nk_flags nk_convert(struct nk_context *ctx, struct nk_buffer *cmds, +/// struct nk_buffer *vertices, struct nk_buffer *elements, const struct nk_convert_config*); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct at the end of a frame +/// __cmds__ | Must point to a previously initialized buffer to hold converted vertex draw commands +/// __vertices__| Must point to a previously initialized buffer to hold all produced vertices +/// __elements__| Must point to a previously initialized buffer to hold all produced vertex indices +/// __config__ | Must point to a filled out `nk_config` struct to configure the conversion process +/// +/// Returns one of enum nk_convert_result error codes +/// +/// Parameter | Description +/// --------------------------------|----------------------------------------------------------- +/// NK_CONVERT_SUCCESS | Signals a successful draw command to vertex buffer conversion +/// NK_CONVERT_INVALID_PARAM | An invalid argument was passed in the function call +/// NK_CONVERT_COMMAND_BUFFER_FULL | The provided buffer for storing draw commands is full or failed to allocate more memory +/// NK_CONVERT_VERTEX_BUFFER_FULL | The provided buffer for storing vertices is full or failed to allocate more memory +/// NK_CONVERT_ELEMENT_BUFFER_FULL | The provided buffer for storing indices is full or failed to allocate more memory +*/ +NK_API nk_flags nk_convert(struct nk_context*, struct nk_buffer *cmds, struct nk_buffer *vertices, struct nk_buffer *elements, const struct nk_convert_config*); +/*/// #### nk__draw_begin +/// Returns a draw vertex command buffer iterator to iterate over the vertex draw command buffer +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// const struct nk_draw_command* nk__draw_begin(const struct nk_context*, const struct nk_buffer*); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct at the end of a frame +/// __buf__ | Must point to an previously by `nk_convert` filled out vertex draw command buffer +/// +/// Returns vertex draw command pointer pointing to the first command inside the vertex draw command buffer +*/ +NK_API const struct nk_draw_command* nk__draw_begin(const struct nk_context*, const struct nk_buffer*); +/*/// #### nk__draw_end +/// Returns the vertex draw command at the end of the vertex draw command buffer +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// const struct nk_draw_command* nk__draw_end(const struct nk_context *ctx, const struct nk_buffer *buf); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct at the end of a frame +/// __buf__ | Must point to an previously by `nk_convert` filled out vertex draw command buffer +/// +/// Returns vertex draw command pointer pointing to the end of the last vertex draw command inside the vertex draw command buffer +*/ +NK_API const struct nk_draw_command* nk__draw_end(const struct nk_context*, const struct nk_buffer*); +/*/// #### nk__draw_next +/// Increments the vertex draw command buffer iterator +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// const struct nk_draw_command* nk__draw_next(const struct nk_draw_command*, const struct nk_buffer*, const struct nk_context*); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __cmd__ | Must point to an previously either by `nk__draw_begin` or `nk__draw_next` returned vertex draw command +/// __buf__ | Must point to an previously by `nk_convert` filled out vertex draw command buffer +/// __ctx__ | Must point to an previously initialized `nk_context` struct at the end of a frame +/// +/// Returns vertex draw command pointer pointing to the end of the last vertex draw command inside the vertex draw command buffer +*/ +NK_API const struct nk_draw_command* nk__draw_next(const struct nk_draw_command*, const struct nk_buffer*, const struct nk_context*); +/*/// #### nk_draw_foreach +/// Iterates over each vertex draw command inside a vertex draw command buffer +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// #define nk_draw_foreach(cmd,ctx, b) +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __cmd__ | `nk_draw_command`iterator set to NULL +/// __buf__ | Must point to an previously by `nk_convert` filled out vertex draw command buffer +/// __ctx__ | Must point to an previously initialized `nk_context` struct at the end of a frame +*/ +#define nk_draw_foreach(cmd,ctx, b) for((cmd)=nk__draw_begin(ctx, b); (cmd)!=0; (cmd)=nk__draw_next(cmd, b, ctx)) +#endif +/* ============================================================================= + * + * WINDOW + * + * ============================================================================= +/// ### Window +/// Windows are the main persistent state used inside nuklear and are life time +/// controlled by simply "retouching" (i.e. calling) each window each frame. +/// All widgets inside nuklear can only be added inside the function pair `nk_begin_xxx` +/// and `nk_end`. Calling any widgets outside these two functions will result in an +/// assert in debug or no state change in release mode.

+/// +/// Each window holds frame persistent state like position, size, flags, state tables, +/// and some garbage collected internal persistent widget state. Each window +/// is linked into a window stack list which determines the drawing and overlapping +/// order. The topmost window thereby is the currently active window.

+/// +/// To change window position inside the stack occurs either automatically by +/// user input by being clicked on or programmatically by calling `nk_window_focus`. +/// Windows by default are visible unless explicitly being defined with flag +/// `NK_WINDOW_HIDDEN`, the user clicked the close button on windows with flag +/// `NK_WINDOW_CLOSABLE` or if a window was explicitly hidden by calling +/// `nk_window_show`. To explicitly close and destroy a window call `nk_window_close`.

+/// +/// #### Usage +/// To create and keep a window you have to call one of the two `nk_begin_xxx` +/// functions to start window declarations and `nk_end` at the end. Furthermore it +/// is recommended to check the return value of `nk_begin_xxx` and only process +/// widgets inside the window if the value is not 0. Either way you have to call +/// `nk_end` at the end of window declarations. Furthermore, do not attempt to +/// nest `nk_begin_xxx` calls which will hopefully result in an assert or if not +/// in a segmentation fault. +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// if (nk_begin_xxx(...) { +/// // [... widgets ...] +/// } +/// nk_end(ctx); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// In the grand concept window and widget declarations need to occur after input +/// handling and before drawing to screen. Not doing so can result in higher +/// latency or at worst invalid behavior. Furthermore make sure that `nk_clear` +/// is called at the end of the frame. While nuklear's default platform backends +/// already call `nk_clear` for you if you write your own backend not calling +/// `nk_clear` can cause asserts or even worse undefined behavior. +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// struct nk_context ctx; +/// nk_init_xxx(&ctx, ...); +/// while (1) { +/// Event evt; +/// nk_input_begin(&ctx); +/// while (GetEvent(&evt)) { +/// if (evt.type == MOUSE_MOVE) +/// nk_input_motion(&ctx, evt.motion.x, evt.motion.y); +/// else if (evt.type == [...]) { +/// nk_input_xxx(...); +/// } +/// } +/// nk_input_end(&ctx); +/// +/// if (nk_begin_xxx(...) { +/// //[...] +/// } +/// nk_end(ctx); +/// +/// const struct nk_command *cmd = 0; +/// nk_foreach(cmd, &ctx) { +/// case NK_COMMAND_LINE: +/// your_draw_line_function(...) +/// break; +/// case NK_COMMAND_RECT +/// your_draw_rect_function(...) +/// break; +/// case //...: +/// //[...] +/// } +/// nk_clear(&ctx); +/// } +/// nk_free(&ctx); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// #### Reference +/// Function | Description +/// ------------------------------------|---------------------------------------- +/// nk_begin | Starts a new window; needs to be called every frame for every window (unless hidden) or otherwise the window gets removed +/// nk_begin_titled | Extended window start with separated title and identifier to allow multiple windows with same name but not title +/// nk_end | Needs to be called at the end of the window building process to process scaling, scrollbars and general cleanup +// +/// nk_window_find | Finds and returns the window with give name +/// nk_window_get_bounds | Returns a rectangle with screen position and size of the currently processed window. +/// nk_window_get_position | Returns the position of the currently processed window +/// nk_window_get_size | Returns the size with width and height of the currently processed window +/// nk_window_get_width | Returns the width of the currently processed window +/// nk_window_get_height | Returns the height of the currently processed window +/// nk_window_get_panel | Returns the underlying panel which contains all processing state of the current window +/// nk_window_get_content_region | Returns the position and size of the currently visible and non-clipped space inside the currently processed window +/// nk_window_get_content_region_min | Returns the upper rectangle position of the currently visible and non-clipped space inside the currently processed window +/// nk_window_get_content_region_max | Returns the upper rectangle position of the currently visible and non-clipped space inside the currently processed window +/// nk_window_get_content_region_size | Returns the size of the currently visible and non-clipped space inside the currently processed window +/// nk_window_get_canvas | Returns the draw command buffer. Can be used to draw custom widgets +/// nk_window_get_scroll | Gets the scroll offset of the current window +/// nk_window_has_focus | Returns if the currently processed window is currently active +/// nk_window_is_collapsed | Returns if the window with given name is currently minimized/collapsed +/// nk_window_is_closed | Returns if the currently processed window was closed +/// nk_window_is_hidden | Returns if the currently processed window was hidden +/// nk_window_is_active | Same as nk_window_has_focus for some reason +/// nk_window_is_hovered | Returns if the currently processed window is currently being hovered by mouse +/// nk_window_is_any_hovered | Return if any window currently hovered +/// nk_item_is_any_active | Returns if any window or widgets is currently hovered or active +// +/// nk_window_set_bounds | Updates position and size of the currently processed window +/// nk_window_set_position | Updates position of the currently process window +/// nk_window_set_size | Updates the size of the currently processed window +/// nk_window_set_focus | Set the currently processed window as active window +/// nk_window_set_scroll | Sets the scroll offset of the current window +// +/// nk_window_close | Closes the window with given window name which deletes the window at the end of the frame +/// nk_window_collapse | Collapses the window with given window name +/// nk_window_collapse_if | Collapses the window with given window name if the given condition was met +/// nk_window_show | Hides a visible or reshows a hidden window +/// nk_window_show_if | Hides/shows a window depending on condition +*/ +/* +/// #### nk_panel_flags +/// Flag | Description +/// ----------------------------|---------------------------------------- +/// NK_WINDOW_BORDER | Draws a border around the window to visually separate window from the background +/// NK_WINDOW_MOVABLE | The movable flag indicates that a window can be moved by user input or by dragging the window header +/// NK_WINDOW_SCALABLE | The scalable flag indicates that a window can be scaled by user input by dragging a scaler icon at the button of the window +/// NK_WINDOW_CLOSABLE | Adds a closable icon into the header +/// NK_WINDOW_MINIMIZABLE | Adds a minimize icon into the header +/// NK_WINDOW_NO_SCROLLBAR | Removes the scrollbar from the window +/// NK_WINDOW_TITLE | Forces a header at the top at the window showing the title +/// NK_WINDOW_SCROLL_AUTO_HIDE | Automatically hides the window scrollbar if no user interaction: also requires delta time in `nk_context` to be set each frame +/// NK_WINDOW_BACKGROUND | Always keep window in the background +/// NK_WINDOW_SCALE_LEFT | Puts window scaler in the left-bottom corner instead right-bottom +/// NK_WINDOW_NO_INPUT | Prevents window of scaling, moving or getting focus +/// +/// #### nk_collapse_states +/// State | Description +/// ----------------|----------------------------------------------------------- +/// __NK_MINIMIZED__| UI section is collased and not visible until maximized +/// __NK_MAXIMIZED__| UI section is extended and visible until minimized +///

+*/ +enum nk_panel_flags { + NK_WINDOW_BORDER = NK_FLAG(0), + NK_WINDOW_MOVABLE = NK_FLAG(1), + NK_WINDOW_SCALABLE = NK_FLAG(2), + NK_WINDOW_CLOSABLE = NK_FLAG(3), + NK_WINDOW_MINIMIZABLE = NK_FLAG(4), + NK_WINDOW_NO_SCROLLBAR = NK_FLAG(5), + NK_WINDOW_TITLE = NK_FLAG(6), + NK_WINDOW_SCROLL_AUTO_HIDE = NK_FLAG(7), + NK_WINDOW_BACKGROUND = NK_FLAG(8), + NK_WINDOW_SCALE_LEFT = NK_FLAG(9), + NK_WINDOW_NO_INPUT = NK_FLAG(10) +}; +/*/// #### nk_begin +/// Starts a new window; needs to be called every frame for every +/// window (unless hidden) or otherwise the window gets removed +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// nk_bool nk_begin(struct nk_context *ctx, const char *title, struct nk_rect bounds, nk_flags flags); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct +/// __title__ | Window title and identifier. Needs to be persistent over frames to identify the window +/// __bounds__ | Initial position and window size. However if you do not define `NK_WINDOW_SCALABLE` or `NK_WINDOW_MOVABLE` you can set window position and size every frame +/// __flags__ | Window flags defined in the nk_panel_flags section with a number of different window behaviors +/// +/// Returns `true(1)` if the window can be filled up with widgets from this point +/// until `nk_end` or `false(0)` otherwise for example if minimized +*/ +NK_API nk_bool nk_begin(struct nk_context *ctx, const char *title, struct nk_rect bounds, nk_flags flags); +/*/// #### nk_begin_titled +/// Extended window start with separated title and identifier to allow multiple +/// windows with same title but not name +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// nk_bool nk_begin_titled(struct nk_context *ctx, const char *name, const char *title, struct nk_rect bounds, nk_flags flags); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct +/// __name__ | Window identifier. Needs to be persistent over frames to identify the window +/// __title__ | Window title displayed inside header if flag `NK_WINDOW_TITLE` or either `NK_WINDOW_CLOSABLE` or `NK_WINDOW_MINIMIZED` was set +/// __bounds__ | Initial position and window size. However if you do not define `NK_WINDOW_SCALABLE` or `NK_WINDOW_MOVABLE` you can set window position and size every frame +/// __flags__ | Window flags defined in the nk_panel_flags section with a number of different window behaviors +/// +/// Returns `true(1)` if the window can be filled up with widgets from this point +/// until `nk_end` or `false(0)` otherwise for example if minimized +*/ +NK_API nk_bool nk_begin_titled(struct nk_context *ctx, const char *name, const char *title, struct nk_rect bounds, nk_flags flags); +/*/// #### nk_end +/// Needs to be called at the end of the window building process to process scaling, scrollbars and general cleanup. +/// All widget calls after this functions will result in asserts or no state changes +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// void nk_end(struct nk_context *ctx); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct +*/ +NK_API void nk_end(struct nk_context *ctx); +/*/// #### nk_window_find +/// Finds and returns a window from passed name +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// struct nk_window *nk_window_find(struct nk_context *ctx, const char *name); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct +/// __name__ | Window identifier +/// +/// Returns a `nk_window` struct pointing to the identified window or NULL if +/// no window with the given name was found +*/ +NK_API struct nk_window *nk_window_find(struct nk_context *ctx, const char *name); +/*/// #### nk_window_get_bounds +/// Returns a rectangle with screen position and size of the currently processed window +/// +/// !!! WARNING +/// Only call this function between calls `nk_begin_xxx` and `nk_end` +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// struct nk_rect nk_window_get_bounds(const struct nk_context *ctx); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct +/// +/// Returns a `nk_rect` struct with window upper left window position and size +*/ +NK_API struct nk_rect nk_window_get_bounds(const struct nk_context *ctx); +/*/// #### nk_window_get_position +/// Returns the position of the currently processed window. +/// +/// !!! WARNING +/// Only call this function between calls `nk_begin_xxx` and `nk_end` +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// struct nk_vec2 nk_window_get_position(const struct nk_context *ctx); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct +/// +/// Returns a `nk_vec2` struct with window upper left position +*/ +NK_API struct nk_vec2 nk_window_get_position(const struct nk_context *ctx); +/*/// #### nk_window_get_size +/// Returns the size with width and height of the currently processed window. +/// +/// !!! WARNING +/// Only call this function between calls `nk_begin_xxx` and `nk_end` +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// struct nk_vec2 nk_window_get_size(const struct nk_context *ctx); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct +/// +/// Returns a `nk_vec2` struct with window width and height +*/ +NK_API struct nk_vec2 nk_window_get_size(const struct nk_context*); +/*/// #### nk_window_get_width +/// Returns the width of the currently processed window. +/// +/// !!! WARNING +/// Only call this function between calls `nk_begin_xxx` and `nk_end` +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// float nk_window_get_width(const struct nk_context *ctx); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct +/// +/// Returns the current window width +*/ +NK_API float nk_window_get_width(const struct nk_context*); +/*/// #### nk_window_get_height +/// Returns the height of the currently processed window. +/// +/// !!! WARNING +/// Only call this function between calls `nk_begin_xxx` and `nk_end` +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// float nk_window_get_height(const struct nk_context *ctx); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct +/// +/// Returns the current window height +*/ +NK_API float nk_window_get_height(const struct nk_context*); +/*/// #### nk_window_get_panel +/// Returns the underlying panel which contains all processing state of the current window. +/// +/// !!! WARNING +/// Only call this function between calls `nk_begin_xxx` and `nk_end` +/// !!! WARNING +/// Do not keep the returned panel pointer around, it is only valid until `nk_end` +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// struct nk_panel* nk_window_get_panel(struct nk_context *ctx); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct +/// +/// Returns a pointer to window internal `nk_panel` state. +*/ +NK_API struct nk_panel* nk_window_get_panel(struct nk_context*); +/*/// #### nk_window_get_content_region +/// Returns the position and size of the currently visible and non-clipped space +/// inside the currently processed window. +/// +/// !!! WARNING +/// Only call this function between calls `nk_begin_xxx` and `nk_end` +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// struct nk_rect nk_window_get_content_region(struct nk_context *ctx); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct +/// +/// Returns `nk_rect` struct with screen position and size (no scrollbar offset) +/// of the visible space inside the current window +*/ +NK_API struct nk_rect nk_window_get_content_region(struct nk_context*); +/*/// #### nk_window_get_content_region_min +/// Returns the upper left position of the currently visible and non-clipped +/// space inside the currently processed window. +/// +/// !!! WARNING +/// Only call this function between calls `nk_begin_xxx` and `nk_end` +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// struct nk_vec2 nk_window_get_content_region_min(struct nk_context *ctx); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct +/// +/// returns `nk_vec2` struct with upper left screen position (no scrollbar offset) +/// of the visible space inside the current window +*/ +NK_API struct nk_vec2 nk_window_get_content_region_min(struct nk_context*); +/*/// #### nk_window_get_content_region_max +/// Returns the lower right screen position of the currently visible and +/// non-clipped space inside the currently processed window. +/// +/// !!! WARNING +/// Only call this function between calls `nk_begin_xxx` and `nk_end` +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// struct nk_vec2 nk_window_get_content_region_max(struct nk_context *ctx); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct +/// +/// Returns `nk_vec2` struct with lower right screen position (no scrollbar offset) +/// of the visible space inside the current window +*/ +NK_API struct nk_vec2 nk_window_get_content_region_max(struct nk_context*); +/*/// #### nk_window_get_content_region_size +/// Returns the size of the currently visible and non-clipped space inside the +/// currently processed window +/// +/// !!! WARNING +/// Only call this function between calls `nk_begin_xxx` and `nk_end` +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// struct nk_vec2 nk_window_get_content_region_size(struct nk_context *ctx); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct +/// +/// Returns `nk_vec2` struct with size the visible space inside the current window +*/ +NK_API struct nk_vec2 nk_window_get_content_region_size(struct nk_context*); +/*/// #### nk_window_get_canvas +/// Returns the draw command buffer. Can be used to draw custom widgets +/// !!! WARNING +/// Only call this function between calls `nk_begin_xxx` and `nk_end` +/// !!! WARNING +/// Do not keep the returned command buffer pointer around it is only valid until `nk_end` +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// struct nk_command_buffer* nk_window_get_canvas(struct nk_context *ctx); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct +/// +/// Returns a pointer to window internal `nk_command_buffer` struct used as +/// drawing canvas. Can be used to do custom drawing. +*/ +NK_API struct nk_command_buffer* nk_window_get_canvas(struct nk_context*); +/*/// #### nk_window_get_scroll +/// Gets the scroll offset for the current window +/// !!! WARNING +/// Only call this function between calls `nk_begin_xxx` and `nk_end` +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// void nk_window_get_scroll(struct nk_context *ctx, nk_uint *offset_x, nk_uint *offset_y); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// -------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct +/// __offset_x__ | A pointer to the x offset output (or NULL to ignore) +/// __offset_y__ | A pointer to the y offset output (or NULL to ignore) +*/ +NK_API void nk_window_get_scroll(struct nk_context*, nk_uint *offset_x, nk_uint *offset_y); +/*/// #### nk_window_has_focus +/// Returns if the currently processed window is currently active +/// !!! WARNING +/// Only call this function between calls `nk_begin_xxx` and `nk_end` +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// nk_bool nk_window_has_focus(const struct nk_context *ctx); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct +/// +/// Returns `false(0)` if current window is not active or `true(1)` if it is +*/ +NK_API nk_bool nk_window_has_focus(const struct nk_context*); +/*/// #### nk_window_is_hovered +/// Return if the current window is being hovered +/// !!! WARNING +/// Only call this function between calls `nk_begin_xxx` and `nk_end` +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// nk_bool nk_window_is_hovered(struct nk_context *ctx); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct +/// +/// Returns `true(1)` if current window is hovered or `false(0)` otherwise +*/ +NK_API nk_bool nk_window_is_hovered(struct nk_context*); +/*/// #### nk_window_is_collapsed +/// Returns if the window with given name is currently minimized/collapsed +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// nk_bool nk_window_is_collapsed(struct nk_context *ctx, const char *name); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct +/// __name__ | Identifier of window you want to check if it is collapsed +/// +/// Returns `true(1)` if current window is minimized and `false(0)` if window not +/// found or is not minimized +*/ +NK_API nk_bool nk_window_is_collapsed(struct nk_context *ctx, const char *name); +/*/// #### nk_window_is_closed +/// Returns if the window with given name was closed by calling `nk_close` +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// nk_bool nk_window_is_closed(struct nk_context *ctx, const char *name); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct +/// __name__ | Identifier of window you want to check if it is closed +/// +/// Returns `true(1)` if current window was closed or `false(0)` window not found or not closed +*/ +NK_API nk_bool nk_window_is_closed(struct nk_context*, const char*); +/*/// #### nk_window_is_hidden +/// Returns if the window with given name is hidden +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// nk_bool nk_window_is_hidden(struct nk_context *ctx, const char *name); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct +/// __name__ | Identifier of window you want to check if it is hidden +/// +/// Returns `true(1)` if current window is hidden or `false(0)` window not found or visible +*/ +NK_API nk_bool nk_window_is_hidden(struct nk_context*, const char*); +/*/// #### nk_window_is_active +/// Same as nk_window_has_focus for some reason +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// nk_bool nk_window_is_active(struct nk_context *ctx, const char *name); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct +/// __name__ | Identifier of window you want to check if it is active +/// +/// Returns `true(1)` if current window is active or `false(0)` window not found or not active +*/ +NK_API nk_bool nk_window_is_active(struct nk_context*, const char*); +/*/// #### nk_window_is_any_hovered +/// Returns if the any window is being hovered +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// nk_bool nk_window_is_any_hovered(struct nk_context*); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct +/// +/// Returns `true(1)` if any window is hovered or `false(0)` otherwise +*/ +NK_API nk_bool nk_window_is_any_hovered(struct nk_context*); +/*/// #### nk_item_is_any_active +/// Returns if the any window is being hovered or any widget is currently active. +/// Can be used to decide if input should be processed by UI or your specific input handling. +/// Example could be UI and 3D camera to move inside a 3D space. +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// nk_bool nk_item_is_any_active(struct nk_context*); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct +/// +/// Returns `true(1)` if any window is hovered or any item is active or `false(0)` otherwise +*/ +NK_API nk_bool nk_item_is_any_active(struct nk_context*); +/*/// #### nk_window_set_bounds +/// Updates position and size of window with passed in name +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// void nk_window_set_bounds(struct nk_context*, const char *name, struct nk_rect bounds); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct +/// __name__ | Identifier of the window to modify both position and size +/// __bounds__ | Must point to a `nk_rect` struct with the new position and size +*/ +NK_API void nk_window_set_bounds(struct nk_context*, const char *name, struct nk_rect bounds); +/*/// #### nk_window_set_position +/// Updates position of window with passed name +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// void nk_window_set_position(struct nk_context*, const char *name, struct nk_vec2 pos); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct +/// __name__ | Identifier of the window to modify both position +/// __pos__ | Must point to a `nk_vec2` struct with the new position +*/ +NK_API void nk_window_set_position(struct nk_context*, const char *name, struct nk_vec2 pos); +/*/// #### nk_window_set_size +/// Updates size of window with passed in name +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// void nk_window_set_size(struct nk_context*, const char *name, struct nk_vec2); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct +/// __name__ | Identifier of the window to modify both window size +/// __size__ | Must point to a `nk_vec2` struct with new window size +*/ +NK_API void nk_window_set_size(struct nk_context*, const char *name, struct nk_vec2); +/*/// #### nk_window_set_focus +/// Sets the window with given name as active +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// void nk_window_set_focus(struct nk_context*, const char *name); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct +/// __name__ | Identifier of the window to set focus on +*/ +NK_API void nk_window_set_focus(struct nk_context*, const char *name); +/*/// #### nk_window_set_scroll +/// Sets the scroll offset for the current window +/// !!! WARNING +/// Only call this function between calls `nk_begin_xxx` and `nk_end` +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// void nk_window_set_scroll(struct nk_context *ctx, nk_uint offset_x, nk_uint offset_y); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// -------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct +/// __offset_x__ | The x offset to scroll to +/// __offset_y__ | The y offset to scroll to +*/ +NK_API void nk_window_set_scroll(struct nk_context*, nk_uint offset_x, nk_uint offset_y); +/*/// #### nk_window_close +/// Closes a window and marks it for being freed at the end of the frame +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// void nk_window_close(struct nk_context *ctx, const char *name); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct +/// __name__ | Identifier of the window to close +*/ +NK_API void nk_window_close(struct nk_context *ctx, const char *name); +/*/// #### nk_window_collapse +/// Updates collapse state of a window with given name +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// void nk_window_collapse(struct nk_context*, const char *name, enum nk_collapse_states state); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct +/// __name__ | Identifier of the window to close +/// __state__ | value out of nk_collapse_states section +*/ +NK_API void nk_window_collapse(struct nk_context*, const char *name, enum nk_collapse_states state); +/*/// #### nk_window_collapse_if +/// Updates collapse state of a window with given name if given condition is met +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// void nk_window_collapse_if(struct nk_context*, const char *name, enum nk_collapse_states, int cond); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct +/// __name__ | Identifier of the window to either collapse or maximize +/// __state__ | value out of nk_collapse_states section the window should be put into +/// __cond__ | condition that has to be met to actually commit the collapse state change +*/ +NK_API void nk_window_collapse_if(struct nk_context*, const char *name, enum nk_collapse_states, int cond); +/*/// #### nk_window_show +/// updates visibility state of a window with given name +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// void nk_window_show(struct nk_context*, const char *name, enum nk_show_states); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct +/// __name__ | Identifier of the window to either collapse or maximize +/// __state__ | state with either visible or hidden to modify the window with +*/ +NK_API void nk_window_show(struct nk_context*, const char *name, enum nk_show_states); +/*/// #### nk_window_show_if +/// Updates visibility state of a window with given name if a given condition is met +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// void nk_window_show_if(struct nk_context*, const char *name, enum nk_show_states, int cond); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct +/// __name__ | Identifier of the window to either hide or show +/// __state__ | state with either visible or hidden to modify the window with +/// __cond__ | condition that has to be met to actually commit the visbility state change +*/ +NK_API void nk_window_show_if(struct nk_context*, const char *name, enum nk_show_states, int cond); +/* ============================================================================= + * + * LAYOUT + * + * ============================================================================= +/// ### Layouting +/// Layouting in general describes placing widget inside a window with position and size. +/// While in this particular implementation there are five different APIs for layouting +/// each with different trade offs between control and ease of use.

+/// +/// All layouting methods in this library are based around the concept of a row. +/// A row has a height the window content grows by and a number of columns and each +/// layouting method specifies how each widget is placed inside the row. +/// After a row has been allocated by calling a layouting functions and then +/// filled with widgets will advance an internal pointer over the allocated row.

+/// +/// To actually define a layout you just call the appropriate layouting function +/// and each subsequent widget call will place the widget as specified. Important +/// here is that if you define more widgets then columns defined inside the layout +/// functions it will allocate the next row without you having to make another layouting

+/// call. +/// +/// Biggest limitation with using all these APIs outside the `nk_layout_space_xxx` API +/// is that you have to define the row height for each. However the row height +/// often depends on the height of the font.

+/// +/// To fix that internally nuklear uses a minimum row height that is set to the +/// height plus padding of currently active font and overwrites the row height +/// value if zero.

+/// +/// If you manually want to change the minimum row height then +/// use nk_layout_set_min_row_height, and use nk_layout_reset_min_row_height to +/// reset it back to be derived from font height.

+/// +/// Also if you change the font in nuklear it will automatically change the minimum +/// row height for you and. This means if you change the font but still want +/// a minimum row height smaller than the font you have to repush your value.

+/// +/// For actually more advanced UI I would even recommend using the `nk_layout_space_xxx` +/// layouting method in combination with a cassowary constraint solver (there are +/// some versions on github with permissive license model) to take over all control over widget +/// layouting yourself. However for quick and dirty layouting using all the other layouting +/// functions should be fine. +/// +/// #### Usage +/// 1. __nk_layout_row_dynamic__

+/// The easiest layouting function is `nk_layout_row_dynamic`. It provides each +/// widgets with same horizontal space inside the row and dynamically grows +/// if the owning window grows in width. So the number of columns dictates +/// the size of each widget dynamically by formula: +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// widget_width = (window_width - padding - spacing) * (1/colum_count) +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Just like all other layouting APIs if you define more widget than columns this +/// library will allocate a new row and keep all layouting parameters previously +/// defined. +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// if (nk_begin_xxx(...) { +/// // first row with height: 30 composed of two widgets +/// nk_layout_row_dynamic(&ctx, 30, 2); +/// nk_widget(...); +/// nk_widget(...); +/// // +/// // second row with same parameter as defined above +/// nk_widget(...); +/// nk_widget(...); +/// // +/// // third row uses 0 for height which will use auto layouting +/// nk_layout_row_dynamic(&ctx, 0, 2); +/// nk_widget(...); +/// nk_widget(...); +/// } +/// nk_end(...); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// 2. __nk_layout_row_static__

+/// Another easy layouting function is `nk_layout_row_static`. It provides each +/// widget with same horizontal pixel width inside the row and does not grow +/// if the owning window scales smaller or bigger. +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// if (nk_begin_xxx(...) { +/// // first row with height: 30 composed of two widgets with width: 80 +/// nk_layout_row_static(&ctx, 30, 80, 2); +/// nk_widget(...); +/// nk_widget(...); +/// // +/// // second row with same parameter as defined above +/// nk_widget(...); +/// nk_widget(...); +/// // +/// // third row uses 0 for height which will use auto layouting +/// nk_layout_row_static(&ctx, 0, 80, 2); +/// nk_widget(...); +/// nk_widget(...); +/// } +/// nk_end(...); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// 3. __nk_layout_row_xxx__

+/// A little bit more advanced layouting API are functions `nk_layout_row_begin`, +/// `nk_layout_row_push` and `nk_layout_row_end`. They allow to directly +/// specify each column pixel or window ratio in a row. It supports either +/// directly setting per column pixel width or widget window ratio but not +/// both. Furthermore it is a immediate mode API so each value is directly +/// pushed before calling a widget. Therefore the layout is not automatically +/// repeating like the last two layouting functions. +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// if (nk_begin_xxx(...) { +/// // first row with height: 25 composed of two widgets with width 60 and 40 +/// nk_layout_row_begin(ctx, NK_STATIC, 25, 2); +/// nk_layout_row_push(ctx, 60); +/// nk_widget(...); +/// nk_layout_row_push(ctx, 40); +/// nk_widget(...); +/// nk_layout_row_end(ctx); +/// // +/// // second row with height: 25 composed of two widgets with window ratio 0.25 and 0.75 +/// nk_layout_row_begin(ctx, NK_DYNAMIC, 25, 2); +/// nk_layout_row_push(ctx, 0.25f); +/// nk_widget(...); +/// nk_layout_row_push(ctx, 0.75f); +/// nk_widget(...); +/// nk_layout_row_end(ctx); +/// // +/// // third row with auto generated height: composed of two widgets with window ratio 0.25 and 0.75 +/// nk_layout_row_begin(ctx, NK_DYNAMIC, 0, 2); +/// nk_layout_row_push(ctx, 0.25f); +/// nk_widget(...); +/// nk_layout_row_push(ctx, 0.75f); +/// nk_widget(...); +/// nk_layout_row_end(ctx); +/// } +/// nk_end(...); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// 4. __nk_layout_row__

+/// The array counterpart to API nk_layout_row_xxx is the single nk_layout_row +/// functions. Instead of pushing either pixel or window ratio for every widget +/// it allows to define it by array. The trade of for less control is that +/// `nk_layout_row` is automatically repeating. Otherwise the behavior is the +/// same. +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// if (nk_begin_xxx(...) { +/// // two rows with height: 30 composed of two widgets with width 60 and 40 +/// const float ratio[] = {60,40}; +/// nk_layout_row(ctx, NK_STATIC, 30, 2, ratio); +/// nk_widget(...); +/// nk_widget(...); +/// nk_widget(...); +/// nk_widget(...); +/// // +/// // two rows with height: 30 composed of two widgets with window ratio 0.25 and 0.75 +/// const float ratio[] = {0.25, 0.75}; +/// nk_layout_row(ctx, NK_DYNAMIC, 30, 2, ratio); +/// nk_widget(...); +/// nk_widget(...); +/// nk_widget(...); +/// nk_widget(...); +/// // +/// // two rows with auto generated height composed of two widgets with window ratio 0.25 and 0.75 +/// const float ratio[] = {0.25, 0.75}; +/// nk_layout_row(ctx, NK_DYNAMIC, 30, 2, ratio); +/// nk_widget(...); +/// nk_widget(...); +/// nk_widget(...); +/// nk_widget(...); +/// } +/// nk_end(...); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// 5. __nk_layout_row_template_xxx__

+/// The most complex and second most flexible API is a simplified flexbox version without +/// line wrapping and weights for dynamic widgets. It is an immediate mode API but +/// unlike `nk_layout_row_xxx` it has auto repeat behavior and needs to be called +/// before calling the templated widgets. +/// The row template layout has three different per widget size specifier. The first +/// one is the `nk_layout_row_template_push_static` with fixed widget pixel width. +/// They do not grow if the row grows and will always stay the same. +/// The second size specifier is `nk_layout_row_template_push_variable` +/// which defines a minimum widget size but it also can grow if more space is available +/// not taken by other widgets. +/// Finally there are dynamic widgets with `nk_layout_row_template_push_dynamic` +/// which are completely flexible and unlike variable widgets can even shrink +/// to zero if not enough space is provided. +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// if (nk_begin_xxx(...) { +/// // two rows with height: 30 composed of three widgets +/// nk_layout_row_template_begin(ctx, 30); +/// nk_layout_row_template_push_dynamic(ctx); +/// nk_layout_row_template_push_variable(ctx, 80); +/// nk_layout_row_template_push_static(ctx, 80); +/// nk_layout_row_template_end(ctx); +/// // +/// // first row +/// nk_widget(...); // dynamic widget can go to zero if not enough space +/// nk_widget(...); // variable widget with min 80 pixel but can grow bigger if enough space +/// nk_widget(...); // static widget with fixed 80 pixel width +/// // +/// // second row same layout +/// nk_widget(...); +/// nk_widget(...); +/// nk_widget(...); +/// } +/// nk_end(...); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// 6. __nk_layout_space_xxx__

+/// Finally the most flexible API directly allows you to place widgets inside the +/// window. The space layout API is an immediate mode API which does not support +/// row auto repeat and directly sets position and size of a widget. Position +/// and size hereby can be either specified as ratio of allocated space or +/// allocated space local position and pixel size. Since this API is quite +/// powerful there are a number of utility functions to get the available space +/// and convert between local allocated space and screen space. +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// if (nk_begin_xxx(...) { +/// // static row with height: 500 (you can set column count to INT_MAX if you don't want to be bothered) +/// nk_layout_space_begin(ctx, NK_STATIC, 500, INT_MAX); +/// nk_layout_space_push(ctx, nk_rect(0,0,150,200)); +/// nk_widget(...); +/// nk_layout_space_push(ctx, nk_rect(200,200,100,200)); +/// nk_widget(...); +/// nk_layout_space_end(ctx); +/// // +/// // dynamic row with height: 500 (you can set column count to INT_MAX if you don't want to be bothered) +/// nk_layout_space_begin(ctx, NK_DYNAMIC, 500, INT_MAX); +/// nk_layout_space_push(ctx, nk_rect(0.5,0.5,0.1,0.1)); +/// nk_widget(...); +/// nk_layout_space_push(ctx, nk_rect(0.7,0.6,0.1,0.1)); +/// nk_widget(...); +/// } +/// nk_end(...); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// #### Reference +/// Function | Description +/// ----------------------------------------|------------------------------------ +/// nk_layout_set_min_row_height | Set the currently used minimum row height to a specified value +/// nk_layout_reset_min_row_height | Resets the currently used minimum row height to font height +/// nk_layout_widget_bounds | Calculates current width a static layout row can fit inside a window +/// nk_layout_ratio_from_pixel | Utility functions to calculate window ratio from pixel size +// +/// nk_layout_row_dynamic | Current layout is divided into n same sized growing columns +/// nk_layout_row_static | Current layout is divided into n same fixed sized columns +/// nk_layout_row_begin | Starts a new row with given height and number of columns +/// nk_layout_row_push | Pushes another column with given size or window ratio +/// nk_layout_row_end | Finished previously started row +/// nk_layout_row | Specifies row columns in array as either window ratio or size +// +/// nk_layout_row_template_begin | Begins the row template declaration +/// nk_layout_row_template_push_dynamic | Adds a dynamic column that dynamically grows and can go to zero if not enough space +/// nk_layout_row_template_push_variable | Adds a variable column that dynamically grows but does not shrink below specified pixel width +/// nk_layout_row_template_push_static | Adds a static column that does not grow and will always have the same size +/// nk_layout_row_template_end | Marks the end of the row template +// +/// nk_layout_space_begin | Begins a new layouting space that allows to specify each widgets position and size +/// nk_layout_space_push | Pushes position and size of the next widget in own coordinate space either as pixel or ratio +/// nk_layout_space_end | Marks the end of the layouting space +// +/// nk_layout_space_bounds | Callable after nk_layout_space_begin and returns total space allocated +/// nk_layout_space_to_screen | Converts vector from nk_layout_space coordinate space into screen space +/// nk_layout_space_to_local | Converts vector from screen space into nk_layout_space coordinates +/// nk_layout_space_rect_to_screen | Converts rectangle from nk_layout_space coordinate space into screen space +/// nk_layout_space_rect_to_local | Converts rectangle from screen space into nk_layout_space coordinates +*/ +/*/// #### nk_layout_set_min_row_height +/// Sets the currently used minimum row height. +/// !!! WARNING +/// The passed height needs to include both your preferred row height +/// as well as padding. No internal padding is added. +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// void nk_layout_set_min_row_height(struct nk_context*, float height); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` +/// __height__ | New minimum row height to be used for auto generating the row height +*/ +NK_API void nk_layout_set_min_row_height(struct nk_context*, float height); +/*/// #### nk_layout_reset_min_row_height +/// Reset the currently used minimum row height back to `font_height + text_padding + padding` +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// void nk_layout_reset_min_row_height(struct nk_context*); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` +*/ +NK_API void nk_layout_reset_min_row_height(struct nk_context*); +/*/// #### nk_layout_widget_bounds +/// Returns the width of the next row allocate by one of the layouting functions +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// struct nk_rect nk_layout_widget_bounds(struct nk_context*); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` +/// +/// Return `nk_rect` with both position and size of the next row +*/ +NK_API struct nk_rect nk_layout_widget_bounds(struct nk_context*); +/*/// #### nk_layout_ratio_from_pixel +/// Utility functions to calculate window ratio from pixel size +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// float nk_layout_ratio_from_pixel(struct nk_context*, float pixel_width); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` +/// __pixel__ | Pixel_width to convert to window ratio +/// +/// Returns `nk_rect` with both position and size of the next row +*/ +NK_API float nk_layout_ratio_from_pixel(struct nk_context*, float pixel_width); +/*/// #### nk_layout_row_dynamic +/// Sets current row layout to share horizontal space +/// between @cols number of widgets evenly. Once called all subsequent widget +/// calls greater than @cols will allocate a new row with same layout. +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// void nk_layout_row_dynamic(struct nk_context *ctx, float height, int cols); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` +/// __height__ | Holds height of each widget in row or zero for auto layouting +/// __columns__ | Number of widget inside row +*/ +NK_API void nk_layout_row_dynamic(struct nk_context *ctx, float height, int cols); +/*/// #### nk_layout_row_static +/// Sets current row layout to fill @cols number of widgets +/// in row with same @item_width horizontal size. Once called all subsequent widget +/// calls greater than @cols will allocate a new row with same layout. +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// void nk_layout_row_static(struct nk_context *ctx, float height, int item_width, int cols); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` +/// __height__ | Holds height of each widget in row or zero for auto layouting +/// __width__ | Holds pixel width of each widget in the row +/// __columns__ | Number of widget inside row +*/ +NK_API void nk_layout_row_static(struct nk_context *ctx, float height, int item_width, int cols); +/*/// #### nk_layout_row_begin +/// Starts a new dynamic or fixed row with given height and columns. +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// void nk_layout_row_begin(struct nk_context *ctx, enum nk_layout_format fmt, float row_height, int cols); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` +/// __fmt__ | either `NK_DYNAMIC` for window ratio or `NK_STATIC` for fixed size columns +/// __height__ | holds height of each widget in row or zero for auto layouting +/// __columns__ | Number of widget inside row +*/ +NK_API void nk_layout_row_begin(struct nk_context *ctx, enum nk_layout_format fmt, float row_height, int cols); +/*/// #### nk_layout_row_push +/// Specifies either window ratio or width of a single column +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// void nk_layout_row_push(struct nk_context*, float value); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` +/// __value__ | either a window ratio or fixed width depending on @fmt in previous `nk_layout_row_begin` call +*/ +NK_API void nk_layout_row_push(struct nk_context*, float value); +/*/// #### nk_layout_row_end +/// Finished previously started row +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// void nk_layout_row_end(struct nk_context*); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` +*/ +NK_API void nk_layout_row_end(struct nk_context*); +/*/// #### nk_layout_row +/// Specifies row columns in array as either window ratio or size +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// void nk_layout_row(struct nk_context*, enum nk_layout_format, float height, int cols, const float *ratio); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` +/// __fmt__ | Either `NK_DYNAMIC` for window ratio or `NK_STATIC` for fixed size columns +/// __height__ | Holds height of each widget in row or zero for auto layouting +/// __columns__ | Number of widget inside row +*/ +NK_API void nk_layout_row(struct nk_context*, enum nk_layout_format, float height, int cols, const float *ratio); +/*/// #### nk_layout_row_template_begin +/// Begins the row template declaration +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// void nk_layout_row_template_begin(struct nk_context*, float row_height); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` +/// __height__ | Holds height of each widget in row or zero for auto layouting +*/ +NK_API void nk_layout_row_template_begin(struct nk_context*, float row_height); +/*/// #### nk_layout_row_template_push_dynamic +/// Adds a dynamic column that dynamically grows and can go to zero if not enough space +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// void nk_layout_row_template_push_dynamic(struct nk_context*); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` +/// __height__ | Holds height of each widget in row or zero for auto layouting +*/ +NK_API void nk_layout_row_template_push_dynamic(struct nk_context*); +/*/// #### nk_layout_row_template_push_variable +/// Adds a variable column that dynamically grows but does not shrink below specified pixel width +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// void nk_layout_row_template_push_variable(struct nk_context*, float min_width); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` +/// __width__ | Holds the minimum pixel width the next column must always be +*/ +NK_API void nk_layout_row_template_push_variable(struct nk_context*, float min_width); +/*/// #### nk_layout_row_template_push_static +/// Adds a static column that does not grow and will always have the same size +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// void nk_layout_row_template_push_static(struct nk_context*, float width); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` +/// __width__ | Holds the absolute pixel width value the next column must be +*/ +NK_API void nk_layout_row_template_push_static(struct nk_context*, float width); +/*/// #### nk_layout_row_template_end +/// Marks the end of the row template +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// void nk_layout_row_template_end(struct nk_context*); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` +*/ +NK_API void nk_layout_row_template_end(struct nk_context*); +/*/// #### nk_layout_space_begin +/// Begins a new layouting space that allows to specify each widgets position and size. +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// void nk_layout_space_begin(struct nk_context*, enum nk_layout_format, float height, int widget_count); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` +/// __fmt__ | Either `NK_DYNAMIC` for window ratio or `NK_STATIC` for fixed size columns +/// __height__ | Holds height of each widget in row or zero for auto layouting +/// __columns__ | Number of widgets inside row +*/ +NK_API void nk_layout_space_begin(struct nk_context*, enum nk_layout_format, float height, int widget_count); +/*/// #### nk_layout_space_push +/// Pushes position and size of the next widget in own coordinate space either as pixel or ratio +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// void nk_layout_space_push(struct nk_context *ctx, struct nk_rect bounds); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin` +/// __bounds__ | Position and size in laoyut space local coordinates +*/ +NK_API void nk_layout_space_push(struct nk_context*, struct nk_rect bounds); +/*/// #### nk_layout_space_end +/// Marks the end of the layout space +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// void nk_layout_space_end(struct nk_context*); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin` +*/ +NK_API void nk_layout_space_end(struct nk_context*); +/*/// #### nk_layout_space_bounds +/// Utility function to calculate total space allocated for `nk_layout_space` +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// struct nk_rect nk_layout_space_bounds(struct nk_context*); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin` +/// +/// Returns `nk_rect` holding the total space allocated +*/ +NK_API struct nk_rect nk_layout_space_bounds(struct nk_context*); +/*/// #### nk_layout_space_to_screen +/// Converts vector from nk_layout_space coordinate space into screen space +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// struct nk_vec2 nk_layout_space_to_screen(struct nk_context*, struct nk_vec2); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin` +/// __vec__ | Position to convert from layout space into screen coordinate space +/// +/// Returns transformed `nk_vec2` in screen space coordinates +*/ +NK_API struct nk_vec2 nk_layout_space_to_screen(struct nk_context*, struct nk_vec2); +/*/// #### nk_layout_space_to_local +/// Converts vector from layout space into screen space +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// struct nk_vec2 nk_layout_space_to_local(struct nk_context*, struct nk_vec2); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin` +/// __vec__ | Position to convert from screen space into layout coordinate space +/// +/// Returns transformed `nk_vec2` in layout space coordinates +*/ +NK_API struct nk_vec2 nk_layout_space_to_local(struct nk_context*, struct nk_vec2); +/*/// #### nk_layout_space_rect_to_screen +/// Converts rectangle from screen space into layout space +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// struct nk_rect nk_layout_space_rect_to_screen(struct nk_context*, struct nk_rect); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin` +/// __bounds__ | Rectangle to convert from layout space into screen space +/// +/// Returns transformed `nk_rect` in screen space coordinates +*/ +NK_API struct nk_rect nk_layout_space_rect_to_screen(struct nk_context*, struct nk_rect); +/*/// #### nk_layout_space_rect_to_local +/// Converts rectangle from layout space into screen space +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// struct nk_rect nk_layout_space_rect_to_local(struct nk_context*, struct nk_rect); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin` +/// __bounds__ | Rectangle to convert from layout space into screen space +/// +/// Returns transformed `nk_rect` in layout space coordinates +*/ +NK_API struct nk_rect nk_layout_space_rect_to_local(struct nk_context*, struct nk_rect); + +/*/// #### nk_spacer +/// Spacer is a dummy widget that consumes space as usual but doesn't draw anything +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// void nk_spacer(struct nk_context* ); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin` +/// +*/ +NK_API void nk_spacer(struct nk_context* ); + + +/* ============================================================================= + * + * GROUP + * + * ============================================================================= +/// ### Groups +/// Groups are basically windows inside windows. They allow to subdivide space +/// in a window to layout widgets as a group. Almost all more complex widget +/// layouting requirements can be solved using groups and basic layouting +/// fuctionality. Groups just like windows are identified by an unique name and +/// internally keep track of scrollbar offsets by default. However additional +/// versions are provided to directly manage the scrollbar. +/// +/// #### Usage +/// To create a group you have to call one of the three `nk_group_begin_xxx` +/// functions to start group declarations and `nk_group_end` at the end. Furthermore it +/// is required to check the return value of `nk_group_begin_xxx` and only process +/// widgets inside the window if the value is not 0. +/// Nesting groups is possible and even encouraged since many layouting schemes +/// can only be achieved by nesting. Groups, unlike windows, need `nk_group_end` +/// to be only called if the corresponding `nk_group_begin_xxx` call does not return 0: +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// if (nk_group_begin_xxx(ctx, ...) { +/// // [... widgets ...] +/// nk_group_end(ctx); +/// } +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// In the grand concept groups can be called after starting a window +/// with `nk_begin_xxx` and before calling `nk_end`: +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// struct nk_context ctx; +/// nk_init_xxx(&ctx, ...); +/// while (1) { +/// // Input +/// Event evt; +/// nk_input_begin(&ctx); +/// while (GetEvent(&evt)) { +/// if (evt.type == MOUSE_MOVE) +/// nk_input_motion(&ctx, evt.motion.x, evt.motion.y); +/// else if (evt.type == [...]) { +/// nk_input_xxx(...); +/// } +/// } +/// nk_input_end(&ctx); +/// // +/// // Window +/// if (nk_begin_xxx(...) { +/// // [...widgets...] +/// nk_layout_row_dynamic(...); +/// if (nk_group_begin_xxx(ctx, ...) { +/// //[... widgets ...] +/// nk_group_end(ctx); +/// } +/// } +/// nk_end(ctx); +/// // +/// // Draw +/// const struct nk_command *cmd = 0; +/// nk_foreach(cmd, &ctx) { +/// switch (cmd->type) { +/// case NK_COMMAND_LINE: +/// your_draw_line_function(...) +/// break; +/// case NK_COMMAND_RECT +/// your_draw_rect_function(...) +/// break; +/// case ...: +/// // [...] +/// } +/// nk_clear(&ctx); +/// } +/// nk_free(&ctx); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// #### Reference +/// Function | Description +/// --------------------------------|------------------------------------------- +/// nk_group_begin | Start a new group with internal scrollbar handling +/// nk_group_begin_titled | Start a new group with separated name and title and internal scrollbar handling +/// nk_group_end | Ends a group. Should only be called if nk_group_begin returned non-zero +/// nk_group_scrolled_offset_begin | Start a new group with manual separated handling of scrollbar x- and y-offset +/// nk_group_scrolled_begin | Start a new group with manual scrollbar handling +/// nk_group_scrolled_end | Ends a group with manual scrollbar handling. Should only be called if nk_group_begin returned non-zero +/// nk_group_get_scroll | Gets the scroll offset for the given group +/// nk_group_set_scroll | Sets the scroll offset for the given group +*/ +/*/// #### nk_group_begin +/// Starts a new widget group. Requires a previous layouting function to specify a pos/size. +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// nk_bool nk_group_begin(struct nk_context*, const char *title, nk_flags); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct +/// __title__ | Must be an unique identifier for this group that is also used for the group header +/// __flags__ | Window flags defined in the nk_panel_flags section with a number of different group behaviors +/// +/// Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise +*/ +NK_API nk_bool nk_group_begin(struct nk_context*, const char *title, nk_flags); +/*/// #### nk_group_begin_titled +/// Starts a new widget group. Requires a previous layouting function to specify a pos/size. +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// nk_bool nk_group_begin_titled(struct nk_context*, const char *name, const char *title, nk_flags); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct +/// __id__ | Must be an unique identifier for this group +/// __title__ | Group header title +/// __flags__ | Window flags defined in the nk_panel_flags section with a number of different group behaviors +/// +/// Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise +*/ +NK_API nk_bool nk_group_begin_titled(struct nk_context*, const char *name, const char *title, nk_flags); +/*/// #### nk_group_end +/// Ends a widget group +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// void nk_group_end(struct nk_context*); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct +*/ +NK_API void nk_group_end(struct nk_context*); +/*/// #### nk_group_scrolled_offset_begin +/// starts a new widget group. requires a previous layouting function to specify +/// a size. Does not keep track of scrollbar. +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// nk_bool nk_group_scrolled_offset_begin(struct nk_context*, nk_uint *x_offset, nk_uint *y_offset, const char *title, nk_flags flags); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct +/// __x_offset__| Scrollbar x-offset to offset all widgets inside the group horizontally. +/// __y_offset__| Scrollbar y-offset to offset all widgets inside the group vertically +/// __title__ | Window unique group title used to both identify and display in the group header +/// __flags__ | Window flags from the nk_panel_flags section +/// +/// Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise +*/ +NK_API nk_bool nk_group_scrolled_offset_begin(struct nk_context*, nk_uint *x_offset, nk_uint *y_offset, const char *title, nk_flags flags); +/*/// #### nk_group_scrolled_begin +/// Starts a new widget group. requires a previous +/// layouting function to specify a size. Does not keep track of scrollbar. +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// nk_bool nk_group_scrolled_begin(struct nk_context*, struct nk_scroll *off, const char *title, nk_flags); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct +/// __off__ | Both x- and y- scroll offset. Allows for manual scrollbar control +/// __title__ | Window unique group title used to both identify and display in the group header +/// __flags__ | Window flags from nk_panel_flags section +/// +/// Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise +*/ +NK_API nk_bool nk_group_scrolled_begin(struct nk_context*, struct nk_scroll *off, const char *title, nk_flags); +/*/// #### nk_group_scrolled_end +/// Ends a widget group after calling nk_group_scrolled_offset_begin or nk_group_scrolled_begin. +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// void nk_group_scrolled_end(struct nk_context*); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct +*/ +NK_API void nk_group_scrolled_end(struct nk_context*); +/*/// #### nk_group_get_scroll +/// Gets the scroll position of the given group. +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// void nk_group_get_scroll(struct nk_context*, const char *id, nk_uint *x_offset, nk_uint *y_offset); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// -------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct +/// __id__ | The id of the group to get the scroll position of +/// __x_offset__ | A pointer to the x offset output (or NULL to ignore) +/// __y_offset__ | A pointer to the y offset output (or NULL to ignore) +*/ +NK_API void nk_group_get_scroll(struct nk_context*, const char *id, nk_uint *x_offset, nk_uint *y_offset); +/*/// #### nk_group_set_scroll +/// Sets the scroll position of the given group. +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// void nk_group_set_scroll(struct nk_context*, const char *id, nk_uint x_offset, nk_uint y_offset); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// -------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct +/// __id__ | The id of the group to scroll +/// __x_offset__ | The x offset to scroll to +/// __y_offset__ | The y offset to scroll to +*/ +NK_API void nk_group_set_scroll(struct nk_context*, const char *id, nk_uint x_offset, nk_uint y_offset); +/* ============================================================================= + * + * TREE + * + * ============================================================================= +/// ### Tree +/// Trees represent two different concept. First the concept of a collapsible +/// UI section that can be either in a hidden or visible state. They allow the UI +/// user to selectively minimize the current set of visible UI to comprehend. +/// The second concept are tree widgets for visual UI representation of trees.

+/// +/// Trees thereby can be nested for tree representations and multiple nested +/// collapsible UI sections. All trees are started by calling of the +/// `nk_tree_xxx_push_tree` functions and ended by calling one of the +/// `nk_tree_xxx_pop_xxx()` functions. Each starting functions takes a title label +/// and optionally an image to be displayed and the initial collapse state from +/// the nk_collapse_states section.

+/// +/// The runtime state of the tree is either stored outside the library by the caller +/// or inside which requires a unique ID. The unique ID can either be generated +/// automatically from `__FILE__` and `__LINE__` with function `nk_tree_push`, +/// by `__FILE__` and a user provided ID generated for example by loop index with +/// function `nk_tree_push_id` or completely provided from outside by user with +/// function `nk_tree_push_hashed`. +/// +/// #### Usage +/// To create a tree you have to call one of the seven `nk_tree_xxx_push_xxx` +/// functions to start a collapsible UI section and `nk_tree_xxx_pop` to mark the +/// end. +/// Each starting function will either return `false(0)` if the tree is collapsed +/// or hidden and therefore does not need to be filled with content or `true(1)` +/// if visible and required to be filled. +/// +/// !!! Note +/// The tree header does not require and layouting function and instead +/// calculates a auto height based on the currently used font size +/// +/// The tree ending functions only need to be called if the tree content is +/// actually visible. So make sure the tree push function is guarded by `if` +/// and the pop call is only taken if the tree is visible. +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// if (nk_tree_push(ctx, NK_TREE_TAB, "Tree", NK_MINIMIZED)) { +/// nk_layout_row_dynamic(...); +/// nk_widget(...); +/// nk_tree_pop(ctx); +/// } +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// #### Reference +/// Function | Description +/// ----------------------------|------------------------------------------- +/// nk_tree_push | Start a collapsible UI section with internal state management +/// nk_tree_push_id | Start a collapsible UI section with internal state management callable in a look +/// nk_tree_push_hashed | Start a collapsible UI section with internal state management with full control over internal unique ID use to store state +/// nk_tree_image_push | Start a collapsible UI section with image and label header +/// nk_tree_image_push_id | Start a collapsible UI section with image and label header and internal state management callable in a look +/// nk_tree_image_push_hashed | Start a collapsible UI section with image and label header and internal state management with full control over internal unique ID use to store state +/// nk_tree_pop | Ends a collapsible UI section +// +/// nk_tree_state_push | Start a collapsible UI section with external state management +/// nk_tree_state_image_push | Start a collapsible UI section with image and label header and external state management +/// nk_tree_state_pop | Ends a collapsabale UI section +/// +/// #### nk_tree_type +/// Flag | Description +/// ----------------|---------------------------------------- +/// NK_TREE_NODE | Highlighted tree header to mark a collapsible UI section +/// NK_TREE_TAB | Non-highlighted tree header closer to tree representations +*/ +/*/// #### nk_tree_push +/// Starts a collapsible UI section with internal state management +/// !!! WARNING +/// To keep track of the runtime tree collapsible state this function uses +/// defines `__FILE__` and `__LINE__` to generate a unique ID. If you want +/// to call this function in a loop please use `nk_tree_push_id` or +/// `nk_tree_push_hashed` instead. +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// #define nk_tree_push(ctx, type, title, state) +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct +/// __type__ | Value from the nk_tree_type section to visually mark a tree node header as either a collapseable UI section or tree node +/// __title__ | Label printed in the tree header +/// __state__ | Initial tree state value out of nk_collapse_states +/// +/// Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise +*/ +#define nk_tree_push(ctx, type, title, state) nk_tree_push_hashed(ctx, type, title, state, NK_FILE_LINE,nk_strlen(NK_FILE_LINE),__LINE__) +/*/// #### nk_tree_push_id +/// Starts a collapsible UI section with internal state management callable in a look +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// #define nk_tree_push_id(ctx, type, title, state, id) +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct +/// __type__ | Value from the nk_tree_type section to visually mark a tree node header as either a collapseable UI section or tree node +/// __title__ | Label printed in the tree header +/// __state__ | Initial tree state value out of nk_collapse_states +/// __id__ | Loop counter index if this function is called in a loop +/// +/// Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise +*/ +#define nk_tree_push_id(ctx, type, title, state, id) nk_tree_push_hashed(ctx, type, title, state, NK_FILE_LINE,nk_strlen(NK_FILE_LINE),id) +/*/// #### nk_tree_push_hashed +/// Start a collapsible UI section with internal state management with full +/// control over internal unique ID used to store state +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// nk_bool nk_tree_push_hashed(struct nk_context*, enum nk_tree_type, const char *title, enum nk_collapse_states initial_state, const char *hash, int len,int seed); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct +/// __type__ | Value from the nk_tree_type section to visually mark a tree node header as either a collapseable UI section or tree node +/// __title__ | Label printed in the tree header +/// __state__ | Initial tree state value out of nk_collapse_states +/// __hash__ | Memory block or string to generate the ID from +/// __len__ | Size of passed memory block or string in __hash__ +/// __seed__ | Seeding value if this function is called in a loop or default to `0` +/// +/// Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise +*/ +NK_API nk_bool nk_tree_push_hashed(struct nk_context*, enum nk_tree_type, const char *title, enum nk_collapse_states initial_state, const char *hash, int len,int seed); +/*/// #### nk_tree_image_push +/// Start a collapsible UI section with image and label header +/// !!! WARNING +/// To keep track of the runtime tree collapsible state this function uses +/// defines `__FILE__` and `__LINE__` to generate a unique ID. If you want +/// to call this function in a loop please use `nk_tree_image_push_id` or +/// `nk_tree_image_push_hashed` instead. +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// #define nk_tree_image_push(ctx, type, img, title, state) +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct +/// __type__ | Value from the nk_tree_type section to visually mark a tree node header as either a collapseable UI section or tree node +/// __img__ | Image to display inside the header on the left of the label +/// __title__ | Label printed in the tree header +/// __state__ | Initial tree state value out of nk_collapse_states +/// +/// Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise +*/ +#define nk_tree_image_push(ctx, type, img, title, state) nk_tree_image_push_hashed(ctx, type, img, title, state, NK_FILE_LINE,nk_strlen(NK_FILE_LINE),__LINE__) +/*/// #### nk_tree_image_push_id +/// Start a collapsible UI section with image and label header and internal state +/// management callable in a look +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// #define nk_tree_image_push_id(ctx, type, img, title, state, id) +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct +/// __type__ | Value from the nk_tree_type section to visually mark a tree node header as either a collapseable UI section or tree node +/// __img__ | Image to display inside the header on the left of the label +/// __title__ | Label printed in the tree header +/// __state__ | Initial tree state value out of nk_collapse_states +/// __id__ | Loop counter index if this function is called in a loop +/// +/// Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise +*/ +#define nk_tree_image_push_id(ctx, type, img, title, state, id) nk_tree_image_push_hashed(ctx, type, img, title, state, NK_FILE_LINE,nk_strlen(NK_FILE_LINE),id) +/*/// #### nk_tree_image_push_hashed +/// Start a collapsible UI section with internal state management with full +/// control over internal unique ID used to store state +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// nk_bool nk_tree_image_push_hashed(struct nk_context*, enum nk_tree_type, struct nk_image, const char *title, enum nk_collapse_states initial_state, const char *hash, int len,int seed); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct +/// __type__ | Value from the nk_tree_type section to visually mark a tree node header as either a collapseable UI section or tree node +/// __img__ | Image to display inside the header on the left of the label +/// __title__ | Label printed in the tree header +/// __state__ | Initial tree state value out of nk_collapse_states +/// __hash__ | Memory block or string to generate the ID from +/// __len__ | Size of passed memory block or string in __hash__ +/// __seed__ | Seeding value if this function is called in a loop or default to `0` +/// +/// Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise +*/ +NK_API nk_bool nk_tree_image_push_hashed(struct nk_context*, enum nk_tree_type, struct nk_image, const char *title, enum nk_collapse_states initial_state, const char *hash, int len,int seed); +/*/// #### nk_tree_pop +/// Ends a collapsabale UI section +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// void nk_tree_pop(struct nk_context*); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct after calling `nk_tree_xxx_push_xxx` +*/ +NK_API void nk_tree_pop(struct nk_context*); +/*/// #### nk_tree_state_push +/// Start a collapsible UI section with external state management +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// nk_bool nk_tree_state_push(struct nk_context*, enum nk_tree_type, const char *title, enum nk_collapse_states *state); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct after calling `nk_tree_xxx_push_xxx` +/// __type__ | Value from the nk_tree_type section to visually mark a tree node header as either a collapseable UI section or tree node +/// __title__ | Label printed in the tree header +/// __state__ | Persistent state to update +/// +/// Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise +*/ +NK_API nk_bool nk_tree_state_push(struct nk_context*, enum nk_tree_type, const char *title, enum nk_collapse_states *state); +/*/// #### nk_tree_state_image_push +/// Start a collapsible UI section with image and label header and external state management +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// nk_bool nk_tree_state_image_push(struct nk_context*, enum nk_tree_type, struct nk_image, const char *title, enum nk_collapse_states *state); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct after calling `nk_tree_xxx_push_xxx` +/// __img__ | Image to display inside the header on the left of the label +/// __type__ | Value from the nk_tree_type section to visually mark a tree node header as either a collapseable UI section or tree node +/// __title__ | Label printed in the tree header +/// __state__ | Persistent state to update +/// +/// Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise +*/ +NK_API nk_bool nk_tree_state_image_push(struct nk_context*, enum nk_tree_type, struct nk_image, const char *title, enum nk_collapse_states *state); +/*/// #### nk_tree_state_pop +/// Ends a collapsabale UI section +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// void nk_tree_state_pop(struct nk_context*); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// ------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct after calling `nk_tree_xxx_push_xxx` +*/ +NK_API void nk_tree_state_pop(struct nk_context*); + +#define nk_tree_element_push(ctx, type, title, state, sel) nk_tree_element_push_hashed(ctx, type, title, state, sel, NK_FILE_LINE,nk_strlen(NK_FILE_LINE),__LINE__) +#define nk_tree_element_push_id(ctx, type, title, state, sel, id) nk_tree_element_push_hashed(ctx, type, title, state, sel, NK_FILE_LINE,nk_strlen(NK_FILE_LINE),id) +NK_API nk_bool nk_tree_element_push_hashed(struct nk_context*, enum nk_tree_type, const char *title, enum nk_collapse_states initial_state, nk_bool *selected, const char *hash, int len, int seed); +NK_API nk_bool nk_tree_element_image_push_hashed(struct nk_context*, enum nk_tree_type, struct nk_image, const char *title, enum nk_collapse_states initial_state, nk_bool *selected, const char *hash, int len,int seed); +NK_API void nk_tree_element_pop(struct nk_context*); + +/* ============================================================================= + * + * LIST VIEW + * + * ============================================================================= */ +struct nk_list_view { +/* public: */ + int begin, end, count; +/* private: */ + int total_height; + struct nk_context *ctx; + nk_uint *scroll_pointer; + nk_uint scroll_value; +}; +NK_API nk_bool nk_list_view_begin(struct nk_context*, struct nk_list_view *out, const char *id, nk_flags, int row_height, int row_count); +NK_API void nk_list_view_end(struct nk_list_view*); +/* ============================================================================= + * + * WIDGET + * + * ============================================================================= */ +enum nk_widget_layout_states { + NK_WIDGET_INVALID, /* The widget cannot be seen and is completely out of view */ + NK_WIDGET_VALID, /* The widget is completely inside the window and can be updated and drawn */ + NK_WIDGET_ROM /* The widget is partially visible and cannot be updated */ +}; +enum nk_widget_states { + NK_WIDGET_STATE_MODIFIED = NK_FLAG(1), + NK_WIDGET_STATE_INACTIVE = NK_FLAG(2), /* widget is neither active nor hovered */ + NK_WIDGET_STATE_ENTERED = NK_FLAG(3), /* widget has been hovered on the current frame */ + NK_WIDGET_STATE_HOVER = NK_FLAG(4), /* widget is being hovered */ + NK_WIDGET_STATE_ACTIVED = NK_FLAG(5),/* widget is currently activated */ + NK_WIDGET_STATE_LEFT = NK_FLAG(6), /* widget is from this frame on not hovered anymore */ + NK_WIDGET_STATE_HOVERED = NK_WIDGET_STATE_HOVER|NK_WIDGET_STATE_MODIFIED, /* widget is being hovered */ + NK_WIDGET_STATE_ACTIVE = NK_WIDGET_STATE_ACTIVED|NK_WIDGET_STATE_MODIFIED /* widget is currently activated */ +}; +NK_API enum nk_widget_layout_states nk_widget(struct nk_rect*, const struct nk_context*); +NK_API enum nk_widget_layout_states nk_widget_fitting(struct nk_rect*, struct nk_context*, struct nk_vec2); +NK_API struct nk_rect nk_widget_bounds(struct nk_context*); +NK_API struct nk_vec2 nk_widget_position(struct nk_context*); +NK_API struct nk_vec2 nk_widget_size(struct nk_context*); +NK_API float nk_widget_width(struct nk_context*); +NK_API float nk_widget_height(struct nk_context*); +NK_API nk_bool nk_widget_is_hovered(struct nk_context*); +NK_API nk_bool nk_widget_is_mouse_clicked(struct nk_context*, enum nk_buttons); +NK_API nk_bool nk_widget_has_mouse_click_down(struct nk_context*, enum nk_buttons, nk_bool down); +NK_API void nk_spacing(struct nk_context*, int cols); +/* ============================================================================= + * + * TEXT + * + * ============================================================================= */ +enum nk_text_align { + NK_TEXT_ALIGN_LEFT = 0x01, + NK_TEXT_ALIGN_CENTERED = 0x02, + NK_TEXT_ALIGN_RIGHT = 0x04, + NK_TEXT_ALIGN_TOP = 0x08, + NK_TEXT_ALIGN_MIDDLE = 0x10, + NK_TEXT_ALIGN_BOTTOM = 0x20 +}; +enum nk_text_alignment { + NK_TEXT_LEFT = NK_TEXT_ALIGN_MIDDLE|NK_TEXT_ALIGN_LEFT, + NK_TEXT_CENTERED = NK_TEXT_ALIGN_MIDDLE|NK_TEXT_ALIGN_CENTERED, + NK_TEXT_RIGHT = NK_TEXT_ALIGN_MIDDLE|NK_TEXT_ALIGN_RIGHT +}; +NK_API void nk_text(struct nk_context*, const char*, int, nk_flags); +NK_API void nk_text_colored(struct nk_context*, const char*, int, nk_flags, struct nk_color); +NK_API void nk_text_wrap(struct nk_context*, const char*, int); +NK_API void nk_text_wrap_colored(struct nk_context*, const char*, int, struct nk_color); +NK_API void nk_label(struct nk_context*, const char*, nk_flags align); +NK_API void nk_label_colored(struct nk_context*, const char*, nk_flags align, struct nk_color); +NK_API void nk_label_wrap(struct nk_context*, const char*); +NK_API void nk_label_colored_wrap(struct nk_context*, const char*, struct nk_color); +NK_API void nk_image(struct nk_context*, struct nk_image); +NK_API void nk_image_color(struct nk_context*, struct nk_image, struct nk_color); +#ifdef NK_INCLUDE_STANDARD_VARARGS +NK_API void nk_labelf(struct nk_context*, nk_flags, NK_PRINTF_FORMAT_STRING const char*, ...) NK_PRINTF_VARARG_FUNC(3); +NK_API void nk_labelf_colored(struct nk_context*, nk_flags, struct nk_color, NK_PRINTF_FORMAT_STRING const char*,...) NK_PRINTF_VARARG_FUNC(4); +NK_API void nk_labelf_wrap(struct nk_context*, NK_PRINTF_FORMAT_STRING const char*,...) NK_PRINTF_VARARG_FUNC(2); +NK_API void nk_labelf_colored_wrap(struct nk_context*, struct nk_color, NK_PRINTF_FORMAT_STRING const char*,...) NK_PRINTF_VARARG_FUNC(3); +NK_API void nk_labelfv(struct nk_context*, nk_flags, NK_PRINTF_FORMAT_STRING const char*, va_list) NK_PRINTF_VALIST_FUNC(3); +NK_API void nk_labelfv_colored(struct nk_context*, nk_flags, struct nk_color, NK_PRINTF_FORMAT_STRING const char*, va_list) NK_PRINTF_VALIST_FUNC(4); +NK_API void nk_labelfv_wrap(struct nk_context*, NK_PRINTF_FORMAT_STRING const char*, va_list) NK_PRINTF_VALIST_FUNC(2); +NK_API void nk_labelfv_colored_wrap(struct nk_context*, struct nk_color, NK_PRINTF_FORMAT_STRING const char*, va_list) NK_PRINTF_VALIST_FUNC(3); +NK_API void nk_value_bool(struct nk_context*, const char *prefix, int); +NK_API void nk_value_int(struct nk_context*, const char *prefix, int); +NK_API void nk_value_uint(struct nk_context*, const char *prefix, unsigned int); +NK_API void nk_value_float(struct nk_context*, const char *prefix, float); +NK_API void nk_value_color_byte(struct nk_context*, const char *prefix, struct nk_color); +NK_API void nk_value_color_float(struct nk_context*, const char *prefix, struct nk_color); +NK_API void nk_value_color_hex(struct nk_context*, const char *prefix, struct nk_color); +#endif +/* ============================================================================= + * + * BUTTON + * + * ============================================================================= */ +NK_API nk_bool nk_button_text(struct nk_context*, const char *title, int len); +NK_API nk_bool nk_button_label(struct nk_context*, const char *title); +NK_API nk_bool nk_button_color(struct nk_context*, struct nk_color); +NK_API nk_bool nk_button_symbol(struct nk_context*, enum nk_symbol_type); +NK_API nk_bool nk_button_image(struct nk_context*, struct nk_image img); +NK_API nk_bool nk_button_symbol_label(struct nk_context*, enum nk_symbol_type, const char*, nk_flags text_alignment); +NK_API nk_bool nk_button_symbol_text(struct nk_context*, enum nk_symbol_type, const char*, int, nk_flags alignment); +NK_API nk_bool nk_button_image_label(struct nk_context*, struct nk_image img, const char*, nk_flags text_alignment); +NK_API nk_bool nk_button_image_text(struct nk_context*, struct nk_image img, const char*, int, nk_flags alignment); +NK_API nk_bool nk_button_text_styled(struct nk_context*, const struct nk_style_button*, const char *title, int len); +NK_API nk_bool nk_button_label_styled(struct nk_context*, const struct nk_style_button*, const char *title); +NK_API nk_bool nk_button_symbol_styled(struct nk_context*, const struct nk_style_button*, enum nk_symbol_type); +NK_API nk_bool nk_button_image_styled(struct nk_context*, const struct nk_style_button*, struct nk_image img); +NK_API nk_bool nk_button_symbol_text_styled(struct nk_context*,const struct nk_style_button*, enum nk_symbol_type, const char*, int, nk_flags alignment); +NK_API nk_bool nk_button_symbol_label_styled(struct nk_context *ctx, const struct nk_style_button *style, enum nk_symbol_type symbol, const char *title, nk_flags align); +NK_API nk_bool nk_button_image_label_styled(struct nk_context*,const struct nk_style_button*, struct nk_image img, const char*, nk_flags text_alignment); +NK_API nk_bool nk_button_image_text_styled(struct nk_context*,const struct nk_style_button*, struct nk_image img, const char*, int, nk_flags alignment); +NK_API void nk_button_set_behavior(struct nk_context*, enum nk_button_behavior); +NK_API nk_bool nk_button_push_behavior(struct nk_context*, enum nk_button_behavior); +NK_API nk_bool nk_button_pop_behavior(struct nk_context*); +/* ============================================================================= + * + * CHECKBOX + * + * ============================================================================= */ +NK_API nk_bool nk_check_label(struct nk_context*, const char*, nk_bool active); +NK_API nk_bool nk_check_text(struct nk_context*, const char*, int, nk_bool active); +NK_API unsigned nk_check_flags_label(struct nk_context*, const char*, unsigned int flags, unsigned int value); +NK_API unsigned nk_check_flags_text(struct nk_context*, const char*, int, unsigned int flags, unsigned int value); +NK_API nk_bool nk_checkbox_label(struct nk_context*, const char*, nk_bool *active); +NK_API nk_bool nk_checkbox_text(struct nk_context*, const char*, int, nk_bool *active); +NK_API nk_bool nk_checkbox_flags_label(struct nk_context*, const char*, unsigned int *flags, unsigned int value); +NK_API nk_bool nk_checkbox_flags_text(struct nk_context*, const char*, int, unsigned int *flags, unsigned int value); +/* ============================================================================= + * + * RADIO BUTTON + * + * ============================================================================= */ +NK_API nk_bool nk_radio_label(struct nk_context*, const char*, nk_bool *active); +NK_API nk_bool nk_radio_text(struct nk_context*, const char*, int, nk_bool *active); +NK_API nk_bool nk_option_label(struct nk_context*, const char*, nk_bool active); +NK_API nk_bool nk_option_text(struct nk_context*, const char*, int, nk_bool active); +/* ============================================================================= + * + * SELECTABLE + * + * ============================================================================= */ +NK_API nk_bool nk_selectable_label(struct nk_context*, const char*, nk_flags align, nk_bool *value); +NK_API nk_bool nk_selectable_text(struct nk_context*, const char*, int, nk_flags align, nk_bool *value); +NK_API nk_bool nk_selectable_image_label(struct nk_context*,struct nk_image, const char*, nk_flags align, nk_bool *value); +NK_API nk_bool nk_selectable_image_text(struct nk_context*,struct nk_image, const char*, int, nk_flags align, nk_bool *value); +NK_API nk_bool nk_selectable_symbol_label(struct nk_context*,enum nk_symbol_type, const char*, nk_flags align, nk_bool *value); +NK_API nk_bool nk_selectable_symbol_text(struct nk_context*,enum nk_symbol_type, const char*, int, nk_flags align, nk_bool *value); + +NK_API nk_bool nk_select_label(struct nk_context*, const char*, nk_flags align, nk_bool value); +NK_API nk_bool nk_select_text(struct nk_context*, const char*, int, nk_flags align, nk_bool value); +NK_API nk_bool nk_select_image_label(struct nk_context*, struct nk_image,const char*, nk_flags align, nk_bool value); +NK_API nk_bool nk_select_image_text(struct nk_context*, struct nk_image,const char*, int, nk_flags align, nk_bool value); +NK_API nk_bool nk_select_symbol_label(struct nk_context*,enum nk_symbol_type, const char*, nk_flags align, nk_bool value); +NK_API nk_bool nk_select_symbol_text(struct nk_context*,enum nk_symbol_type, const char*, int, nk_flags align, nk_bool value); + +/* ============================================================================= + * + * SLIDER + * + * ============================================================================= */ +NK_API float nk_slide_float(struct nk_context*, float min, float val, float max, float step); +NK_API int nk_slide_int(struct nk_context*, int min, int val, int max, int step); +NK_API nk_bool nk_slider_float(struct nk_context*, float min, float *val, float max, float step); +NK_API nk_bool nk_slider_int(struct nk_context*, int min, int *val, int max, int step); +/* ============================================================================= + * + * PROGRESSBAR + * + * ============================================================================= */ +NK_API nk_bool nk_progress(struct nk_context*, nk_size *cur, nk_size max, nk_bool modifyable); +NK_API nk_size nk_prog(struct nk_context*, nk_size cur, nk_size max, nk_bool modifyable); + +/* ============================================================================= + * + * COLOR PICKER + * + * ============================================================================= */ +NK_API struct nk_colorf nk_color_picker(struct nk_context*, struct nk_colorf, enum nk_color_format); +NK_API nk_bool nk_color_pick(struct nk_context*, struct nk_colorf*, enum nk_color_format); +/* ============================================================================= + * + * PROPERTIES + * + * ============================================================================= +/// ### Properties +/// Properties are the main value modification widgets in Nuklear. Changing a value +/// can be achieved by dragging, adding/removing incremental steps on button click +/// or by directly typing a number. +/// +/// #### Usage +/// Each property requires a unique name for identification that is also used for +/// displaying a label. If you want to use the same name multiple times make sure +/// add a '#' before your name. The '#' will not be shown but will generate a +/// unique ID. Each property also takes in a minimum and maximum value. If you want +/// to make use of the complete number range of a type just use the provided +/// type limits from `limits.h`. For example `INT_MIN` and `INT_MAX` for +/// `nk_property_int` and `nk_propertyi`. In additional each property takes in +/// a increment value that will be added or subtracted if either the increment +/// decrement button is clicked. Finally there is a value for increment per pixel +/// dragged that is added or subtracted from the value. +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// int value = 0; +/// struct nk_context ctx; +/// nk_init_xxx(&ctx, ...); +/// while (1) { +/// // Input +/// Event evt; +/// nk_input_begin(&ctx); +/// while (GetEvent(&evt)) { +/// if (evt.type == MOUSE_MOVE) +/// nk_input_motion(&ctx, evt.motion.x, evt.motion.y); +/// else if (evt.type == [...]) { +/// nk_input_xxx(...); +/// } +/// } +/// nk_input_end(&ctx); +/// // +/// // Window +/// if (nk_begin_xxx(...) { +/// // Property +/// nk_layout_row_dynamic(...); +/// nk_property_int(ctx, "ID", INT_MIN, &value, INT_MAX, 1, 1); +/// } +/// nk_end(ctx); +/// // +/// // Draw +/// const struct nk_command *cmd = 0; +/// nk_foreach(cmd, &ctx) { +/// switch (cmd->type) { +/// case NK_COMMAND_LINE: +/// your_draw_line_function(...) +/// break; +/// case NK_COMMAND_RECT +/// your_draw_rect_function(...) +/// break; +/// case ...: +/// // [...] +/// } +/// nk_clear(&ctx); +/// } +/// nk_free(&ctx); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// #### Reference +/// Function | Description +/// --------------------|------------------------------------------- +/// nk_property_int | Integer property directly modifying a passed in value +/// nk_property_float | Float property directly modifying a passed in value +/// nk_property_double | Double property directly modifying a passed in value +/// nk_propertyi | Integer property returning the modified int value +/// nk_propertyf | Float property returning the modified float value +/// nk_propertyd | Double property returning the modified double value +/// +*/ +/*/// #### nk_property_int +/// Integer property directly modifying a passed in value +/// !!! WARNING +/// To generate a unique property ID using the same label make sure to insert +/// a `#` at the beginning. It will not be shown but guarantees correct behavior. +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// void nk_property_int(struct nk_context *ctx, const char *name, int min, int *val, int max, int step, float inc_per_pixel); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// --------------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct after calling a layouting function +/// __name__ | String used both as a label as well as a unique identifier +/// __min__ | Minimum value not allowed to be underflown +/// __val__ | Integer pointer to be modified +/// __max__ | Maximum value not allowed to be overflown +/// __step__ | Increment added and subtracted on increment and decrement button +/// __inc_per_pixel__ | Value per pixel added or subtracted on dragging +*/ +NK_API void nk_property_int(struct nk_context*, const char *name, int min, int *val, int max, int step, float inc_per_pixel); +/*/// #### nk_property_float +/// Float property directly modifying a passed in value +/// !!! WARNING +/// To generate a unique property ID using the same label make sure to insert +/// a `#` at the beginning. It will not be shown but guarantees correct behavior. +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// void nk_property_float(struct nk_context *ctx, const char *name, float min, float *val, float max, float step, float inc_per_pixel); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// --------------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct after calling a layouting function +/// __name__ | String used both as a label as well as a unique identifier +/// __min__ | Minimum value not allowed to be underflown +/// __val__ | Float pointer to be modified +/// __max__ | Maximum value not allowed to be overflown +/// __step__ | Increment added and subtracted on increment and decrement button +/// __inc_per_pixel__ | Value per pixel added or subtracted on dragging +*/ +NK_API void nk_property_float(struct nk_context*, const char *name, float min, float *val, float max, float step, float inc_per_pixel); +/*/// #### nk_property_double +/// Double property directly modifying a passed in value +/// !!! WARNING +/// To generate a unique property ID using the same label make sure to insert +/// a `#` at the beginning. It will not be shown but guarantees correct behavior. +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// void nk_property_double(struct nk_context *ctx, const char *name, double min, double *val, double max, double step, double inc_per_pixel); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// --------------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct after calling a layouting function +/// __name__ | String used both as a label as well as a unique identifier +/// __min__ | Minimum value not allowed to be underflown +/// __val__ | Double pointer to be modified +/// __max__ | Maximum value not allowed to be overflown +/// __step__ | Increment added and subtracted on increment and decrement button +/// __inc_per_pixel__ | Value per pixel added or subtracted on dragging +*/ +NK_API void nk_property_double(struct nk_context*, const char *name, double min, double *val, double max, double step, float inc_per_pixel); +/*/// #### nk_propertyi +/// Integer property modifying a passed in value and returning the new value +/// !!! WARNING +/// To generate a unique property ID using the same label make sure to insert +/// a `#` at the beginning. It will not be shown but guarantees correct behavior. +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// int nk_propertyi(struct nk_context *ctx, const char *name, int min, int val, int max, int step, float inc_per_pixel); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// --------------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct after calling a layouting function +/// __name__ | String used both as a label as well as a unique identifier +/// __min__ | Minimum value not allowed to be underflown +/// __val__ | Current integer value to be modified and returned +/// __max__ | Maximum value not allowed to be overflown +/// __step__ | Increment added and subtracted on increment and decrement button +/// __inc_per_pixel__ | Value per pixel added or subtracted on dragging +/// +/// Returns the new modified integer value +*/ +NK_API int nk_propertyi(struct nk_context*, const char *name, int min, int val, int max, int step, float inc_per_pixel); +/*/// #### nk_propertyf +/// Float property modifying a passed in value and returning the new value +/// !!! WARNING +/// To generate a unique property ID using the same label make sure to insert +/// a `#` at the beginning. It will not be shown but guarantees correct behavior. +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// float nk_propertyf(struct nk_context *ctx, const char *name, float min, float val, float max, float step, float inc_per_pixel); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// --------------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct after calling a layouting function +/// __name__ | String used both as a label as well as a unique identifier +/// __min__ | Minimum value not allowed to be underflown +/// __val__ | Current float value to be modified and returned +/// __max__ | Maximum value not allowed to be overflown +/// __step__ | Increment added and subtracted on increment and decrement button +/// __inc_per_pixel__ | Value per pixel added or subtracted on dragging +/// +/// Returns the new modified float value +*/ +NK_API float nk_propertyf(struct nk_context*, const char *name, float min, float val, float max, float step, float inc_per_pixel); +/*/// #### nk_propertyd +/// Float property modifying a passed in value and returning the new value +/// !!! WARNING +/// To generate a unique property ID using the same label make sure to insert +/// a `#` at the beginning. It will not be shown but guarantees correct behavior. +/// +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c +/// float nk_propertyd(struct nk_context *ctx, const char *name, double min, double val, double max, double step, double inc_per_pixel); +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// +/// Parameter | Description +/// --------------------|----------------------------------------------------------- +/// __ctx__ | Must point to an previously initialized `nk_context` struct after calling a layouting function +/// __name__ | String used both as a label as well as a unique identifier +/// __min__ | Minimum value not allowed to be underflown +/// __val__ | Current double value to be modified and returned +/// __max__ | Maximum value not allowed to be overflown +/// __step__ | Increment added and subtracted on increment and decrement button +/// __inc_per_pixel__ | Value per pixel added or subtracted on dragging +/// +/// Returns the new modified double value +*/ +NK_API double nk_propertyd(struct nk_context*, const char *name, double min, double val, double max, double step, float inc_per_pixel); +/* ============================================================================= + * + * TEXT EDIT + * + * ============================================================================= */ +enum nk_edit_flags { + NK_EDIT_DEFAULT = 0, + NK_EDIT_READ_ONLY = NK_FLAG(0), + NK_EDIT_AUTO_SELECT = NK_FLAG(1), + NK_EDIT_SIG_ENTER = NK_FLAG(2), + NK_EDIT_ALLOW_TAB = NK_FLAG(3), + NK_EDIT_NO_CURSOR = NK_FLAG(4), + NK_EDIT_SELECTABLE = NK_FLAG(5), + NK_EDIT_CLIPBOARD = NK_FLAG(6), + NK_EDIT_CTRL_ENTER_NEWLINE = NK_FLAG(7), + NK_EDIT_NO_HORIZONTAL_SCROLL = NK_FLAG(8), + NK_EDIT_ALWAYS_INSERT_MODE = NK_FLAG(9), + NK_EDIT_MULTILINE = NK_FLAG(10), + NK_EDIT_GOTO_END_ON_ACTIVATE = NK_FLAG(11) +}; +enum nk_edit_types { + NK_EDIT_SIMPLE = NK_EDIT_ALWAYS_INSERT_MODE, + NK_EDIT_FIELD = NK_EDIT_SIMPLE|NK_EDIT_SELECTABLE|NK_EDIT_CLIPBOARD, + NK_EDIT_BOX = NK_EDIT_ALWAYS_INSERT_MODE| NK_EDIT_SELECTABLE| NK_EDIT_MULTILINE|NK_EDIT_ALLOW_TAB|NK_EDIT_CLIPBOARD, + NK_EDIT_EDITOR = NK_EDIT_SELECTABLE|NK_EDIT_MULTILINE|NK_EDIT_ALLOW_TAB| NK_EDIT_CLIPBOARD +}; +enum nk_edit_events { + NK_EDIT_ACTIVE = NK_FLAG(0), /* edit widget is currently being modified */ + NK_EDIT_INACTIVE = NK_FLAG(1), /* edit widget is not active and is not being modified */ + NK_EDIT_ACTIVATED = NK_FLAG(2), /* edit widget went from state inactive to state active */ + NK_EDIT_DEACTIVATED = NK_FLAG(3), /* edit widget went from state active to state inactive */ + NK_EDIT_COMMITED = NK_FLAG(4) /* edit widget has received an enter and lost focus */ +}; +NK_API nk_flags nk_edit_string(struct nk_context*, nk_flags, char *buffer, int *len, int max, nk_plugin_filter); +NK_API nk_flags nk_edit_string_zero_terminated(struct nk_context*, nk_flags, char *buffer, int max, nk_plugin_filter); +NK_API nk_flags nk_edit_buffer(struct nk_context*, nk_flags, struct nk_text_edit*, nk_plugin_filter); +NK_API void nk_edit_focus(struct nk_context*, nk_flags flags); +NK_API void nk_edit_unfocus(struct nk_context*); +/* ============================================================================= + * + * CHART + * + * ============================================================================= */ +NK_API nk_bool nk_chart_begin(struct nk_context*, enum nk_chart_type, int num, float min, float max); +NK_API nk_bool nk_chart_begin_colored(struct nk_context*, enum nk_chart_type, struct nk_color, struct nk_color active, int num, float min, float max); +NK_API void nk_chart_add_slot(struct nk_context *ctx, const enum nk_chart_type, int count, float min_value, float max_value); +NK_API void nk_chart_add_slot_colored(struct nk_context *ctx, const enum nk_chart_type, struct nk_color, struct nk_color active, int count, float min_value, float max_value); +NK_API nk_flags nk_chart_push(struct nk_context*, float); +NK_API nk_flags nk_chart_push_slot(struct nk_context*, float, int); +NK_API void nk_chart_end(struct nk_context*); +NK_API void nk_plot(struct nk_context*, enum nk_chart_type, const float *values, int count, int offset); +NK_API void nk_plot_function(struct nk_context*, enum nk_chart_type, void *userdata, float(*value_getter)(void* user, int index), int count, int offset); +/* ============================================================================= + * + * POPUP + * + * ============================================================================= */ +NK_API nk_bool nk_popup_begin(struct nk_context*, enum nk_popup_type, const char*, nk_flags, struct nk_rect bounds); +NK_API void nk_popup_close(struct nk_context*); +NK_API void nk_popup_end(struct nk_context*); +NK_API void nk_popup_get_scroll(struct nk_context*, nk_uint *offset_x, nk_uint *offset_y); +NK_API void nk_popup_set_scroll(struct nk_context*, nk_uint offset_x, nk_uint offset_y); +/* ============================================================================= + * + * COMBOBOX + * + * ============================================================================= */ +NK_API int nk_combo(struct nk_context*, const char **items, int count, int selected, int item_height, struct nk_vec2 size); +NK_API int nk_combo_separator(struct nk_context*, const char *items_separated_by_separator, int separator, int selected, int count, int item_height, struct nk_vec2 size); +NK_API int nk_combo_string(struct nk_context*, const char *items_separated_by_zeros, int selected, int count, int item_height, struct nk_vec2 size); +NK_API int nk_combo_callback(struct nk_context*, void(*item_getter)(void*, int, const char**), void *userdata, int selected, int count, int item_height, struct nk_vec2 size); +NK_API void nk_combobox(struct nk_context*, const char **items, int count, int *selected, int item_height, struct nk_vec2 size); +NK_API void nk_combobox_string(struct nk_context*, const char *items_separated_by_zeros, int *selected, int count, int item_height, struct nk_vec2 size); +NK_API void nk_combobox_separator(struct nk_context*, const char *items_separated_by_separator, int separator, int *selected, int count, int item_height, struct nk_vec2 size); +NK_API void nk_combobox_callback(struct nk_context*, void(*item_getter)(void*, int, const char**), void*, int *selected, int count, int item_height, struct nk_vec2 size); +/* ============================================================================= + * + * ABSTRACT COMBOBOX + * + * ============================================================================= */ +NK_API nk_bool nk_combo_begin_text(struct nk_context*, const char *selected, int, struct nk_vec2 size); +NK_API nk_bool nk_combo_begin_label(struct nk_context*, const char *selected, struct nk_vec2 size); +NK_API nk_bool nk_combo_begin_color(struct nk_context*, struct nk_color color, struct nk_vec2 size); +NK_API nk_bool nk_combo_begin_symbol(struct nk_context*, enum nk_symbol_type, struct nk_vec2 size); +NK_API nk_bool nk_combo_begin_symbol_label(struct nk_context*, const char *selected, enum nk_symbol_type, struct nk_vec2 size); +NK_API nk_bool nk_combo_begin_symbol_text(struct nk_context*, const char *selected, int, enum nk_symbol_type, struct nk_vec2 size); +NK_API nk_bool nk_combo_begin_image(struct nk_context*, struct nk_image img, struct nk_vec2 size); +NK_API nk_bool nk_combo_begin_image_label(struct nk_context*, const char *selected, struct nk_image, struct nk_vec2 size); +NK_API nk_bool nk_combo_begin_image_text(struct nk_context*, const char *selected, int, struct nk_image, struct nk_vec2 size); +NK_API nk_bool nk_combo_item_label(struct nk_context*, const char*, nk_flags alignment); +NK_API nk_bool nk_combo_item_text(struct nk_context*, const char*,int, nk_flags alignment); +NK_API nk_bool nk_combo_item_image_label(struct nk_context*, struct nk_image, const char*, nk_flags alignment); +NK_API nk_bool nk_combo_item_image_text(struct nk_context*, struct nk_image, const char*, int,nk_flags alignment); +NK_API nk_bool nk_combo_item_symbol_label(struct nk_context*, enum nk_symbol_type, const char*, nk_flags alignment); +NK_API nk_bool nk_combo_item_symbol_text(struct nk_context*, enum nk_symbol_type, const char*, int, nk_flags alignment); +NK_API void nk_combo_close(struct nk_context*); +NK_API void nk_combo_end(struct nk_context*); +/* ============================================================================= + * + * CONTEXTUAL + * + * ============================================================================= */ +NK_API nk_bool nk_contextual_begin(struct nk_context*, nk_flags, struct nk_vec2, struct nk_rect trigger_bounds); +NK_API nk_bool nk_contextual_item_text(struct nk_context*, const char*, int,nk_flags align); +NK_API nk_bool nk_contextual_item_label(struct nk_context*, const char*, nk_flags align); +NK_API nk_bool nk_contextual_item_image_label(struct nk_context*, struct nk_image, const char*, nk_flags alignment); +NK_API nk_bool nk_contextual_item_image_text(struct nk_context*, struct nk_image, const char*, int len, nk_flags alignment); +NK_API nk_bool nk_contextual_item_symbol_label(struct nk_context*, enum nk_symbol_type, const char*, nk_flags alignment); +NK_API nk_bool nk_contextual_item_symbol_text(struct nk_context*, enum nk_symbol_type, const char*, int, nk_flags alignment); +NK_API void nk_contextual_close(struct nk_context*); +NK_API void nk_contextual_end(struct nk_context*); +/* ============================================================================= + * + * TOOLTIP + * + * ============================================================================= */ +NK_API void nk_tooltip(struct nk_context*, const char*); +#ifdef NK_INCLUDE_STANDARD_VARARGS +NK_API void nk_tooltipf(struct nk_context*, NK_PRINTF_FORMAT_STRING const char*, ...) NK_PRINTF_VARARG_FUNC(2); +NK_API void nk_tooltipfv(struct nk_context*, NK_PRINTF_FORMAT_STRING const char*, va_list) NK_PRINTF_VALIST_FUNC(2); +#endif +NK_API nk_bool nk_tooltip_begin(struct nk_context*, float width); +NK_API void nk_tooltip_end(struct nk_context*); +/* ============================================================================= + * + * MENU + * + * ============================================================================= */ +NK_API void nk_menubar_begin(struct nk_context*); +NK_API void nk_menubar_end(struct nk_context*); +NK_API nk_bool nk_menu_begin_text(struct nk_context*, const char* title, int title_len, nk_flags align, struct nk_vec2 size); +NK_API nk_bool nk_menu_begin_label(struct nk_context*, const char*, nk_flags align, struct nk_vec2 size); +NK_API nk_bool nk_menu_begin_image(struct nk_context*, const char*, struct nk_image, struct nk_vec2 size); +NK_API nk_bool nk_menu_begin_image_text(struct nk_context*, const char*, int,nk_flags align,struct nk_image, struct nk_vec2 size); +NK_API nk_bool nk_menu_begin_image_label(struct nk_context*, const char*, nk_flags align,struct nk_image, struct nk_vec2 size); +NK_API nk_bool nk_menu_begin_symbol(struct nk_context*, const char*, enum nk_symbol_type, struct nk_vec2 size); +NK_API nk_bool nk_menu_begin_symbol_text(struct nk_context*, const char*, int,nk_flags align,enum nk_symbol_type, struct nk_vec2 size); +NK_API nk_bool nk_menu_begin_symbol_label(struct nk_context*, const char*, nk_flags align,enum nk_symbol_type, struct nk_vec2 size); +NK_API nk_bool nk_menu_item_text(struct nk_context*, const char*, int,nk_flags align); +NK_API nk_bool nk_menu_item_label(struct nk_context*, const char*, nk_flags alignment); +NK_API nk_bool nk_menu_item_image_label(struct nk_context*, struct nk_image, const char*, nk_flags alignment); +NK_API nk_bool nk_menu_item_image_text(struct nk_context*, struct nk_image, const char*, int len, nk_flags alignment); +NK_API nk_bool nk_menu_item_symbol_text(struct nk_context*, enum nk_symbol_type, const char*, int, nk_flags alignment); +NK_API nk_bool nk_menu_item_symbol_label(struct nk_context*, enum nk_symbol_type, const char*, nk_flags alignment); +NK_API void nk_menu_close(struct nk_context*); +NK_API void nk_menu_end(struct nk_context*); +/* ============================================================================= + * + * STYLE + * + * ============================================================================= */ +enum nk_style_colors { + NK_COLOR_TEXT, + NK_COLOR_WINDOW, + NK_COLOR_HEADER, + NK_COLOR_BORDER, + NK_COLOR_BUTTON, + NK_COLOR_BUTTON_HOVER, + NK_COLOR_BUTTON_ACTIVE, + NK_COLOR_TOGGLE, + NK_COLOR_TOGGLE_HOVER, + NK_COLOR_TOGGLE_CURSOR, + NK_COLOR_SELECT, + NK_COLOR_SELECT_ACTIVE, + NK_COLOR_SLIDER, + NK_COLOR_SLIDER_CURSOR, + NK_COLOR_SLIDER_CURSOR_HOVER, + NK_COLOR_SLIDER_CURSOR_ACTIVE, + NK_COLOR_PROPERTY, + NK_COLOR_EDIT, + NK_COLOR_EDIT_CURSOR, + NK_COLOR_COMBO, + NK_COLOR_CHART, + NK_COLOR_CHART_COLOR, + NK_COLOR_CHART_COLOR_HIGHLIGHT, + NK_COLOR_SCROLLBAR, + NK_COLOR_SCROLLBAR_CURSOR, + NK_COLOR_SCROLLBAR_CURSOR_HOVER, + NK_COLOR_SCROLLBAR_CURSOR_ACTIVE, + NK_COLOR_TAB_HEADER, + NK_COLOR_COUNT +}; +enum nk_style_cursor { + NK_CURSOR_ARROW, + NK_CURSOR_TEXT, + NK_CURSOR_MOVE, + NK_CURSOR_RESIZE_VERTICAL, + NK_CURSOR_RESIZE_HORIZONTAL, + NK_CURSOR_RESIZE_TOP_LEFT_DOWN_RIGHT, + NK_CURSOR_RESIZE_TOP_RIGHT_DOWN_LEFT, + NK_CURSOR_COUNT +}; +NK_API void nk_style_default(struct nk_context*); +NK_API void nk_style_from_table(struct nk_context*, const struct nk_color*); +NK_API void nk_style_load_cursor(struct nk_context*, enum nk_style_cursor, const struct nk_cursor*); +NK_API void nk_style_load_all_cursors(struct nk_context*, struct nk_cursor*); +NK_API const char* nk_style_get_color_by_name(enum nk_style_colors); +NK_API void nk_style_set_font(struct nk_context*, const struct nk_user_font*); +NK_API nk_bool nk_style_set_cursor(struct nk_context*, enum nk_style_cursor); +NK_API void nk_style_show_cursor(struct nk_context*); +NK_API void nk_style_hide_cursor(struct nk_context*); + +NK_API nk_bool nk_style_push_font(struct nk_context*, const struct nk_user_font*); +NK_API nk_bool nk_style_push_float(struct nk_context*, float*, float); +NK_API nk_bool nk_style_push_vec2(struct nk_context*, struct nk_vec2*, struct nk_vec2); +NK_API nk_bool nk_style_push_style_item(struct nk_context*, struct nk_style_item*, struct nk_style_item); +NK_API nk_bool nk_style_push_flags(struct nk_context*, nk_flags*, nk_flags); +NK_API nk_bool nk_style_push_color(struct nk_context*, struct nk_color*, struct nk_color); + +NK_API nk_bool nk_style_pop_font(struct nk_context*); +NK_API nk_bool nk_style_pop_float(struct nk_context*); +NK_API nk_bool nk_style_pop_vec2(struct nk_context*); +NK_API nk_bool nk_style_pop_style_item(struct nk_context*); +NK_API nk_bool nk_style_pop_flags(struct nk_context*); +NK_API nk_bool nk_style_pop_color(struct nk_context*); +/* ============================================================================= + * + * COLOR + * + * ============================================================================= */ +NK_API struct nk_color nk_rgb(int r, int g, int b); +NK_API struct nk_color nk_rgb_iv(const int *rgb); +NK_API struct nk_color nk_rgb_bv(const nk_byte* rgb); +NK_API struct nk_color nk_rgb_f(float r, float g, float b); +NK_API struct nk_color nk_rgb_fv(const float *rgb); +NK_API struct nk_color nk_rgb_cf(struct nk_colorf c); +NK_API struct nk_color nk_rgb_hex(const char *rgb); + +NK_API struct nk_color nk_rgba(int r, int g, int b, int a); +NK_API struct nk_color nk_rgba_u32(nk_uint); +NK_API struct nk_color nk_rgba_iv(const int *rgba); +NK_API struct nk_color nk_rgba_bv(const nk_byte *rgba); +NK_API struct nk_color nk_rgba_f(float r, float g, float b, float a); +NK_API struct nk_color nk_rgba_fv(const float *rgba); +NK_API struct nk_color nk_rgba_cf(struct nk_colorf c); +NK_API struct nk_color nk_rgba_hex(const char *rgb); + +NK_API struct nk_colorf nk_hsva_colorf(float h, float s, float v, float a); +NK_API struct nk_colorf nk_hsva_colorfv(float *c); +NK_API void nk_colorf_hsva_f(float *out_h, float *out_s, float *out_v, float *out_a, struct nk_colorf in); +NK_API void nk_colorf_hsva_fv(float *hsva, struct nk_colorf in); + +NK_API struct nk_color nk_hsv(int h, int s, int v); +NK_API struct nk_color nk_hsv_iv(const int *hsv); +NK_API struct nk_color nk_hsv_bv(const nk_byte *hsv); +NK_API struct nk_color nk_hsv_f(float h, float s, float v); +NK_API struct nk_color nk_hsv_fv(const float *hsv); + +NK_API struct nk_color nk_hsva(int h, int s, int v, int a); +NK_API struct nk_color nk_hsva_iv(const int *hsva); +NK_API struct nk_color nk_hsva_bv(const nk_byte *hsva); +NK_API struct nk_color nk_hsva_f(float h, float s, float v, float a); +NK_API struct nk_color nk_hsva_fv(const float *hsva); + +/* color (conversion nuklear --> user) */ +NK_API void nk_color_f(float *r, float *g, float *b, float *a, struct nk_color); +NK_API void nk_color_fv(float *rgba_out, struct nk_color); +NK_API struct nk_colorf nk_color_cf(struct nk_color); +NK_API void nk_color_d(double *r, double *g, double *b, double *a, struct nk_color); +NK_API void nk_color_dv(double *rgba_out, struct nk_color); + +NK_API nk_uint nk_color_u32(struct nk_color); +NK_API void nk_color_hex_rgba(char *output, struct nk_color); +NK_API void nk_color_hex_rgb(char *output, struct nk_color); + +NK_API void nk_color_hsv_i(int *out_h, int *out_s, int *out_v, struct nk_color); +NK_API void nk_color_hsv_b(nk_byte *out_h, nk_byte *out_s, nk_byte *out_v, struct nk_color); +NK_API void nk_color_hsv_iv(int *hsv_out, struct nk_color); +NK_API void nk_color_hsv_bv(nk_byte *hsv_out, struct nk_color); +NK_API void nk_color_hsv_f(float *out_h, float *out_s, float *out_v, struct nk_color); +NK_API void nk_color_hsv_fv(float *hsv_out, struct nk_color); + +NK_API void nk_color_hsva_i(int *h, int *s, int *v, int *a, struct nk_color); +NK_API void nk_color_hsva_b(nk_byte *h, nk_byte *s, nk_byte *v, nk_byte *a, struct nk_color); +NK_API void nk_color_hsva_iv(int *hsva_out, struct nk_color); +NK_API void nk_color_hsva_bv(nk_byte *hsva_out, struct nk_color); +NK_API void nk_color_hsva_f(float *out_h, float *out_s, float *out_v, float *out_a, struct nk_color); +NK_API void nk_color_hsva_fv(float *hsva_out, struct nk_color); +/* ============================================================================= + * + * IMAGE + * + * ============================================================================= */ +NK_API nk_handle nk_handle_ptr(void*); +NK_API nk_handle nk_handle_id(int); +NK_API struct nk_image nk_image_handle(nk_handle); +NK_API struct nk_image nk_image_ptr(void*); +NK_API struct nk_image nk_image_id(int); +NK_API nk_bool nk_image_is_subimage(const struct nk_image* img); +NK_API struct nk_image nk_subimage_ptr(void*, nk_ushort w, nk_ushort h, struct nk_rect sub_region); +NK_API struct nk_image nk_subimage_id(int, nk_ushort w, nk_ushort h, struct nk_rect sub_region); +NK_API struct nk_image nk_subimage_handle(nk_handle, nk_ushort w, nk_ushort h, struct nk_rect sub_region); +/* ============================================================================= + * + * 9-SLICE + * + * ============================================================================= */ +NK_API struct nk_nine_slice nk_nine_slice_handle(nk_handle, nk_ushort l, nk_ushort t, nk_ushort r, nk_ushort b); +NK_API struct nk_nine_slice nk_nine_slice_ptr(void*, nk_ushort l, nk_ushort t, nk_ushort r, nk_ushort b); +NK_API struct nk_nine_slice nk_nine_slice_id(int, nk_ushort l, nk_ushort t, nk_ushort r, nk_ushort b); +NK_API int nk_nine_slice_is_sub9slice(const struct nk_nine_slice* img); +NK_API struct nk_nine_slice nk_sub9slice_ptr(void*, nk_ushort w, nk_ushort h, struct nk_rect sub_region, nk_ushort l, nk_ushort t, nk_ushort r, nk_ushort b); +NK_API struct nk_nine_slice nk_sub9slice_id(int, nk_ushort w, nk_ushort h, struct nk_rect sub_region, nk_ushort l, nk_ushort t, nk_ushort r, nk_ushort b); +NK_API struct nk_nine_slice nk_sub9slice_handle(nk_handle, nk_ushort w, nk_ushort h, struct nk_rect sub_region, nk_ushort l, nk_ushort t, nk_ushort r, nk_ushort b); +/* ============================================================================= + * + * MATH + * + * ============================================================================= */ +NK_API nk_hash nk_murmur_hash(const void *key, int len, nk_hash seed); +NK_API void nk_triangle_from_direction(struct nk_vec2 *result, struct nk_rect r, float pad_x, float pad_y, enum nk_heading); + +NK_API struct nk_vec2 nk_vec2(float x, float y); +NK_API struct nk_vec2 nk_vec2i(int x, int y); +NK_API struct nk_vec2 nk_vec2v(const float *xy); +NK_API struct nk_vec2 nk_vec2iv(const int *xy); + +NK_API struct nk_rect nk_get_null_rect(void); +NK_API struct nk_rect nk_rect(float x, float y, float w, float h); +NK_API struct nk_rect nk_recti(int x, int y, int w, int h); +NK_API struct nk_rect nk_recta(struct nk_vec2 pos, struct nk_vec2 size); +NK_API struct nk_rect nk_rectv(const float *xywh); +NK_API struct nk_rect nk_rectiv(const int *xywh); +NK_API struct nk_vec2 nk_rect_pos(struct nk_rect); +NK_API struct nk_vec2 nk_rect_size(struct nk_rect); +/* ============================================================================= + * + * STRING + * + * ============================================================================= */ +NK_API int nk_strlen(const char *str); +NK_API int nk_stricmp(const char *s1, const char *s2); +NK_API int nk_stricmpn(const char *s1, const char *s2, int n); +NK_API int nk_strtoi(const char *str, const char **endptr); +NK_API float nk_strtof(const char *str, const char **endptr); +#ifndef NK_STRTOD +#define NK_STRTOD nk_strtod +NK_API double nk_strtod(const char *str, const char **endptr); +#endif +NK_API int nk_strfilter(const char *text, const char *regexp); +NK_API int nk_strmatch_fuzzy_string(char const *str, char const *pattern, int *out_score); +NK_API int nk_strmatch_fuzzy_text(const char *txt, int txt_len, const char *pattern, int *out_score); +/* ============================================================================= + * + * UTF-8 + * + * ============================================================================= */ +NK_API int nk_utf_decode(const char*, nk_rune*, int); +NK_API int nk_utf_encode(nk_rune, char*, int); +NK_API int nk_utf_len(const char*, int byte_len); +NK_API const char* nk_utf_at(const char *buffer, int length, int index, nk_rune *unicode, int *len); +/* =============================================================== + * + * FONT + * + * ===============================================================*/ +/*/// ### Font +/// Font handling in this library was designed to be quite customizable and lets +/// you decide what you want to use and what you want to provide. There are three +/// different ways to use the font atlas. The first two will use your font +/// handling scheme and only requires essential data to run nuklear. The next +/// slightly more advanced features is font handling with vertex buffer output. +/// Finally the most complex API wise is using nuklear's font baking API. +// +/// #### Using your own implementation without vertex buffer output +/// +/// So first up the easiest way to do font handling is by just providing a +/// `nk_user_font` struct which only requires the height in pixel of the used +/// font and a callback to calculate the width of a string. This way of handling +/// fonts is best fitted for using the normal draw shape command API where you +/// do all the text drawing yourself and the library does not require any kind +/// of deeper knowledge about which font handling mechanism you use. +/// IMPORTANT: the `nk_user_font` pointer provided to nuklear has to persist +/// over the complete life time! I know this sucks but it is currently the only +/// way to switch between fonts. +/// +/// ```c +/// float your_text_width_calculation(nk_handle handle, float height, const char *text, int len) +/// { +/// your_font_type *type = handle.ptr; +/// float text_width = ...; +/// return text_width; +/// } +/// +/// struct nk_user_font font; +/// font.userdata.ptr = &your_font_class_or_struct; +/// font.height = your_font_height; +/// font.width = your_text_width_calculation; +/// +/// struct nk_context ctx; +/// nk_init_default(&ctx, &font); +/// ``` +/// #### Using your own implementation with vertex buffer output +/// +/// While the first approach works fine if you don't want to use the optional +/// vertex buffer output it is not enough if you do. To get font handling working +/// for these cases you have to provide two additional parameters inside the +/// `nk_user_font`. First a texture atlas handle used to draw text as subimages +/// of a bigger font atlas texture and a callback to query a character's glyph +/// information (offset, size, ...). So it is still possible to provide your own +/// font and use the vertex buffer output. +/// +/// ```c +/// float your_text_width_calculation(nk_handle handle, float height, const char *text, int len) +/// { +/// your_font_type *type = handle.ptr; +/// float text_width = ...; +/// return text_width; +/// } +/// void query_your_font_glyph(nk_handle handle, float font_height, struct nk_user_font_glyph *glyph, nk_rune codepoint, nk_rune next_codepoint) +/// { +/// your_font_type *type = handle.ptr; +/// glyph.width = ...; +/// glyph.height = ...; +/// glyph.xadvance = ...; +/// glyph.uv[0].x = ...; +/// glyph.uv[0].y = ...; +/// glyph.uv[1].x = ...; +/// glyph.uv[1].y = ...; +/// glyph.offset.x = ...; +/// glyph.offset.y = ...; +/// } +/// +/// struct nk_user_font font; +/// font.userdata.ptr = &your_font_class_or_struct; +/// font.height = your_font_height; +/// font.width = your_text_width_calculation; +/// font.query = query_your_font_glyph; +/// font.texture.id = your_font_texture; +/// +/// struct nk_context ctx; +/// nk_init_default(&ctx, &font); +/// ``` +/// +/// #### Nuklear font baker +/// +/// The final approach if you do not have a font handling functionality or don't +/// want to use it in this library is by using the optional font baker. +/// The font baker APIs can be used to create a font plus font atlas texture +/// and can be used with or without the vertex buffer output. +/// +/// It still uses the `nk_user_font` struct and the two different approaches +/// previously stated still work. The font baker is not located inside +/// `nk_context` like all other systems since it can be understood as more of +/// an extension to nuklear and does not really depend on any `nk_context` state. +/// +/// Font baker need to be initialized first by one of the nk_font_atlas_init_xxx +/// functions. If you don't care about memory just call the default version +/// `nk_font_atlas_init_default` which will allocate all memory from the standard library. +/// If you want to control memory allocation but you don't care if the allocated +/// memory is temporary and therefore can be freed directly after the baking process +/// is over or permanent you can call `nk_font_atlas_init`. +/// +/// After successfully initializing the font baker you can add Truetype(.ttf) fonts from +/// different sources like memory or from file by calling one of the `nk_font_atlas_add_xxx`. +/// functions. Adding font will permanently store each font, font config and ttf memory block(!) +/// inside the font atlas and allows to reuse the font atlas. If you don't want to reuse +/// the font baker by for example adding additional fonts you can call +/// `nk_font_atlas_cleanup` after the baking process is over (after calling nk_font_atlas_end). +/// +/// As soon as you added all fonts you wanted you can now start the baking process +/// for every selected glyph to image by calling `nk_font_atlas_bake`. +/// The baking process returns image memory, width and height which can be used to +/// either create your own image object or upload it to any graphics library. +/// No matter which case you finally have to call `nk_font_atlas_end` which +/// will free all temporary memory including the font atlas image so make sure +/// you created our texture beforehand. `nk_font_atlas_end` requires a handle +/// to your font texture or object and optionally fills a `struct nk_draw_null_texture` +/// which can be used for the optional vertex output. If you don't want it just +/// set the argument to `NULL`. +/// +/// At this point you are done and if you don't want to reuse the font atlas you +/// can call `nk_font_atlas_cleanup` to free all truetype blobs and configuration +/// memory. Finally if you don't use the font atlas and any of it's fonts anymore +/// you need to call `nk_font_atlas_clear` to free all memory still being used. +/// +/// ```c +/// struct nk_font_atlas atlas; +/// nk_font_atlas_init_default(&atlas); +/// nk_font_atlas_begin(&atlas); +/// nk_font *font = nk_font_atlas_add_from_file(&atlas, "Path/To/Your/TTF_Font.ttf", 13, 0); +/// nk_font *font2 = nk_font_atlas_add_from_file(&atlas, "Path/To/Your/TTF_Font2.ttf", 16, 0); +/// const void* img = nk_font_atlas_bake(&atlas, &img_width, &img_height, NK_FONT_ATLAS_RGBA32); +/// nk_font_atlas_end(&atlas, nk_handle_id(texture), 0); +/// +/// struct nk_context ctx; +/// nk_init_default(&ctx, &font->handle); +/// while (1) { +/// +/// } +/// nk_font_atlas_clear(&atlas); +/// ``` +/// The font baker API is probably the most complex API inside this library and +/// I would suggest reading some of my examples `example/` to get a grip on how +/// to use the font atlas. There are a number of details I left out. For example +/// how to merge fonts, configure a font with `nk_font_config` to use other languages, +/// use another texture coordinate format and a lot more: +/// +/// ```c +/// struct nk_font_config cfg = nk_font_config(font_pixel_height); +/// cfg.merge_mode = nk_false or nk_true; +/// cfg.range = nk_font_korean_glyph_ranges(); +/// cfg.coord_type = NK_COORD_PIXEL; +/// nk_font *font = nk_font_atlas_add_from_file(&atlas, "Path/To/Your/TTF_Font.ttf", 13, &cfg); +/// ``` +*/ +struct nk_user_font_glyph; +typedef float(*nk_text_width_f)(nk_handle, float h, const char*, int len); +typedef void(*nk_query_font_glyph_f)(nk_handle handle, float font_height, + struct nk_user_font_glyph *glyph, + nk_rune codepoint, nk_rune next_codepoint); + +#if defined(NK_INCLUDE_VERTEX_BUFFER_OUTPUT) || defined(NK_INCLUDE_SOFTWARE_FONT) +struct nk_user_font_glyph { + struct nk_vec2 uv[2]; + /* texture coordinates */ + struct nk_vec2 offset; + /* offset between top left and glyph */ + float width, height; + /* size of the glyph */ + float xadvance; + /* offset to the next glyph */ +}; +#endif + +struct nk_user_font { + nk_handle userdata; + /* user provided font handle */ + float height; + /* max height of the font */ + nk_text_width_f width; + /* font string width in pixel callback */ +#ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT + nk_query_font_glyph_f query; + /* font glyph callback to query drawing info */ + nk_handle texture; + /* texture handle to the used font atlas or texture */ +#endif +}; + +#ifdef NK_INCLUDE_FONT_BAKING +enum nk_font_coord_type { + NK_COORD_UV, /* texture coordinates inside font glyphs are clamped between 0-1 */ + NK_COORD_PIXEL /* texture coordinates inside font glyphs are in absolute pixel */ +}; + +struct nk_font; +struct nk_baked_font { + float height; + /* height of the font */ + float ascent, descent; + /* font glyphs ascent and descent */ + nk_rune glyph_offset; + /* glyph array offset inside the font glyph baking output array */ + nk_rune glyph_count; + /* number of glyphs of this font inside the glyph baking array output */ + const nk_rune *ranges; + /* font codepoint ranges as pairs of (from/to) and 0 as last element */ +}; + +struct nk_font_config { + struct nk_font_config *next; + /* NOTE: only used internally */ + void *ttf_blob; + /* pointer to loaded TTF file memory block. + * NOTE: not needed for nk_font_atlas_add_from_memory and nk_font_atlas_add_from_file. */ + nk_size ttf_size; + /* size of the loaded TTF file memory block + * NOTE: not needed for nk_font_atlas_add_from_memory and nk_font_atlas_add_from_file. */ + + unsigned char ttf_data_owned_by_atlas; + /* used inside font atlas: default to: 0*/ + unsigned char merge_mode; + /* merges this font into the last font */ + unsigned char pixel_snap; + /* align every character to pixel boundary (if true set oversample (1,1)) */ + unsigned char oversample_v, oversample_h; + /* rasterize at high quality for sub-pixel position */ + unsigned char padding[3]; + + float size; + /* baked pixel height of the font */ + enum nk_font_coord_type coord_type; + /* texture coordinate format with either pixel or UV coordinates */ + struct nk_vec2 spacing; + /* extra pixel spacing between glyphs */ + const nk_rune *range; + /* list of unicode ranges (2 values per range, zero terminated) */ + struct nk_baked_font *font; + /* font to setup in the baking process: NOTE: not needed for font atlas */ + nk_rune fallback_glyph; + /* fallback glyph to use if a given rune is not found */ + struct nk_font_config *n; + struct nk_font_config *p; +}; + +struct nk_font_glyph { + nk_rune codepoint; + float xadvance; + float x0, y0, x1, y1, w, h; + float u0, v0, u1, v1; +}; + +struct nk_font { + struct nk_font *next; + struct nk_user_font handle; + struct nk_baked_font info; + float scale; + struct nk_font_glyph *glyphs; + const struct nk_font_glyph *fallback; + nk_rune fallback_codepoint; + nk_handle texture; + struct nk_font_config *config; +}; + +enum nk_font_atlas_format { + NK_FONT_ATLAS_ALPHA8, + NK_FONT_ATLAS_RGBA32 +}; + +struct nk_font_atlas { + void *pixel; + int tex_width; + int tex_height; + + struct nk_allocator permanent; + struct nk_allocator temporary; + + struct nk_recti custom; + struct nk_cursor cursors[NK_CURSOR_COUNT]; + + int glyph_count; + struct nk_font_glyph *glyphs; + struct nk_font *default_font; + struct nk_font *fonts; + struct nk_font_config *config; + int font_num; +}; + +/* some language glyph codepoint ranges */ +NK_API const nk_rune *nk_font_default_glyph_ranges(void); +NK_API const nk_rune *nk_font_chinese_glyph_ranges(void); +NK_API const nk_rune *nk_font_cyrillic_glyph_ranges(void); +NK_API const nk_rune *nk_font_korean_glyph_ranges(void); + +#ifdef NK_INCLUDE_DEFAULT_ALLOCATOR +NK_API void nk_font_atlas_init_default(struct nk_font_atlas*); +#endif +NK_API void nk_font_atlas_init(struct nk_font_atlas*, struct nk_allocator*); +NK_API void nk_font_atlas_init_custom(struct nk_font_atlas*, struct nk_allocator *persistent, struct nk_allocator *transient); +NK_API void nk_font_atlas_begin(struct nk_font_atlas*); +NK_API struct nk_font_config nk_font_config(float pixel_height); +NK_API struct nk_font *nk_font_atlas_add(struct nk_font_atlas*, const struct nk_font_config*); +#ifdef NK_INCLUDE_DEFAULT_FONT +NK_API struct nk_font* nk_font_atlas_add_default(struct nk_font_atlas*, float height, const struct nk_font_config*); +#endif +NK_API struct nk_font* nk_font_atlas_add_from_memory(struct nk_font_atlas *atlas, void *memory, nk_size size, float height, const struct nk_font_config *config); +#ifdef NK_INCLUDE_STANDARD_IO +NK_API struct nk_font* nk_font_atlas_add_from_file(struct nk_font_atlas *atlas, const char *file_path, float height, const struct nk_font_config*); +#endif +NK_API struct nk_font *nk_font_atlas_add_compressed(struct nk_font_atlas*, void *memory, nk_size size, float height, const struct nk_font_config*); +NK_API struct nk_font* nk_font_atlas_add_compressed_base85(struct nk_font_atlas*, const char *data, float height, const struct nk_font_config *config); +NK_API const void* nk_font_atlas_bake(struct nk_font_atlas*, int *width, int *height, enum nk_font_atlas_format); +NK_API void nk_font_atlas_end(struct nk_font_atlas*, nk_handle tex, struct nk_draw_null_texture*); +NK_API const struct nk_font_glyph* nk_font_find_glyph(struct nk_font*, nk_rune unicode); +NK_API void nk_font_atlas_cleanup(struct nk_font_atlas *atlas); +NK_API void nk_font_atlas_clear(struct nk_font_atlas*); + +#endif + +/* ============================================================== + * + * MEMORY BUFFER + * + * ===============================================================*/ +/*/// ### Memory Buffer +/// A basic (double)-buffer with linear allocation and resetting as only +/// freeing policy. The buffer's main purpose is to control all memory management +/// inside the GUI toolkit and still leave memory control as much as possible in +/// the hand of the user while also making sure the library is easy to use if +/// not as much control is needed. +/// In general all memory inside this library can be provided from the user in +/// three different ways. +/// +/// The first way and the one providing most control is by just passing a fixed +/// size memory block. In this case all control lies in the hand of the user +/// since he can exactly control where the memory comes from and how much memory +/// the library should consume. Of course using the fixed size API removes the +/// ability to automatically resize a buffer if not enough memory is provided so +/// you have to take over the resizing. While being a fixed sized buffer sounds +/// quite limiting, it is very effective in this library since the actual memory +/// consumption is quite stable and has a fixed upper bound for a lot of cases. +/// +/// If you don't want to think about how much memory the library should allocate +/// at all time or have a very dynamic UI with unpredictable memory consumption +/// habits but still want control over memory allocation you can use the dynamic +/// allocator based API. The allocator consists of two callbacks for allocating +/// and freeing memory and optional userdata so you can plugin your own allocator. +/// +/// The final and easiest way can be used by defining +/// NK_INCLUDE_DEFAULT_ALLOCATOR which uses the standard library memory +/// allocation functions malloc and free and takes over complete control over +/// memory in this library. +*/ +struct nk_memory_status { + void *memory; + unsigned int type; + nk_size size; + nk_size allocated; + nk_size needed; + nk_size calls; +}; + +enum nk_allocation_type { + NK_BUFFER_FIXED, + NK_BUFFER_DYNAMIC +}; + +enum nk_buffer_allocation_type { + NK_BUFFER_FRONT, + NK_BUFFER_BACK, + NK_BUFFER_MAX +}; + +struct nk_buffer_marker { + nk_bool active; + nk_size offset; +}; + +struct nk_memory {void *ptr;nk_size size;}; +struct nk_buffer { + struct nk_buffer_marker marker[NK_BUFFER_MAX]; + /* buffer marker to free a buffer to a certain offset */ + struct nk_allocator pool; + /* allocator callback for dynamic buffers */ + enum nk_allocation_type type; + /* memory management type */ + struct nk_memory memory; + /* memory and size of the current memory block */ + float grow_factor; + /* growing factor for dynamic memory management */ + nk_size allocated; + /* total amount of memory allocated */ + nk_size needed; + /* totally consumed memory given that enough memory is present */ + nk_size calls; + /* number of allocation calls */ + nk_size size; + /* current size of the buffer */ +}; + +#ifdef NK_INCLUDE_DEFAULT_ALLOCATOR +NK_API void nk_buffer_init_default(struct nk_buffer*); +#endif +NK_API void nk_buffer_init(struct nk_buffer*, const struct nk_allocator*, nk_size size); +NK_API void nk_buffer_init_fixed(struct nk_buffer*, void *memory, nk_size size); +NK_API void nk_buffer_info(struct nk_memory_status*, struct nk_buffer*); +NK_API void nk_buffer_push(struct nk_buffer*, enum nk_buffer_allocation_type type, const void *memory, nk_size size, nk_size align); +NK_API void nk_buffer_mark(struct nk_buffer*, enum nk_buffer_allocation_type type); +NK_API void nk_buffer_reset(struct nk_buffer*, enum nk_buffer_allocation_type type); +NK_API void nk_buffer_clear(struct nk_buffer*); +NK_API void nk_buffer_free(struct nk_buffer*); +NK_API void *nk_buffer_memory(struct nk_buffer*); +NK_API const void *nk_buffer_memory_const(const struct nk_buffer*); +NK_API nk_size nk_buffer_total(struct nk_buffer*); + +/* ============================================================== + * + * STRING + * + * ===============================================================*/ +/* Basic string buffer which is only used in context with the text editor + * to manage and manipulate dynamic or fixed size string content. This is _NOT_ + * the default string handling method. The only instance you should have any contact + * with this API is if you interact with an `nk_text_edit` object inside one of the + * copy and paste functions and even there only for more advanced cases. */ +struct nk_str { + struct nk_buffer buffer; + int len; /* in codepoints/runes/glyphs */ +}; + +#ifdef NK_INCLUDE_DEFAULT_ALLOCATOR +NK_API void nk_str_init_default(struct nk_str*); +#endif +NK_API void nk_str_init(struct nk_str*, const struct nk_allocator*, nk_size size); +NK_API void nk_str_init_fixed(struct nk_str*, void *memory, nk_size size); +NK_API void nk_str_clear(struct nk_str*); +NK_API void nk_str_free(struct nk_str*); + +NK_API int nk_str_append_text_char(struct nk_str*, const char*, int); +NK_API int nk_str_append_str_char(struct nk_str*, const char*); +NK_API int nk_str_append_text_utf8(struct nk_str*, const char*, int); +NK_API int nk_str_append_str_utf8(struct nk_str*, const char*); +NK_API int nk_str_append_text_runes(struct nk_str*, const nk_rune*, int); +NK_API int nk_str_append_str_runes(struct nk_str*, const nk_rune*); + +NK_API int nk_str_insert_at_char(struct nk_str*, int pos, const char*, int); +NK_API int nk_str_insert_at_rune(struct nk_str*, int pos, const char*, int); + +NK_API int nk_str_insert_text_char(struct nk_str*, int pos, const char*, int); +NK_API int nk_str_insert_str_char(struct nk_str*, int pos, const char*); +NK_API int nk_str_insert_text_utf8(struct nk_str*, int pos, const char*, int); +NK_API int nk_str_insert_str_utf8(struct nk_str*, int pos, const char*); +NK_API int nk_str_insert_text_runes(struct nk_str*, int pos, const nk_rune*, int); +NK_API int nk_str_insert_str_runes(struct nk_str*, int pos, const nk_rune*); + +NK_API void nk_str_remove_chars(struct nk_str*, int len); +NK_API void nk_str_remove_runes(struct nk_str *str, int len); +NK_API void nk_str_delete_chars(struct nk_str*, int pos, int len); +NK_API void nk_str_delete_runes(struct nk_str*, int pos, int len); + +NK_API char *nk_str_at_char(struct nk_str*, int pos); +NK_API char *nk_str_at_rune(struct nk_str*, int pos, nk_rune *unicode, int *len); +NK_API nk_rune nk_str_rune_at(const struct nk_str*, int pos); +NK_API const char *nk_str_at_char_const(const struct nk_str*, int pos); +NK_API const char *nk_str_at_const(const struct nk_str*, int pos, nk_rune *unicode, int *len); + +NK_API char *nk_str_get(struct nk_str*); +NK_API const char *nk_str_get_const(const struct nk_str*); +NK_API int nk_str_len(struct nk_str*); +NK_API int nk_str_len_char(struct nk_str*); + +/*=============================================================== + * + * TEXT EDITOR + * + * ===============================================================*/ +/*/// ### Text Editor +/// Editing text in this library is handled by either `nk_edit_string` or +/// `nk_edit_buffer`. But like almost everything in this library there are multiple +/// ways of doing it and a balance between control and ease of use with memory +/// as well as functionality controlled by flags. +/// +/// This library generally allows three different levels of memory control: +/// First of is the most basic way of just providing a simple char array with +/// string length. This method is probably the easiest way of handling simple +/// user text input. Main upside is complete control over memory while the biggest +/// downside in comparison with the other two approaches is missing undo/redo. +/// +/// For UIs that require undo/redo the second way was created. It is based on +/// a fixed size nk_text_edit struct, which has an internal undo/redo stack. +/// This is mainly useful if you want something more like a text editor but don't want +/// to have a dynamically growing buffer. +/// +/// The final way is using a dynamically growing nk_text_edit struct, which +/// has both a default version if you don't care where memory comes from and an +/// allocator version if you do. While the text editor is quite powerful for its +/// complexity I would not recommend editing gigabytes of data with it. +/// It is rather designed for uses cases which make sense for a GUI library not for +/// an full blown text editor. + */ +#ifndef NK_TEXTEDIT_UNDOSTATECOUNT +#define NK_TEXTEDIT_UNDOSTATECOUNT 99 +#endif + +#ifndef NK_TEXTEDIT_UNDOCHARCOUNT +#define NK_TEXTEDIT_UNDOCHARCOUNT 999 +#endif + +struct nk_text_edit; +struct nk_clipboard { + nk_handle userdata; + nk_plugin_paste paste; + nk_plugin_copy copy; +}; + +struct nk_text_undo_record { + int where; + short insert_length; + short delete_length; + short char_storage; +}; + +struct nk_text_undo_state { + struct nk_text_undo_record undo_rec[NK_TEXTEDIT_UNDOSTATECOUNT]; + nk_rune undo_char[NK_TEXTEDIT_UNDOCHARCOUNT]; + short undo_point; + short redo_point; + short undo_char_point; + short redo_char_point; +}; + +enum nk_text_edit_type { + NK_TEXT_EDIT_SINGLE_LINE, + NK_TEXT_EDIT_MULTI_LINE +}; + +enum nk_text_edit_mode { + NK_TEXT_EDIT_MODE_VIEW, + NK_TEXT_EDIT_MODE_INSERT, + NK_TEXT_EDIT_MODE_REPLACE +}; + +struct nk_text_edit { + struct nk_clipboard clip; + struct nk_str string; + nk_plugin_filter filter; + struct nk_vec2 scrollbar; + + int cursor; + int select_start; + int select_end; + unsigned char mode; + unsigned char cursor_at_end_of_line; + unsigned char initialized; + unsigned char has_preferred_x; + unsigned char single_line; + unsigned char active; + unsigned char padding1; + float preferred_x; + struct nk_text_undo_state undo; +}; + +/* filter function */ +NK_API nk_bool nk_filter_default(const struct nk_text_edit*, nk_rune unicode); +NK_API nk_bool nk_filter_ascii(const struct nk_text_edit*, nk_rune unicode); +NK_API nk_bool nk_filter_float(const struct nk_text_edit*, nk_rune unicode); +NK_API nk_bool nk_filter_decimal(const struct nk_text_edit*, nk_rune unicode); +NK_API nk_bool nk_filter_hex(const struct nk_text_edit*, nk_rune unicode); +NK_API nk_bool nk_filter_oct(const struct nk_text_edit*, nk_rune unicode); +NK_API nk_bool nk_filter_binary(const struct nk_text_edit*, nk_rune unicode); + +/* text editor */ +#ifdef NK_INCLUDE_DEFAULT_ALLOCATOR +NK_API void nk_textedit_init_default(struct nk_text_edit*); +#endif +NK_API void nk_textedit_init(struct nk_text_edit*, struct nk_allocator*, nk_size size); +NK_API void nk_textedit_init_fixed(struct nk_text_edit*, void *memory, nk_size size); +NK_API void nk_textedit_free(struct nk_text_edit*); +NK_API void nk_textedit_text(struct nk_text_edit*, const char*, int total_len); +NK_API void nk_textedit_delete(struct nk_text_edit*, int where, int len); +NK_API void nk_textedit_delete_selection(struct nk_text_edit*); +NK_API void nk_textedit_select_all(struct nk_text_edit*); +NK_API nk_bool nk_textedit_cut(struct nk_text_edit*); +NK_API nk_bool nk_textedit_paste(struct nk_text_edit*, char const*, int len); +NK_API void nk_textedit_undo(struct nk_text_edit*); +NK_API void nk_textedit_redo(struct nk_text_edit*); + +/* =============================================================== + * + * DRAWING + * + * ===============================================================*/ +/*/// ### Drawing +/// This library was designed to be render backend agnostic so it does +/// not draw anything to screen. Instead all drawn shapes, widgets +/// are made of, are buffered into memory and make up a command queue. +/// Each frame therefore fills the command buffer with draw commands +/// that then need to be executed by the user and his own render backend. +/// After that the command buffer needs to be cleared and a new frame can be +/// started. It is probably important to note that the command buffer is the main +/// drawing API and the optional vertex buffer API only takes this format and +/// converts it into a hardware accessible format. +/// +/// To use the command queue to draw your own widgets you can access the +/// command buffer of each window by calling `nk_window_get_canvas` after +/// previously having called `nk_begin`: +/// +/// ```c +/// void draw_red_rectangle_widget(struct nk_context *ctx) +/// { +/// struct nk_command_buffer *canvas; +/// struct nk_input *input = &ctx->input; +/// canvas = nk_window_get_canvas(ctx); +/// +/// struct nk_rect space; +/// enum nk_widget_layout_states state; +/// state = nk_widget(&space, ctx); +/// if (!state) return; +/// +/// if (state != NK_WIDGET_ROM) +/// update_your_widget_by_user_input(...); +/// nk_fill_rect(canvas, space, 0, nk_rgb(255,0,0)); +/// } +/// +/// if (nk_begin(...)) { +/// nk_layout_row_dynamic(ctx, 25, 1); +/// draw_red_rectangle_widget(ctx); +/// } +/// nk_end(..) +/// +/// ``` +/// Important to know if you want to create your own widgets is the `nk_widget` +/// call. It allocates space on the panel reserved for this widget to be used, +/// but also returns the state of the widget space. If your widget is not seen and does +/// not have to be updated it is '0' and you can just return. If it only has +/// to be drawn the state will be `NK_WIDGET_ROM` otherwise you can do both +/// update and draw your widget. The reason for separating is to only draw and +/// update what is actually necessary which is crucial for performance. +*/ +enum nk_command_type { + NK_COMMAND_NOP, + NK_COMMAND_SCISSOR, + NK_COMMAND_LINE, + NK_COMMAND_CURVE, + NK_COMMAND_RECT, + NK_COMMAND_RECT_FILLED, + NK_COMMAND_RECT_MULTI_COLOR, + NK_COMMAND_CIRCLE, + NK_COMMAND_CIRCLE_FILLED, + NK_COMMAND_ARC, + NK_COMMAND_ARC_FILLED, + NK_COMMAND_TRIANGLE, + NK_COMMAND_TRIANGLE_FILLED, + NK_COMMAND_POLYGON, + NK_COMMAND_POLYGON_FILLED, + NK_COMMAND_POLYLINE, + NK_COMMAND_TEXT, + NK_COMMAND_IMAGE, + NK_COMMAND_CUSTOM +}; + +/* command base and header of every command inside the buffer */ +struct nk_command { + enum nk_command_type type; + nk_size next; +#ifdef NK_INCLUDE_COMMAND_USERDATA + nk_handle userdata; +#endif +}; + +struct nk_command_scissor { + struct nk_command header; + short x, y; + unsigned short w, h; +}; + +struct nk_command_line { + struct nk_command header; + unsigned short line_thickness; + struct nk_vec2i begin; + struct nk_vec2i end; + struct nk_color color; +}; + +struct nk_command_curve { + struct nk_command header; + unsigned short line_thickness; + struct nk_vec2i begin; + struct nk_vec2i end; + struct nk_vec2i ctrl[2]; + struct nk_color color; +}; + +struct nk_command_rect { + struct nk_command header; + unsigned short rounding; + unsigned short line_thickness; + short x, y; + unsigned short w, h; + struct nk_color color; +}; + +struct nk_command_rect_filled { + struct nk_command header; + unsigned short rounding; + short x, y; + unsigned short w, h; + struct nk_color color; +}; + +struct nk_command_rect_multi_color { + struct nk_command header; + short x, y; + unsigned short w, h; + struct nk_color left; + struct nk_color top; + struct nk_color bottom; + struct nk_color right; +}; + +struct nk_command_triangle { + struct nk_command header; + unsigned short line_thickness; + struct nk_vec2i a; + struct nk_vec2i b; + struct nk_vec2i c; + struct nk_color color; +}; + +struct nk_command_triangle_filled { + struct nk_command header; + struct nk_vec2i a; + struct nk_vec2i b; + struct nk_vec2i c; + struct nk_color color; +}; + +struct nk_command_circle { + struct nk_command header; + short x, y; + unsigned short line_thickness; + unsigned short w, h; + struct nk_color color; +}; + +struct nk_command_circle_filled { + struct nk_command header; + short x, y; + unsigned short w, h; + struct nk_color color; +}; + +struct nk_command_arc { + struct nk_command header; + short cx, cy; + unsigned short r; + unsigned short line_thickness; + float a[2]; + struct nk_color color; +}; + +struct nk_command_arc_filled { + struct nk_command header; + short cx, cy; + unsigned short r; + float a[2]; + struct nk_color color; +}; + +struct nk_command_polygon { + struct nk_command header; + struct nk_color color; + unsigned short line_thickness; + unsigned short point_count; + struct nk_vec2i points[1]; +}; + +struct nk_command_polygon_filled { + struct nk_command header; + struct nk_color color; + unsigned short point_count; + struct nk_vec2i points[1]; +}; + +struct nk_command_polyline { + struct nk_command header; + struct nk_color color; + unsigned short line_thickness; + unsigned short point_count; + struct nk_vec2i points[1]; +}; + +struct nk_command_image { + struct nk_command header; + short x, y; + unsigned short w, h; + struct nk_image img; + struct nk_color col; +}; + +typedef void (*nk_command_custom_callback)(void *canvas, short x,short y, + unsigned short w, unsigned short h, nk_handle callback_data); +struct nk_command_custom { + struct nk_command header; + short x, y; + unsigned short w, h; + nk_handle callback_data; + nk_command_custom_callback callback; +}; + +struct nk_command_text { + struct nk_command header; + const struct nk_user_font *font; + struct nk_color background; + struct nk_color foreground; + short x, y; + unsigned short w, h; + float height; + int length; + char string[1]; +}; + +enum nk_command_clipping { + NK_CLIPPING_OFF = nk_false, + NK_CLIPPING_ON = nk_true +}; + +struct nk_command_buffer { + struct nk_buffer *base; + struct nk_rect clip; + int use_clipping; + nk_handle userdata; + nk_size begin, end, last; +}; + +/* shape outlines */ +NK_API void nk_stroke_line(struct nk_command_buffer *b, float x0, float y0, float x1, float y1, float line_thickness, struct nk_color); +NK_API void nk_stroke_curve(struct nk_command_buffer*, float, float, float, float, float, float, float, float, float line_thickness, struct nk_color); +NK_API void nk_stroke_rect(struct nk_command_buffer*, struct nk_rect, float rounding, float line_thickness, struct nk_color); +NK_API void nk_stroke_circle(struct nk_command_buffer*, struct nk_rect, float line_thickness, struct nk_color); +NK_API void nk_stroke_arc(struct nk_command_buffer*, float cx, float cy, float radius, float a_min, float a_max, float line_thickness, struct nk_color); +NK_API void nk_stroke_triangle(struct nk_command_buffer*, float, float, float, float, float, float, float line_thichness, struct nk_color); +NK_API void nk_stroke_polyline(struct nk_command_buffer*, float *points, int point_count, float line_thickness, struct nk_color col); +NK_API void nk_stroke_polygon(struct nk_command_buffer*, float*, int point_count, float line_thickness, struct nk_color); + +/* filled shades */ +NK_API void nk_fill_rect(struct nk_command_buffer*, struct nk_rect, float rounding, struct nk_color); +NK_API void nk_fill_rect_multi_color(struct nk_command_buffer*, struct nk_rect, struct nk_color left, struct nk_color top, struct nk_color right, struct nk_color bottom); +NK_API void nk_fill_circle(struct nk_command_buffer*, struct nk_rect, struct nk_color); +NK_API void nk_fill_arc(struct nk_command_buffer*, float cx, float cy, float radius, float a_min, float a_max, struct nk_color); +NK_API void nk_fill_triangle(struct nk_command_buffer*, float x0, float y0, float x1, float y1, float x2, float y2, struct nk_color); +NK_API void nk_fill_polygon(struct nk_command_buffer*, float*, int point_count, struct nk_color); + +/* misc */ +NK_API void nk_draw_image(struct nk_command_buffer*, struct nk_rect, const struct nk_image*, struct nk_color); +NK_API void nk_draw_nine_slice(struct nk_command_buffer*, struct nk_rect, const struct nk_nine_slice*, struct nk_color); +NK_API void nk_draw_text(struct nk_command_buffer*, struct nk_rect, const char *text, int len, const struct nk_user_font*, struct nk_color, struct nk_color); +NK_API void nk_push_scissor(struct nk_command_buffer*, struct nk_rect); +NK_API void nk_push_custom(struct nk_command_buffer*, struct nk_rect, nk_command_custom_callback, nk_handle usr); + +/* =============================================================== + * + * INPUT + * + * ===============================================================*/ +struct nk_mouse_button { + nk_bool down; + unsigned int clicked; + struct nk_vec2 clicked_pos; +}; +struct nk_mouse { + struct nk_mouse_button buttons[NK_BUTTON_MAX]; + struct nk_vec2 pos; +#ifdef NK_BUTTON_TRIGGER_ON_RELEASE + struct nk_vec2 down_pos; +#endif + struct nk_vec2 prev; + struct nk_vec2 delta; + struct nk_vec2 scroll_delta; + unsigned char grab; + unsigned char grabbed; + unsigned char ungrab; +}; + +struct nk_key { + nk_bool down; + unsigned int clicked; +}; +struct nk_keyboard { + struct nk_key keys[NK_KEY_MAX]; + char text[NK_INPUT_MAX]; + int text_len; +}; + +struct nk_input { + struct nk_keyboard keyboard; + struct nk_mouse mouse; +}; + +NK_API nk_bool nk_input_has_mouse_click(const struct nk_input*, enum nk_buttons); +NK_API nk_bool nk_input_has_mouse_click_in_rect(const struct nk_input*, enum nk_buttons, struct nk_rect); +NK_API nk_bool nk_input_has_mouse_click_in_button_rect(const struct nk_input*, enum nk_buttons, struct nk_rect); +NK_API nk_bool nk_input_has_mouse_click_down_in_rect(const struct nk_input*, enum nk_buttons, struct nk_rect, nk_bool down); +NK_API nk_bool nk_input_is_mouse_click_in_rect(const struct nk_input*, enum nk_buttons, struct nk_rect); +NK_API nk_bool nk_input_is_mouse_click_down_in_rect(const struct nk_input *i, enum nk_buttons id, struct nk_rect b, nk_bool down); +NK_API nk_bool nk_input_any_mouse_click_in_rect(const struct nk_input*, struct nk_rect); +NK_API nk_bool nk_input_is_mouse_prev_hovering_rect(const struct nk_input*, struct nk_rect); +NK_API nk_bool nk_input_is_mouse_hovering_rect(const struct nk_input*, struct nk_rect); +NK_API nk_bool nk_input_mouse_clicked(const struct nk_input*, enum nk_buttons, struct nk_rect); +NK_API nk_bool nk_input_is_mouse_down(const struct nk_input*, enum nk_buttons); +NK_API nk_bool nk_input_is_mouse_pressed(const struct nk_input*, enum nk_buttons); +NK_API nk_bool nk_input_is_mouse_released(const struct nk_input*, enum nk_buttons); +NK_API nk_bool nk_input_is_key_pressed(const struct nk_input*, enum nk_keys); +NK_API nk_bool nk_input_is_key_released(const struct nk_input*, enum nk_keys); +NK_API nk_bool nk_input_is_key_down(const struct nk_input*, enum nk_keys); + +/* =============================================================== + * + * DRAW LIST + * + * ===============================================================*/ +#ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT +/* ### Draw List +/// The optional vertex buffer draw list provides a 2D drawing context +/// with antialiasing functionality which takes basic filled or outlined shapes +/// or a path and outputs vertexes, elements and draw commands. +/// The actual draw list API is not required to be used directly while using this +/// library since converting the default library draw command output is done by +/// just calling `nk_convert` but I decided to still make this library accessible +/// since it can be useful. +/// +/// The draw list is based on a path buffering and polygon and polyline +/// rendering API which allows a lot of ways to draw 2D content to screen. +/// In fact it is probably more powerful than needed but allows even more crazy +/// things than this library provides by default. +*/ +#ifdef NK_UINT_DRAW_INDEX +typedef nk_uint nk_draw_index; +#else +typedef nk_ushort nk_draw_index; +#endif +enum nk_draw_list_stroke { + NK_STROKE_OPEN = nk_false, + /* build up path has no connection back to the beginning */ + NK_STROKE_CLOSED = nk_true + /* build up path has a connection back to the beginning */ +}; + +enum nk_draw_vertex_layout_attribute { + NK_VERTEX_POSITION, + NK_VERTEX_COLOR, + NK_VERTEX_TEXCOORD, + NK_VERTEX_ATTRIBUTE_COUNT +}; + +enum nk_draw_vertex_layout_format { + NK_FORMAT_SCHAR, + NK_FORMAT_SSHORT, + NK_FORMAT_SINT, + NK_FORMAT_UCHAR, + NK_FORMAT_USHORT, + NK_FORMAT_UINT, + NK_FORMAT_FLOAT, + NK_FORMAT_DOUBLE, + +NK_FORMAT_COLOR_BEGIN, + NK_FORMAT_R8G8B8 = NK_FORMAT_COLOR_BEGIN, + NK_FORMAT_R16G15B16, + NK_FORMAT_R32G32B32, + + NK_FORMAT_R8G8B8A8, + NK_FORMAT_B8G8R8A8, + NK_FORMAT_R16G15B16A16, + NK_FORMAT_R32G32B32A32, + NK_FORMAT_R32G32B32A32_FLOAT, + NK_FORMAT_R32G32B32A32_DOUBLE, + + NK_FORMAT_RGB32, + NK_FORMAT_RGBA32, +NK_FORMAT_COLOR_END = NK_FORMAT_RGBA32, + NK_FORMAT_COUNT +}; + +#define NK_VERTEX_LAYOUT_END NK_VERTEX_ATTRIBUTE_COUNT,NK_FORMAT_COUNT,0 +struct nk_draw_vertex_layout_element { + enum nk_draw_vertex_layout_attribute attribute; + enum nk_draw_vertex_layout_format format; + nk_size offset; +}; + +struct nk_draw_command { + unsigned int elem_count; + /* number of elements in the current draw batch */ + struct nk_rect clip_rect; + /* current screen clipping rectangle */ + nk_handle texture; + /* current texture to set */ +#ifdef NK_INCLUDE_COMMAND_USERDATA + nk_handle userdata; +#endif +}; + +struct nk_draw_list { + struct nk_rect clip_rect; + struct nk_vec2 circle_vtx[12]; + struct nk_convert_config config; + + struct nk_buffer *buffer; + struct nk_buffer *vertices; + struct nk_buffer *elements; + + unsigned int element_count; + unsigned int vertex_count; + unsigned int cmd_count; + nk_size cmd_offset; + + unsigned int path_count; + unsigned int path_offset; + + enum nk_anti_aliasing line_AA; + enum nk_anti_aliasing shape_AA; + +#ifdef NK_INCLUDE_COMMAND_USERDATA + nk_handle userdata; +#endif +}; + +/* draw list */ +NK_API void nk_draw_list_init(struct nk_draw_list*); +NK_API void nk_draw_list_setup(struct nk_draw_list*, const struct nk_convert_config*, struct nk_buffer *cmds, struct nk_buffer *vertices, struct nk_buffer *elements, enum nk_anti_aliasing line_aa,enum nk_anti_aliasing shape_aa); + +/* drawing */ +#define nk_draw_list_foreach(cmd, can, b) for((cmd)=nk__draw_list_begin(can, b); (cmd)!=0; (cmd)=nk__draw_list_next(cmd, b, can)) +NK_API const struct nk_draw_command* nk__draw_list_begin(const struct nk_draw_list*, const struct nk_buffer*); +NK_API const struct nk_draw_command* nk__draw_list_next(const struct nk_draw_command*, const struct nk_buffer*, const struct nk_draw_list*); +NK_API const struct nk_draw_command* nk__draw_list_end(const struct nk_draw_list*, const struct nk_buffer*); + +/* path */ +NK_API void nk_draw_list_path_clear(struct nk_draw_list*); +NK_API void nk_draw_list_path_line_to(struct nk_draw_list*, struct nk_vec2 pos); +NK_API void nk_draw_list_path_arc_to_fast(struct nk_draw_list*, struct nk_vec2 center, float radius, int a_min, int a_max); +NK_API void nk_draw_list_path_arc_to(struct nk_draw_list*, struct nk_vec2 center, float radius, float a_min, float a_max, unsigned int segments); +NK_API void nk_draw_list_path_rect_to(struct nk_draw_list*, struct nk_vec2 a, struct nk_vec2 b, float rounding); +NK_API void nk_draw_list_path_curve_to(struct nk_draw_list*, struct nk_vec2 p2, struct nk_vec2 p3, struct nk_vec2 p4, unsigned int num_segments); +NK_API void nk_draw_list_path_fill(struct nk_draw_list*, struct nk_color); +NK_API void nk_draw_list_path_stroke(struct nk_draw_list*, struct nk_color, enum nk_draw_list_stroke closed, float thickness); + +/* stroke */ +NK_API void nk_draw_list_stroke_line(struct nk_draw_list*, struct nk_vec2 a, struct nk_vec2 b, struct nk_color, float thickness); +NK_API void nk_draw_list_stroke_rect(struct nk_draw_list*, struct nk_rect rect, struct nk_color, float rounding, float thickness); +NK_API void nk_draw_list_stroke_triangle(struct nk_draw_list*, struct nk_vec2 a, struct nk_vec2 b, struct nk_vec2 c, struct nk_color, float thickness); +NK_API void nk_draw_list_stroke_circle(struct nk_draw_list*, struct nk_vec2 center, float radius, struct nk_color, unsigned int segs, float thickness); +NK_API void nk_draw_list_stroke_curve(struct nk_draw_list*, struct nk_vec2 p0, struct nk_vec2 cp0, struct nk_vec2 cp1, struct nk_vec2 p1, struct nk_color, unsigned int segments, float thickness); +NK_API void nk_draw_list_stroke_poly_line(struct nk_draw_list*, const struct nk_vec2 *pnts, const unsigned int cnt, struct nk_color, enum nk_draw_list_stroke, float thickness, enum nk_anti_aliasing); + +/* fill */ +NK_API void nk_draw_list_fill_rect(struct nk_draw_list*, struct nk_rect rect, struct nk_color, float rounding); +NK_API void nk_draw_list_fill_rect_multi_color(struct nk_draw_list*, struct nk_rect rect, struct nk_color left, struct nk_color top, struct nk_color right, struct nk_color bottom); +NK_API void nk_draw_list_fill_triangle(struct nk_draw_list*, struct nk_vec2 a, struct nk_vec2 b, struct nk_vec2 c, struct nk_color); +NK_API void nk_draw_list_fill_circle(struct nk_draw_list*, struct nk_vec2 center, float radius, struct nk_color col, unsigned int segs); +NK_API void nk_draw_list_fill_poly_convex(struct nk_draw_list*, const struct nk_vec2 *points, const unsigned int count, struct nk_color, enum nk_anti_aliasing); + +/* misc */ +NK_API void nk_draw_list_add_image(struct nk_draw_list*, struct nk_image texture, struct nk_rect rect, struct nk_color); +NK_API void nk_draw_list_add_text(struct nk_draw_list*, const struct nk_user_font*, struct nk_rect, const char *text, int len, float font_height, struct nk_color); +#ifdef NK_INCLUDE_COMMAND_USERDATA +NK_API void nk_draw_list_push_userdata(struct nk_draw_list*, nk_handle userdata); +#endif + +#endif + +/* =============================================================== + * + * GUI + * + * ===============================================================*/ +enum nk_style_item_type { + NK_STYLE_ITEM_COLOR, + NK_STYLE_ITEM_IMAGE, + NK_STYLE_ITEM_NINE_SLICE +}; + +union nk_style_item_data { + struct nk_color color; + struct nk_image image; + struct nk_nine_slice slice; +}; + +struct nk_style_item { + enum nk_style_item_type type; + union nk_style_item_data data; +}; + +struct nk_style_text { + struct nk_color color; + struct nk_vec2 padding; +}; + +struct nk_style_button { + /* background */ + struct nk_style_item normal; + struct nk_style_item hover; + struct nk_style_item active; + struct nk_color border_color; + + /* text */ + struct nk_color text_background; + struct nk_color text_normal; + struct nk_color text_hover; + struct nk_color text_active; + nk_flags text_alignment; + + /* properties */ + float border; + float rounding; + struct nk_vec2 padding; + struct nk_vec2 image_padding; + struct nk_vec2 touch_padding; + + /* optional user callbacks */ + nk_handle userdata; + void(*draw_begin)(struct nk_command_buffer*, nk_handle userdata); + void(*draw_end)(struct nk_command_buffer*, nk_handle userdata); +}; + +struct nk_style_toggle { + /* background */ + struct nk_style_item normal; + struct nk_style_item hover; + struct nk_style_item active; + struct nk_color border_color; + + /* cursor */ + struct nk_style_item cursor_normal; + struct nk_style_item cursor_hover; + + /* text */ + struct nk_color text_normal; + struct nk_color text_hover; + struct nk_color text_active; + struct nk_color text_background; + nk_flags text_alignment; + + /* properties */ + struct nk_vec2 padding; + struct nk_vec2 touch_padding; + float spacing; + float border; + + /* optional user callbacks */ + nk_handle userdata; + void(*draw_begin)(struct nk_command_buffer*, nk_handle); + void(*draw_end)(struct nk_command_buffer*, nk_handle); +}; + +struct nk_style_selectable { + /* background (inactive) */ + struct nk_style_item normal; + struct nk_style_item hover; + struct nk_style_item pressed; + + /* background (active) */ + struct nk_style_item normal_active; + struct nk_style_item hover_active; + struct nk_style_item pressed_active; + + /* text color (inactive) */ + struct nk_color text_normal; + struct nk_color text_hover; + struct nk_color text_pressed; + + /* text color (active) */ + struct nk_color text_normal_active; + struct nk_color text_hover_active; + struct nk_color text_pressed_active; + struct nk_color text_background; + nk_flags text_alignment; + + /* properties */ + float rounding; + struct nk_vec2 padding; + struct nk_vec2 touch_padding; + struct nk_vec2 image_padding; + + /* optional user callbacks */ + nk_handle userdata; + void(*draw_begin)(struct nk_command_buffer*, nk_handle); + void(*draw_end)(struct nk_command_buffer*, nk_handle); +}; + +struct nk_style_slider { + /* background */ + struct nk_style_item normal; + struct nk_style_item hover; + struct nk_style_item active; + struct nk_color border_color; + + /* background bar */ + struct nk_color bar_normal; + struct nk_color bar_hover; + struct nk_color bar_active; + struct nk_color bar_filled; + + /* cursor */ + struct nk_style_item cursor_normal; + struct nk_style_item cursor_hover; + struct nk_style_item cursor_active; + + /* properties */ + float border; + float rounding; + float bar_height; + struct nk_vec2 padding; + struct nk_vec2 spacing; + struct nk_vec2 cursor_size; + + /* optional buttons */ + int show_buttons; + struct nk_style_button inc_button; + struct nk_style_button dec_button; + enum nk_symbol_type inc_symbol; + enum nk_symbol_type dec_symbol; + + /* optional user callbacks */ + nk_handle userdata; + void(*draw_begin)(struct nk_command_buffer*, nk_handle); + void(*draw_end)(struct nk_command_buffer*, nk_handle); +}; + +struct nk_style_progress { + /* background */ + struct nk_style_item normal; + struct nk_style_item hover; + struct nk_style_item active; + struct nk_color border_color; + + /* cursor */ + struct nk_style_item cursor_normal; + struct nk_style_item cursor_hover; + struct nk_style_item cursor_active; + struct nk_color cursor_border_color; + + /* properties */ + float rounding; + float border; + float cursor_border; + float cursor_rounding; + struct nk_vec2 padding; + + /* optional user callbacks */ + nk_handle userdata; + void(*draw_begin)(struct nk_command_buffer*, nk_handle); + void(*draw_end)(struct nk_command_buffer*, nk_handle); +}; + +struct nk_style_scrollbar { + /* background */ + struct nk_style_item normal; + struct nk_style_item hover; + struct nk_style_item active; + struct nk_color border_color; + + /* cursor */ + struct nk_style_item cursor_normal; + struct nk_style_item cursor_hover; + struct nk_style_item cursor_active; + struct nk_color cursor_border_color; + + /* properties */ + float border; + float rounding; + float border_cursor; + float rounding_cursor; + struct nk_vec2 padding; + + /* optional buttons */ + int show_buttons; + struct nk_style_button inc_button; + struct nk_style_button dec_button; + enum nk_symbol_type inc_symbol; + enum nk_symbol_type dec_symbol; + + /* optional user callbacks */ + nk_handle userdata; + void(*draw_begin)(struct nk_command_buffer*, nk_handle); + void(*draw_end)(struct nk_command_buffer*, nk_handle); +}; + +struct nk_style_edit { + /* background */ + struct nk_style_item normal; + struct nk_style_item hover; + struct nk_style_item active; + struct nk_color border_color; + struct nk_style_scrollbar scrollbar; + + /* cursor */ + struct nk_color cursor_normal; + struct nk_color cursor_hover; + struct nk_color cursor_text_normal; + struct nk_color cursor_text_hover; + + /* text (unselected) */ + struct nk_color text_normal; + struct nk_color text_hover; + struct nk_color text_active; + + /* text (selected) */ + struct nk_color selected_normal; + struct nk_color selected_hover; + struct nk_color selected_text_normal; + struct nk_color selected_text_hover; + + /* properties */ + float border; + float rounding; + float cursor_size; + struct nk_vec2 scrollbar_size; + struct nk_vec2 padding; + float row_padding; +}; + +struct nk_style_property { + /* background */ + struct nk_style_item normal; + struct nk_style_item hover; + struct nk_style_item active; + struct nk_color border_color; + + /* text */ + struct nk_color label_normal; + struct nk_color label_hover; + struct nk_color label_active; + + /* symbols */ + enum nk_symbol_type sym_left; + enum nk_symbol_type sym_right; + + /* properties */ + float border; + float rounding; + struct nk_vec2 padding; + + struct nk_style_edit edit; + struct nk_style_button inc_button; + struct nk_style_button dec_button; + + /* optional user callbacks */ + nk_handle userdata; + void(*draw_begin)(struct nk_command_buffer*, nk_handle); + void(*draw_end)(struct nk_command_buffer*, nk_handle); +}; + +struct nk_style_chart { + /* colors */ + struct nk_style_item background; + struct nk_color border_color; + struct nk_color selected_color; + struct nk_color color; + + /* properties */ + float border; + float rounding; + struct nk_vec2 padding; +}; + +struct nk_style_combo { + /* background */ + struct nk_style_item normal; + struct nk_style_item hover; + struct nk_style_item active; + struct nk_color border_color; + + /* label */ + struct nk_color label_normal; + struct nk_color label_hover; + struct nk_color label_active; + + /* symbol */ + struct nk_color symbol_normal; + struct nk_color symbol_hover; + struct nk_color symbol_active; + + /* button */ + struct nk_style_button button; + enum nk_symbol_type sym_normal; + enum nk_symbol_type sym_hover; + enum nk_symbol_type sym_active; + + /* properties */ + float border; + float rounding; + struct nk_vec2 content_padding; + struct nk_vec2 button_padding; + struct nk_vec2 spacing; +}; + +struct nk_style_tab { + /* background */ + struct nk_style_item background; + struct nk_color border_color; + struct nk_color text; + + /* button */ + struct nk_style_button tab_maximize_button; + struct nk_style_button tab_minimize_button; + struct nk_style_button node_maximize_button; + struct nk_style_button node_minimize_button; + enum nk_symbol_type sym_minimize; + enum nk_symbol_type sym_maximize; + + /* properties */ + float border; + float rounding; + float indent; + struct nk_vec2 padding; + struct nk_vec2 spacing; +}; + +enum nk_style_header_align { + NK_HEADER_LEFT, + NK_HEADER_RIGHT +}; +struct nk_style_window_header { + /* background */ + struct nk_style_item normal; + struct nk_style_item hover; + struct nk_style_item active; + + /* button */ + struct nk_style_button close_button; + struct nk_style_button minimize_button; + enum nk_symbol_type close_symbol; + enum nk_symbol_type minimize_symbol; + enum nk_symbol_type maximize_symbol; + + /* title */ + struct nk_color label_normal; + struct nk_color label_hover; + struct nk_color label_active; + + /* properties */ + enum nk_style_header_align align; + struct nk_vec2 padding; + struct nk_vec2 label_padding; + struct nk_vec2 spacing; +}; + +struct nk_style_window { + struct nk_style_window_header header; + struct nk_style_item fixed_background; + struct nk_color background; + + struct nk_color border_color; + struct nk_color popup_border_color; + struct nk_color combo_border_color; + struct nk_color contextual_border_color; + struct nk_color menu_border_color; + struct nk_color group_border_color; + struct nk_color tooltip_border_color; + struct nk_style_item scaler; + + float border; + float combo_border; + float contextual_border; + float menu_border; + float group_border; + float tooltip_border; + float popup_border; + float min_row_height_padding; + + float rounding; + struct nk_vec2 spacing; + struct nk_vec2 scrollbar_size; + struct nk_vec2 min_size; + + struct nk_vec2 padding; + struct nk_vec2 group_padding; + struct nk_vec2 popup_padding; + struct nk_vec2 combo_padding; + struct nk_vec2 contextual_padding; + struct nk_vec2 menu_padding; + struct nk_vec2 tooltip_padding; +}; + +struct nk_style { + const struct nk_user_font *font; + const struct nk_cursor *cursors[NK_CURSOR_COUNT]; + const struct nk_cursor *cursor_active; + struct nk_cursor *cursor_last; + int cursor_visible; + + struct nk_style_text text; + struct nk_style_button button; + struct nk_style_button contextual_button; + struct nk_style_button menu_button; + struct nk_style_toggle option; + struct nk_style_toggle checkbox; + struct nk_style_selectable selectable; + struct nk_style_slider slider; + struct nk_style_progress progress; + struct nk_style_property property; + struct nk_style_edit edit; + struct nk_style_chart chart; + struct nk_style_scrollbar scrollh; + struct nk_style_scrollbar scrollv; + struct nk_style_tab tab; + struct nk_style_combo combo; + struct nk_style_window window; +}; + +NK_API struct nk_style_item nk_style_item_color(struct nk_color); +NK_API struct nk_style_item nk_style_item_image(struct nk_image img); +NK_API struct nk_style_item nk_style_item_nine_slice(struct nk_nine_slice slice); +NK_API struct nk_style_item nk_style_item_hide(void); + +/*============================================================== + * PANEL + * =============================================================*/ +#ifndef NK_MAX_LAYOUT_ROW_TEMPLATE_COLUMNS +#define NK_MAX_LAYOUT_ROW_TEMPLATE_COLUMNS 16 +#endif +#ifndef NK_CHART_MAX_SLOT +#define NK_CHART_MAX_SLOT 4 +#endif + +enum nk_panel_type { + NK_PANEL_NONE = 0, + NK_PANEL_WINDOW = NK_FLAG(0), + NK_PANEL_GROUP = NK_FLAG(1), + NK_PANEL_POPUP = NK_FLAG(2), + NK_PANEL_CONTEXTUAL = NK_FLAG(4), + NK_PANEL_COMBO = NK_FLAG(5), + NK_PANEL_MENU = NK_FLAG(6), + NK_PANEL_TOOLTIP = NK_FLAG(7) +}; +enum nk_panel_set { + NK_PANEL_SET_NONBLOCK = NK_PANEL_CONTEXTUAL|NK_PANEL_COMBO|NK_PANEL_MENU|NK_PANEL_TOOLTIP, + NK_PANEL_SET_POPUP = NK_PANEL_SET_NONBLOCK|NK_PANEL_POPUP, + NK_PANEL_SET_SUB = NK_PANEL_SET_POPUP|NK_PANEL_GROUP +}; + +struct nk_chart_slot { + enum nk_chart_type type; + struct nk_color color; + struct nk_color highlight; + float min, max, range; + int count; + struct nk_vec2 last; + int index; +}; + +struct nk_chart { + int slot; + float x, y, w, h; + struct nk_chart_slot slots[NK_CHART_MAX_SLOT]; +}; + +enum nk_panel_row_layout_type { + NK_LAYOUT_DYNAMIC_FIXED = 0, + NK_LAYOUT_DYNAMIC_ROW, + NK_LAYOUT_DYNAMIC_FREE, + NK_LAYOUT_DYNAMIC, + NK_LAYOUT_STATIC_FIXED, + NK_LAYOUT_STATIC_ROW, + NK_LAYOUT_STATIC_FREE, + NK_LAYOUT_STATIC, + NK_LAYOUT_TEMPLATE, + NK_LAYOUT_COUNT +}; +struct nk_row_layout { + enum nk_panel_row_layout_type type; + int index; + float height; + float min_height; + int columns; + const float *ratio; + float item_width; + float item_height; + float item_offset; + float filled; + struct nk_rect item; + int tree_depth; + float templates[NK_MAX_LAYOUT_ROW_TEMPLATE_COLUMNS]; +}; + +struct nk_popup_buffer { + nk_size begin; + nk_size parent; + nk_size last; + nk_size end; + nk_bool active; +}; + +struct nk_menu_state { + float x, y, w, h; + struct nk_scroll offset; +}; + +struct nk_panel { + enum nk_panel_type type; + nk_flags flags; + struct nk_rect bounds; + nk_uint *offset_x; + nk_uint *offset_y; + float at_x, at_y, max_x; + float footer_height; + float header_height; + float border; + unsigned int has_scrolling; + struct nk_rect clip; + struct nk_menu_state menu; + struct nk_row_layout row; + struct nk_chart chart; + struct nk_command_buffer *buffer; + struct nk_panel *parent; +}; + +/*============================================================== + * WINDOW + * =============================================================*/ +#ifndef NK_WINDOW_MAX_NAME +#define NK_WINDOW_MAX_NAME 64 +#endif + +struct nk_table; +enum nk_window_flags { + NK_WINDOW_PRIVATE = NK_FLAG(11), + NK_WINDOW_DYNAMIC = NK_WINDOW_PRIVATE, + /* special window type growing up in height while being filled to a certain maximum height */ + NK_WINDOW_ROM = NK_FLAG(12), + /* sets window widgets into a read only mode and does not allow input changes */ + NK_WINDOW_NOT_INTERACTIVE = NK_WINDOW_ROM|NK_WINDOW_NO_INPUT, + /* prevents all interaction caused by input to either window or widgets inside */ + NK_WINDOW_HIDDEN = NK_FLAG(13), + /* Hides window and stops any window interaction and drawing */ + NK_WINDOW_CLOSED = NK_FLAG(14), + /* Directly closes and frees the window at the end of the frame */ + NK_WINDOW_MINIMIZED = NK_FLAG(15), + /* marks the window as minimized */ + NK_WINDOW_REMOVE_ROM = NK_FLAG(16) + /* Removes read only mode at the end of the window */ +}; + +struct nk_popup_state { + struct nk_window *win; + enum nk_panel_type type; + struct nk_popup_buffer buf; + nk_hash name; + nk_bool active; + unsigned combo_count; + unsigned con_count, con_old; + unsigned active_con; + struct nk_rect header; +}; + +struct nk_edit_state { + nk_hash name; + unsigned int seq; + unsigned int old; + int active, prev; + int cursor; + int sel_start; + int sel_end; + struct nk_scroll scrollbar; + unsigned char mode; + unsigned char single_line; +}; + +struct nk_property_state { + int active, prev; + char buffer[NK_MAX_NUMBER_BUFFER]; + int length; + int cursor; + int select_start; + int select_end; + nk_hash name; + unsigned int seq; + unsigned int old; + int state; +}; + +struct nk_window { + unsigned int seq; + nk_hash name; + char name_string[NK_WINDOW_MAX_NAME]; + nk_flags flags; + + struct nk_rect bounds; + struct nk_scroll scrollbar; + struct nk_command_buffer buffer; + struct nk_panel *layout; + float scrollbar_hiding_timer; + + /* persistent widget state */ + struct nk_property_state property; + struct nk_popup_state popup; + struct nk_edit_state edit; + unsigned int scrolled; + + struct nk_table *tables; + unsigned int table_count; + + /* window list hooks */ + struct nk_window *next; + struct nk_window *prev; + struct nk_window *parent; +}; + +/*============================================================== + * STACK + * =============================================================*/ +/*/// ### Stack +/// The style modifier stack can be used to temporarily change a +/// property inside `nk_style`. For example if you want a special +/// red button you can temporarily push the old button color onto a stack +/// draw the button with a red color and then you just pop the old color +/// back from the stack: +/// +/// nk_style_push_style_item(ctx, &ctx->style.button.normal, nk_style_item_color(nk_rgb(255,0,0))); +/// nk_style_push_style_item(ctx, &ctx->style.button.hover, nk_style_item_color(nk_rgb(255,0,0))); +/// nk_style_push_style_item(ctx, &ctx->style.button.active, nk_style_item_color(nk_rgb(255,0,0))); +/// nk_style_push_vec2(ctx, &cx->style.button.padding, nk_vec2(2,2)); +/// +/// nk_button(...); +/// +/// nk_style_pop_style_item(ctx); +/// nk_style_pop_style_item(ctx); +/// nk_style_pop_style_item(ctx); +/// nk_style_pop_vec2(ctx); +/// +/// Nuklear has a stack for style_items, float properties, vector properties, +/// flags, colors, fonts and for button_behavior. Each has it's own fixed size stack +/// which can be changed at compile time. + */ +#ifndef NK_BUTTON_BEHAVIOR_STACK_SIZE +#define NK_BUTTON_BEHAVIOR_STACK_SIZE 8 +#endif + +#ifndef NK_FONT_STACK_SIZE +#define NK_FONT_STACK_SIZE 8 +#endif + +#ifndef NK_STYLE_ITEM_STACK_SIZE +#define NK_STYLE_ITEM_STACK_SIZE 16 +#endif + +#ifndef NK_FLOAT_STACK_SIZE +#define NK_FLOAT_STACK_SIZE 32 +#endif + +#ifndef NK_VECTOR_STACK_SIZE +#define NK_VECTOR_STACK_SIZE 16 +#endif + +#ifndef NK_FLAGS_STACK_SIZE +#define NK_FLAGS_STACK_SIZE 32 +#endif + +#ifndef NK_COLOR_STACK_SIZE +#define NK_COLOR_STACK_SIZE 32 +#endif + +#define NK_CONFIGURATION_STACK_TYPE(prefix, name, type)\ + struct nk_config_stack_##name##_element {\ + prefix##_##type *address;\ + prefix##_##type old_value;\ + } +#define NK_CONFIG_STACK(type,size)\ + struct nk_config_stack_##type {\ + int head;\ + struct nk_config_stack_##type##_element elements[size];\ + } + +#define nk_float float +NK_CONFIGURATION_STACK_TYPE(struct nk, style_item, style_item); +NK_CONFIGURATION_STACK_TYPE(nk ,float, float); +NK_CONFIGURATION_STACK_TYPE(struct nk, vec2, vec2); +NK_CONFIGURATION_STACK_TYPE(nk ,flags, flags); +NK_CONFIGURATION_STACK_TYPE(struct nk, color, color); +NK_CONFIGURATION_STACK_TYPE(const struct nk, user_font, user_font*); +NK_CONFIGURATION_STACK_TYPE(enum nk, button_behavior, button_behavior); + +NK_CONFIG_STACK(style_item, NK_STYLE_ITEM_STACK_SIZE); +NK_CONFIG_STACK(float, NK_FLOAT_STACK_SIZE); +NK_CONFIG_STACK(vec2, NK_VECTOR_STACK_SIZE); +NK_CONFIG_STACK(flags, NK_FLAGS_STACK_SIZE); +NK_CONFIG_STACK(color, NK_COLOR_STACK_SIZE); +NK_CONFIG_STACK(user_font, NK_FONT_STACK_SIZE); +NK_CONFIG_STACK(button_behavior, NK_BUTTON_BEHAVIOR_STACK_SIZE); + +struct nk_configuration_stacks { + struct nk_config_stack_style_item style_items; + struct nk_config_stack_float floats; + struct nk_config_stack_vec2 vectors; + struct nk_config_stack_flags flags; + struct nk_config_stack_color colors; + struct nk_config_stack_user_font fonts; + struct nk_config_stack_button_behavior button_behaviors; +}; + +/*============================================================== + * CONTEXT + * =============================================================*/ +#define NK_VALUE_PAGE_CAPACITY \ + (((NK_MAX(sizeof(struct nk_window),sizeof(struct nk_panel)) / sizeof(nk_uint))) / 2) + +struct nk_table { + unsigned int seq; + unsigned int size; + nk_hash keys[NK_VALUE_PAGE_CAPACITY]; + nk_uint values[NK_VALUE_PAGE_CAPACITY]; + struct nk_table *next, *prev; +}; + +union nk_page_data { + struct nk_table tbl; + struct nk_panel pan; + struct nk_window win; +}; + +struct nk_page_element { + union nk_page_data data; + struct nk_page_element *next; + struct nk_page_element *prev; +}; + +struct nk_page { + unsigned int size; + struct nk_page *next; + struct nk_page_element win[1]; +}; + +struct nk_pool { + struct nk_allocator alloc; + enum nk_allocation_type type; + unsigned int page_count; + struct nk_page *pages; + struct nk_page_element *freelist; + unsigned capacity; + nk_size size; + nk_size cap; +}; + +struct nk_context { +/* public: can be accessed freely */ + struct nk_input input; + struct nk_style style; + struct nk_buffer memory; + struct nk_clipboard clip; + nk_flags last_widget_state; + enum nk_button_behavior button_behavior; + struct nk_configuration_stacks stacks; + float delta_time_seconds; + +/* private: + should only be accessed if you + know what you are doing */ +#ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT + struct nk_draw_list draw_list; +#endif +#ifdef NK_INCLUDE_COMMAND_USERDATA + nk_handle userdata; +#endif + /* text editor objects are quite big because of an internal + * undo/redo stack. Therefore it does not make sense to have one for + * each window for temporary use cases, so I only provide *one* instance + * for all windows. This works because the content is cleared anyway */ + struct nk_text_edit text_edit; + /* draw buffer used for overlay drawing operation like cursor */ + struct nk_command_buffer overlay; + + /* windows */ + int build; + int use_pool; + struct nk_pool pool; + struct nk_window *begin; + struct nk_window *end; + struct nk_window *active; + struct nk_window *current; + struct nk_page_element *freelist; + unsigned int count; + unsigned int seq; +}; + +/* ============================================================== + * MATH + * =============================================================== */ +#define NK_PI 3.141592654f +#define NK_UTF_INVALID 0xFFFD +#define NK_MAX_FLOAT_PRECISION 2 + +#define NK_UNUSED(x) ((void)(x)) +#define NK_SATURATE(x) (NK_MAX(0, NK_MIN(1.0f, x))) +#define NK_LEN(a) (sizeof(a)/sizeof(a)[0]) +#define NK_ABS(a) (((a) < 0) ? -(a) : (a)) +#define NK_BETWEEN(x, a, b) ((a) <= (x) && (x) < (b)) +#define NK_INBOX(px, py, x, y, w, h)\ + (NK_BETWEEN(px,x,x+w) && NK_BETWEEN(py,y,y+h)) +#define NK_INTERSECT(x0, y0, w0, h0, x1, y1, w1, h1) \ + ((x1 < (x0 + w0)) && (x0 < (x1 + w1)) && \ + (y1 < (y0 + h0)) && (y0 < (y1 + h1))) +#define NK_CONTAINS(x, y, w, h, bx, by, bw, bh)\ + (NK_INBOX(x,y, bx, by, bw, bh) && NK_INBOX(x+w,y+h, bx, by, bw, bh)) + +#define nk_vec2_sub(a, b) nk_vec2((a).x - (b).x, (a).y - (b).y) +#define nk_vec2_add(a, b) nk_vec2((a).x + (b).x, (a).y + (b).y) +#define nk_vec2_len_sqr(a) ((a).x*(a).x+(a).y*(a).y) +#define nk_vec2_muls(a, t) nk_vec2((a).x * (t), (a).y * (t)) + +#define nk_ptr_add(t, p, i) ((t*)((void*)((nk_byte*)(p) + (i)))) +#define nk_ptr_add_const(t, p, i) ((const t*)((const void*)((const nk_byte*)(p) + (i)))) +#define nk_zero_struct(s) nk_zero(&s, sizeof(s)) + +/* ============================================================== + * ALIGNMENT + * =============================================================== */ +/* Pointer to Integer type conversion for pointer alignment */ +#if defined(__PTRDIFF_TYPE__) /* This case should work for GCC*/ +# define NK_UINT_TO_PTR(x) ((void*)(__PTRDIFF_TYPE__)(x)) +# define NK_PTR_TO_UINT(x) ((nk_size)(__PTRDIFF_TYPE__)(x)) +#elif !defined(__GNUC__) /* works for compilers other than LLVM */ +# define NK_UINT_TO_PTR(x) ((void*)&((char*)0)[x]) +# define NK_PTR_TO_UINT(x) ((nk_size)(((char*)x)-(char*)0)) +#elif defined(NK_USE_FIXED_TYPES) /* used if we have */ +# define NK_UINT_TO_PTR(x) ((void*)(uintptr_t)(x)) +# define NK_PTR_TO_UINT(x) ((uintptr_t)(x)) +#else /* generates warning but works */ +# define NK_UINT_TO_PTR(x) ((void*)(x)) +# define NK_PTR_TO_UINT(x) ((nk_size)(x)) +#endif + +#define NK_ALIGN_PTR(x, mask)\ + (NK_UINT_TO_PTR((NK_PTR_TO_UINT((nk_byte*)(x) + (mask-1)) & ~(mask-1)))) +#define NK_ALIGN_PTR_BACK(x, mask)\ + (NK_UINT_TO_PTR((NK_PTR_TO_UINT((nk_byte*)(x)) & ~(mask-1)))) + +#if (defined(__GNUC__) && __GNUC__ >= 4) || defined(__clang__) +#define NK_OFFSETOF(st,m) (__builtin_offsetof(st,m)) +#else +#define NK_OFFSETOF(st,m) ((nk_ptr)&(((st*)0)->m)) +#endif + +#ifdef __cplusplus +} +#endif + +#ifdef __cplusplus +template struct nk_alignof; +template struct nk_helper{enum {value = size_diff};}; +template struct nk_helper{enum {value = nk_alignof::value};}; +template struct nk_alignof{struct Big {T x; char c;}; enum { + diff = sizeof(Big) - sizeof(T), value = nk_helper::value};}; +#define NK_ALIGNOF(t) (nk_alignof::value) +#else +#define NK_ALIGNOF(t) NK_OFFSETOF(struct {char c; t _h;}, _h) +#endif + +#define NK_CONTAINER_OF(ptr,type,member)\ + (type*)((void*)((char*)(1 ? (ptr): &((type*)0)->member) - NK_OFFSETOF(type, member))) + + + +#endif /* NK_NUKLEAR_H_ */ + +#ifdef NK_IMPLEMENTATION + +#ifndef NK_INTERNAL_H +#define NK_INTERNAL_H + +#ifndef NK_POOL_DEFAULT_CAPACITY +#define NK_POOL_DEFAULT_CAPACITY 16 +#endif + +#ifndef NK_DEFAULT_COMMAND_BUFFER_SIZE +#define NK_DEFAULT_COMMAND_BUFFER_SIZE (4*1024) +#endif + +#ifndef NK_BUFFER_DEFAULT_INITIAL_SIZE +#define NK_BUFFER_DEFAULT_INITIAL_SIZE (4*1024) +#endif + +/* standard library headers */ +#ifdef NK_INCLUDE_DEFAULT_ALLOCATOR +#include /* malloc, free */ +#endif +#ifdef NK_INCLUDE_STANDARD_IO +#include /* fopen, fclose,... */ +#endif +#ifdef NK_INCLUDE_STANDARD_VARARGS +#include /* valist, va_start, va_end, ... */ +#endif +#ifndef NK_ASSERT +#include +#define NK_ASSERT(expr) assert(expr) +#endif + +#define NK_DEFAULT (-1) + +#ifndef NK_VSNPRINTF +/* If your compiler does support `vsnprintf` I would highly recommend + * defining this to vsnprintf instead since `vsprintf` is basically + * unbelievable unsafe and should *NEVER* be used. But I have to support + * it since C89 only provides this unsafe version. */ + #if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) ||\ + (defined(__cplusplus) && (__cplusplus >= 201103L)) || \ + (defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L)) ||\ + (defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE >= 500)) ||\ + defined(_ISOC99_SOURCE) || defined(_BSD_SOURCE) + #define NK_VSNPRINTF(s,n,f,a) vsnprintf(s,n,f,a) + #else + #define NK_VSNPRINTF(s,n,f,a) vsprintf(s,f,a) + #endif +#endif + +#define NK_SCHAR_MIN (-127) +#define NK_SCHAR_MAX 127 +#define NK_UCHAR_MIN 0 +#define NK_UCHAR_MAX 256 +#define NK_SSHORT_MIN (-32767) +#define NK_SSHORT_MAX 32767 +#define NK_USHORT_MIN 0 +#define NK_USHORT_MAX 65535 +#define NK_SINT_MIN (-2147483647) +#define NK_SINT_MAX 2147483647 +#define NK_UINT_MIN 0 +#define NK_UINT_MAX 4294967295u + +/* Make sure correct type size: + * This will fire with a negative subscript error if the type sizes + * are set incorrectly by the compiler, and compile out if not */ +NK_STATIC_ASSERT(sizeof(nk_size) >= sizeof(void*)); +NK_STATIC_ASSERT(sizeof(nk_ptr) == sizeof(void*)); +NK_STATIC_ASSERT(sizeof(nk_flags) >= 4); +NK_STATIC_ASSERT(sizeof(nk_rune) >= 4); +NK_STATIC_ASSERT(sizeof(nk_ushort) == 2); +NK_STATIC_ASSERT(sizeof(nk_short) == 2); +NK_STATIC_ASSERT(sizeof(nk_uint) == 4); +NK_STATIC_ASSERT(sizeof(nk_int) == 4); +NK_STATIC_ASSERT(sizeof(nk_byte) == 1); +#ifdef NK_INCLUDE_STANDARD_BOOL +NK_STATIC_ASSERT(sizeof(nk_bool) == sizeof(bool)); +#else +NK_STATIC_ASSERT(sizeof(nk_bool) == 4); +#endif + +NK_GLOBAL const struct nk_rect nk_null_rect = {-8192.0f, -8192.0f, 16384, 16384}; +#define NK_FLOAT_PRECISION 0.00000000000001 + +NK_GLOBAL const struct nk_color nk_red = {255,0,0,255}; +NK_GLOBAL const struct nk_color nk_green = {0,255,0,255}; +NK_GLOBAL const struct nk_color nk_blue = {0,0,255,255}; +NK_GLOBAL const struct nk_color nk_white = {255,255,255,255}; +NK_GLOBAL const struct nk_color nk_black = {0,0,0,255}; +NK_GLOBAL const struct nk_color nk_yellow = {255,255,0,255}; + +/* widget */ +#define nk_widget_state_reset(s)\ + if ((*(s)) & NK_WIDGET_STATE_MODIFIED)\ + (*(s)) = NK_WIDGET_STATE_INACTIVE|NK_WIDGET_STATE_MODIFIED;\ + else (*(s)) = NK_WIDGET_STATE_INACTIVE; + +/* math */ +#ifndef NK_INV_SQRT +NK_LIB float nk_inv_sqrt(float n); +#endif +#ifndef NK_SIN +NK_LIB float nk_sin(float x); +#endif +#ifndef NK_COS +NK_LIB float nk_cos(float x); +#endif +NK_LIB nk_uint nk_round_up_pow2(nk_uint v); +NK_LIB struct nk_rect nk_shrink_rect(struct nk_rect r, float amount); +NK_LIB struct nk_rect nk_pad_rect(struct nk_rect r, struct nk_vec2 pad); +NK_LIB void nk_unify(struct nk_rect *clip, const struct nk_rect *a, float x0, float y0, float x1, float y1); +NK_LIB double nk_pow(double x, int n); +NK_LIB int nk_ifloord(double x); +NK_LIB int nk_ifloorf(float x); +NK_LIB int nk_iceilf(float x); +NK_LIB int nk_log10(double n); + +/* util */ +enum {NK_DO_NOT_STOP_ON_NEW_LINE, NK_STOP_ON_NEW_LINE}; +NK_LIB nk_bool nk_is_lower(int c); +NK_LIB nk_bool nk_is_upper(int c); +NK_LIB int nk_to_upper(int c); +NK_LIB int nk_to_lower(int c); + +#ifndef NK_MEMCPY +NK_LIB void* nk_memcopy(void *dst, const void *src, nk_size n); +#endif +#ifndef NK_MEMSET +NK_LIB void nk_memset(void *ptr, int c0, nk_size size); +#endif +NK_LIB void nk_zero(void *ptr, nk_size size); +NK_LIB char *nk_itoa(char *s, long n); +NK_LIB int nk_string_float_limit(char *string, int prec); +#ifndef NK_DTOA +NK_LIB char *nk_dtoa(char *s, double n); +#endif +NK_LIB int nk_text_clamp(const struct nk_user_font *font, const char *text, int text_len, float space, int *glyphs, float *text_width, nk_rune *sep_list, int sep_count); +NK_LIB struct nk_vec2 nk_text_calculate_text_bounds(const struct nk_user_font *font, const char *begin, int byte_len, float row_height, const char **remaining, struct nk_vec2 *out_offset, int *glyphs, int op); +#ifdef NK_INCLUDE_STANDARD_VARARGS +NK_LIB int nk_strfmt(char *buf, int buf_size, const char *fmt, va_list args); +#endif +#ifdef NK_INCLUDE_STANDARD_IO +NK_LIB char *nk_file_load(const char* path, nk_size* siz, struct nk_allocator *alloc); +#endif + +/* buffer */ +#ifdef NK_INCLUDE_DEFAULT_ALLOCATOR +NK_LIB void* nk_malloc(nk_handle unused, void *old,nk_size size); +NK_LIB void nk_mfree(nk_handle unused, void *ptr); +#endif +NK_LIB void* nk_buffer_align(void *unaligned, nk_size align, nk_size *alignment, enum nk_buffer_allocation_type type); +NK_LIB void* nk_buffer_alloc(struct nk_buffer *b, enum nk_buffer_allocation_type type, nk_size size, nk_size align); +NK_LIB void* nk_buffer_realloc(struct nk_buffer *b, nk_size capacity, nk_size *size); + +/* draw */ +NK_LIB void nk_command_buffer_init(struct nk_command_buffer *cb, struct nk_buffer *b, enum nk_command_clipping clip); +NK_LIB void nk_command_buffer_reset(struct nk_command_buffer *b); +NK_LIB void* nk_command_buffer_push(struct nk_command_buffer* b, enum nk_command_type t, nk_size size); +NK_LIB void nk_draw_symbol(struct nk_command_buffer *out, enum nk_symbol_type type, struct nk_rect content, struct nk_color background, struct nk_color foreground, float border_width, const struct nk_user_font *font); + +/* buffering */ +NK_LIB void nk_start_buffer(struct nk_context *ctx, struct nk_command_buffer *b); +NK_LIB void nk_start(struct nk_context *ctx, struct nk_window *win); +NK_LIB void nk_start_popup(struct nk_context *ctx, struct nk_window *win); +NK_LIB void nk_finish_popup(struct nk_context *ctx, struct nk_window*); +NK_LIB void nk_finish_buffer(struct nk_context *ctx, struct nk_command_buffer *b); +NK_LIB void nk_finish(struct nk_context *ctx, struct nk_window *w); +NK_LIB void nk_build(struct nk_context *ctx); + +/* text editor */ +NK_LIB void nk_textedit_clear_state(struct nk_text_edit *state, enum nk_text_edit_type type, nk_plugin_filter filter); +NK_LIB void nk_textedit_click(struct nk_text_edit *state, float x, float y, const struct nk_user_font *font, float row_height); +NK_LIB void nk_textedit_drag(struct nk_text_edit *state, float x, float y, const struct nk_user_font *font, float row_height); +NK_LIB void nk_textedit_key(struct nk_text_edit *state, enum nk_keys key, int shift_mod, const struct nk_user_font *font, float row_height); + +/* window */ +enum nk_window_insert_location { + NK_INSERT_BACK, /* inserts window into the back of list (front of screen) */ + NK_INSERT_FRONT /* inserts window into the front of list (back of screen) */ +}; +NK_LIB void *nk_create_window(struct nk_context *ctx); +NK_LIB void nk_remove_window(struct nk_context*, struct nk_window*); +NK_LIB void nk_free_window(struct nk_context *ctx, struct nk_window *win); +NK_LIB struct nk_window *nk_find_window(struct nk_context *ctx, nk_hash hash, const char *name); +NK_LIB void nk_insert_window(struct nk_context *ctx, struct nk_window *win, enum nk_window_insert_location loc); + +/* pool */ +NK_LIB void nk_pool_init(struct nk_pool *pool, struct nk_allocator *alloc, unsigned int capacity); +NK_LIB void nk_pool_free(struct nk_pool *pool); +NK_LIB void nk_pool_init_fixed(struct nk_pool *pool, void *memory, nk_size size); +NK_LIB struct nk_page_element *nk_pool_alloc(struct nk_pool *pool); + +/* page-element */ +NK_LIB struct nk_page_element* nk_create_page_element(struct nk_context *ctx); +NK_LIB void nk_link_page_element_into_freelist(struct nk_context *ctx, struct nk_page_element *elem); +NK_LIB void nk_free_page_element(struct nk_context *ctx, struct nk_page_element *elem); + +/* table */ +NK_LIB struct nk_table* nk_create_table(struct nk_context *ctx); +NK_LIB void nk_remove_table(struct nk_window *win, struct nk_table *tbl); +NK_LIB void nk_free_table(struct nk_context *ctx, struct nk_table *tbl); +NK_LIB void nk_push_table(struct nk_window *win, struct nk_table *tbl); +NK_LIB nk_uint *nk_add_value(struct nk_context *ctx, struct nk_window *win, nk_hash name, nk_uint value); +NK_LIB nk_uint *nk_find_value(struct nk_window *win, nk_hash name); + +/* panel */ +NK_LIB void *nk_create_panel(struct nk_context *ctx); +NK_LIB void nk_free_panel(struct nk_context*, struct nk_panel *pan); +NK_LIB nk_bool nk_panel_has_header(nk_flags flags, const char *title); +NK_LIB struct nk_vec2 nk_panel_get_padding(const struct nk_style *style, enum nk_panel_type type); +NK_LIB float nk_panel_get_border(const struct nk_style *style, nk_flags flags, enum nk_panel_type type); +NK_LIB struct nk_color nk_panel_get_border_color(const struct nk_style *style, enum nk_panel_type type); +NK_LIB nk_bool nk_panel_is_sub(enum nk_panel_type type); +NK_LIB nk_bool nk_panel_is_nonblock(enum nk_panel_type type); +NK_LIB nk_bool nk_panel_begin(struct nk_context *ctx, const char *title, enum nk_panel_type panel_type); +NK_LIB void nk_panel_end(struct nk_context *ctx); + +/* layout */ +NK_LIB float nk_layout_row_calculate_usable_space(const struct nk_style *style, enum nk_panel_type type, float total_space, int columns); +NK_LIB void nk_panel_layout(const struct nk_context *ctx, struct nk_window *win, float height, int cols); +NK_LIB void nk_row_layout(struct nk_context *ctx, enum nk_layout_format fmt, float height, int cols, int width); +NK_LIB void nk_panel_alloc_row(const struct nk_context *ctx, struct nk_window *win); +NK_LIB void nk_layout_widget_space(struct nk_rect *bounds, const struct nk_context *ctx, struct nk_window *win, int modify); +NK_LIB void nk_panel_alloc_space(struct nk_rect *bounds, const struct nk_context *ctx); +NK_LIB void nk_layout_peek(struct nk_rect *bounds, struct nk_context *ctx); + +/* popup */ +NK_LIB nk_bool nk_nonblock_begin(struct nk_context *ctx, nk_flags flags, struct nk_rect body, struct nk_rect header, enum nk_panel_type panel_type); + +/* text */ +struct nk_text { + struct nk_vec2 padding; + struct nk_color background; + struct nk_color text; +}; +NK_LIB void nk_widget_text(struct nk_command_buffer *o, struct nk_rect b, const char *string, int len, const struct nk_text *t, nk_flags a, const struct nk_user_font *f); +NK_LIB void nk_widget_text_wrap(struct nk_command_buffer *o, struct nk_rect b, const char *string, int len, const struct nk_text *t, const struct nk_user_font *f); + +/* button */ +NK_LIB nk_bool nk_button_behavior(nk_flags *state, struct nk_rect r, const struct nk_input *i, enum nk_button_behavior behavior); +NK_LIB const struct nk_style_item* nk_draw_button(struct nk_command_buffer *out, const struct nk_rect *bounds, nk_flags state, const struct nk_style_button *style); +NK_LIB nk_bool nk_do_button(nk_flags *state, struct nk_command_buffer *out, struct nk_rect r, const struct nk_style_button *style, const struct nk_input *in, enum nk_button_behavior behavior, struct nk_rect *content); +NK_LIB void nk_draw_button_text(struct nk_command_buffer *out, const struct nk_rect *bounds, const struct nk_rect *content, nk_flags state, const struct nk_style_button *style, const char *txt, int len, nk_flags text_alignment, const struct nk_user_font *font); +NK_LIB nk_bool nk_do_button_text(nk_flags *state, struct nk_command_buffer *out, struct nk_rect bounds, const char *string, int len, nk_flags align, enum nk_button_behavior behavior, const struct nk_style_button *style, const struct nk_input *in, const struct nk_user_font *font); +NK_LIB void nk_draw_button_symbol(struct nk_command_buffer *out, const struct nk_rect *bounds, const struct nk_rect *content, nk_flags state, const struct nk_style_button *style, enum nk_symbol_type type, const struct nk_user_font *font); +NK_LIB nk_bool nk_do_button_symbol(nk_flags *state, struct nk_command_buffer *out, struct nk_rect bounds, enum nk_symbol_type symbol, enum nk_button_behavior behavior, const struct nk_style_button *style, const struct nk_input *in, const struct nk_user_font *font); +NK_LIB void nk_draw_button_image(struct nk_command_buffer *out, const struct nk_rect *bounds, const struct nk_rect *content, nk_flags state, const struct nk_style_button *style, const struct nk_image *img); +NK_LIB nk_bool nk_do_button_image(nk_flags *state, struct nk_command_buffer *out, struct nk_rect bounds, struct nk_image img, enum nk_button_behavior b, const struct nk_style_button *style, const struct nk_input *in); +NK_LIB void nk_draw_button_text_symbol(struct nk_command_buffer *out, const struct nk_rect *bounds, const struct nk_rect *label, const struct nk_rect *symbol, nk_flags state, const struct nk_style_button *style, const char *str, int len, enum nk_symbol_type type, const struct nk_user_font *font); +NK_LIB nk_bool nk_do_button_text_symbol(nk_flags *state, struct nk_command_buffer *out, struct nk_rect bounds, enum nk_symbol_type symbol, const char *str, int len, nk_flags align, enum nk_button_behavior behavior, const struct nk_style_button *style, const struct nk_user_font *font, const struct nk_input *in); +NK_LIB void nk_draw_button_text_image(struct nk_command_buffer *out, const struct nk_rect *bounds, const struct nk_rect *label, const struct nk_rect *image, nk_flags state, const struct nk_style_button *style, const char *str, int len, const struct nk_user_font *font, const struct nk_image *img); +NK_LIB nk_bool nk_do_button_text_image(nk_flags *state, struct nk_command_buffer *out, struct nk_rect bounds, struct nk_image img, const char* str, int len, nk_flags align, enum nk_button_behavior behavior, const struct nk_style_button *style, const struct nk_user_font *font, const struct nk_input *in); + +/* toggle */ +enum nk_toggle_type { + NK_TOGGLE_CHECK, + NK_TOGGLE_OPTION +}; +NK_LIB nk_bool nk_toggle_behavior(const struct nk_input *in, struct nk_rect select, nk_flags *state, nk_bool active); +NK_LIB void nk_draw_checkbox(struct nk_command_buffer *out, nk_flags state, const struct nk_style_toggle *style, nk_bool active, const struct nk_rect *label, const struct nk_rect *selector, const struct nk_rect *cursors, const char *string, int len, const struct nk_user_font *font); +NK_LIB void nk_draw_option(struct nk_command_buffer *out, nk_flags state, const struct nk_style_toggle *style, nk_bool active, const struct nk_rect *label, const struct nk_rect *selector, const struct nk_rect *cursors, const char *string, int len, const struct nk_user_font *font); +NK_LIB nk_bool nk_do_toggle(nk_flags *state, struct nk_command_buffer *out, struct nk_rect r, nk_bool *active, const char *str, int len, enum nk_toggle_type type, const struct nk_style_toggle *style, const struct nk_input *in, const struct nk_user_font *font); + +/* progress */ +NK_LIB nk_size nk_progress_behavior(nk_flags *state, struct nk_input *in, struct nk_rect r, struct nk_rect cursor, nk_size max, nk_size value, nk_bool modifiable); +NK_LIB void nk_draw_progress(struct nk_command_buffer *out, nk_flags state, const struct nk_style_progress *style, const struct nk_rect *bounds, const struct nk_rect *scursor, nk_size value, nk_size max); +NK_LIB nk_size nk_do_progress(nk_flags *state, struct nk_command_buffer *out, struct nk_rect bounds, nk_size value, nk_size max, nk_bool modifiable, const struct nk_style_progress *style, struct nk_input *in); + +/* slider */ +NK_LIB float nk_slider_behavior(nk_flags *state, struct nk_rect *logical_cursor, struct nk_rect *visual_cursor, struct nk_input *in, struct nk_rect bounds, float slider_min, float slider_max, float slider_value, float slider_step, float slider_steps); +NK_LIB void nk_draw_slider(struct nk_command_buffer *out, nk_flags state, const struct nk_style_slider *style, const struct nk_rect *bounds, const struct nk_rect *visual_cursor, float min, float value, float max); +NK_LIB float nk_do_slider(nk_flags *state, struct nk_command_buffer *out, struct nk_rect bounds, float min, float val, float max, float step, const struct nk_style_slider *style, struct nk_input *in, const struct nk_user_font *font); + +/* scrollbar */ +NK_LIB float nk_scrollbar_behavior(nk_flags *state, struct nk_input *in, int has_scrolling, const struct nk_rect *scroll, const struct nk_rect *cursor, const struct nk_rect *empty0, const struct nk_rect *empty1, float scroll_offset, float target, float scroll_step, enum nk_orientation o); +NK_LIB void nk_draw_scrollbar(struct nk_command_buffer *out, nk_flags state, const struct nk_style_scrollbar *style, const struct nk_rect *bounds, const struct nk_rect *scroll); +NK_LIB float nk_do_scrollbarv(nk_flags *state, struct nk_command_buffer *out, struct nk_rect scroll, int has_scrolling, float offset, float target, float step, float button_pixel_inc, const struct nk_style_scrollbar *style, struct nk_input *in, const struct nk_user_font *font); +NK_LIB float nk_do_scrollbarh(nk_flags *state, struct nk_command_buffer *out, struct nk_rect scroll, int has_scrolling, float offset, float target, float step, float button_pixel_inc, const struct nk_style_scrollbar *style, struct nk_input *in, const struct nk_user_font *font); + +/* selectable */ +NK_LIB void nk_draw_selectable(struct nk_command_buffer *out, nk_flags state, const struct nk_style_selectable *style, nk_bool active, const struct nk_rect *bounds, const struct nk_rect *icon, const struct nk_image *img, enum nk_symbol_type sym, const char *string, int len, nk_flags align, const struct nk_user_font *font); +NK_LIB nk_bool nk_do_selectable(nk_flags *state, struct nk_command_buffer *out, struct nk_rect bounds, const char *str, int len, nk_flags align, nk_bool *value, const struct nk_style_selectable *style, const struct nk_input *in, const struct nk_user_font *font); +NK_LIB nk_bool nk_do_selectable_image(nk_flags *state, struct nk_command_buffer *out, struct nk_rect bounds, const char *str, int len, nk_flags align, nk_bool *value, const struct nk_image *img, const struct nk_style_selectable *style, const struct nk_input *in, const struct nk_user_font *font); + +/* edit */ +NK_LIB void nk_edit_draw_text(struct nk_command_buffer *out, const struct nk_style_edit *style, float pos_x, float pos_y, float x_offset, const char *text, int byte_len, float row_height, const struct nk_user_font *font, struct nk_color background, struct nk_color foreground, nk_bool is_selected); +NK_LIB nk_flags nk_do_edit(nk_flags *state, struct nk_command_buffer *out, struct nk_rect bounds, nk_flags flags, nk_plugin_filter filter, struct nk_text_edit *edit, const struct nk_style_edit *style, struct nk_input *in, const struct nk_user_font *font); + +/* color-picker */ +NK_LIB nk_bool nk_color_picker_behavior(nk_flags *state, const struct nk_rect *bounds, const struct nk_rect *matrix, const struct nk_rect *hue_bar, const struct nk_rect *alpha_bar, struct nk_colorf *color, const struct nk_input *in); +NK_LIB void nk_draw_color_picker(struct nk_command_buffer *o, const struct nk_rect *matrix, const struct nk_rect *hue_bar, const struct nk_rect *alpha_bar, struct nk_colorf col); +NK_LIB nk_bool nk_do_color_picker(nk_flags *state, struct nk_command_buffer *out, struct nk_colorf *col, enum nk_color_format fmt, struct nk_rect bounds, struct nk_vec2 padding, const struct nk_input *in, const struct nk_user_font *font); + +/* property */ +enum nk_property_status { + NK_PROPERTY_DEFAULT, + NK_PROPERTY_EDIT, + NK_PROPERTY_DRAG +}; +enum nk_property_filter { + NK_FILTER_INT, + NK_FILTER_FLOAT +}; +enum nk_property_kind { + NK_PROPERTY_INT, + NK_PROPERTY_FLOAT, + NK_PROPERTY_DOUBLE +}; +union nk_property { + int i; + float f; + double d; +}; +struct nk_property_variant { + enum nk_property_kind kind; + union nk_property value; + union nk_property min_value; + union nk_property max_value; + union nk_property step; +}; +NK_LIB struct nk_property_variant nk_property_variant_int(int value, int min_value, int max_value, int step); +NK_LIB struct nk_property_variant nk_property_variant_float(float value, float min_value, float max_value, float step); +NK_LIB struct nk_property_variant nk_property_variant_double(double value, double min_value, double max_value, double step); + +NK_LIB void nk_drag_behavior(nk_flags *state, const struct nk_input *in, struct nk_rect drag, struct nk_property_variant *variant, float inc_per_pixel); +NK_LIB void nk_property_behavior(nk_flags *ws, const struct nk_input *in, struct nk_rect property, struct nk_rect label, struct nk_rect edit, struct nk_rect empty, int *state, struct nk_property_variant *variant, float inc_per_pixel); +NK_LIB void nk_draw_property(struct nk_command_buffer *out, const struct nk_style_property *style, const struct nk_rect *bounds, const struct nk_rect *label, nk_flags state, const char *name, int len, const struct nk_user_font *font); +NK_LIB void nk_do_property(nk_flags *ws, struct nk_command_buffer *out, struct nk_rect property, const char *name, struct nk_property_variant *variant, float inc_per_pixel, char *buffer, int *len, int *state, int *cursor, int *select_begin, int *select_end, const struct nk_style_property *style, enum nk_property_filter filter, struct nk_input *in, const struct nk_user_font *font, struct nk_text_edit *text_edit, enum nk_button_behavior behavior); +NK_LIB void nk_property(struct nk_context *ctx, const char *name, struct nk_property_variant *variant, float inc_per_pixel, const enum nk_property_filter filter); + +#ifdef NK_INCLUDE_FONT_BAKING + +#define STB_RECT_PACK_IMPLEMENTATION +#define STB_TRUETYPE_IMPLEMENTATION + +/* Allow consumer to define own STBTT_malloc/STBTT_free, and use the font atlas' allocator otherwise */ +#ifndef STBTT_malloc +static void* +nk_stbtt_malloc(nk_size size, void *user_data) { + struct nk_allocator *alloc = (struct nk_allocator *) user_data; + return alloc->alloc(alloc->userdata, 0, size); +} + +static void +nk_stbtt_free(void *ptr, void *user_data) { + struct nk_allocator *alloc = (struct nk_allocator *) user_data; + alloc->free(alloc->userdata, ptr); +} + +#define STBTT_malloc(x,u) nk_stbtt_malloc(x,u) +#define STBTT_free(x,u) nk_stbtt_free(x,u) + +#endif /* STBTT_malloc */ + +#endif /* NK_INCLUDE_FONT_BAKING */ + +#endif + + + + + +/* =============================================================== + * + * MATH + * + * ===============================================================*/ +/*/// ### Math +/// Since nuklear is supposed to work on all systems providing floating point +/// math without any dependencies I also had to implement my own math functions +/// for sqrt, sin and cos. Since the actual highly accurate implementations for +/// the standard library functions are quite complex and I do not need high +/// precision for my use cases I use approximations. +/// +/// Sqrt +/// ---- +/// For square root nuklear uses the famous fast inverse square root: +/// https://en.wikipedia.org/wiki/Fast_inverse_square_root with +/// slightly tweaked magic constant. While on today's hardware it is +/// probably not faster it is still fast and accurate enough for +/// nuklear's use cases. IMPORTANT: this requires float format IEEE 754 +/// +/// Sine/Cosine +/// ----------- +/// All constants inside both function are generated Remez's minimax +/// approximations for value range 0...2*PI. The reason why I decided to +/// approximate exactly that range is that nuklear only needs sine and +/// cosine to generate circles which only requires that exact range. +/// In addition I used Remez instead of Taylor for additional precision: +/// www.lolengine.net/blog/2011/12/21/better-function-approximations. +/// +/// The tool I used to generate constants for both sine and cosine +/// (it can actually approximate a lot more functions) can be +/// found here: www.lolengine.net/wiki/oss/lolremez +*/ +#ifndef NK_INV_SQRT +#define NK_INV_SQRT nk_inv_sqrt +NK_LIB float +nk_inv_sqrt(float n) +{ + float x2; + const float threehalfs = 1.5f; + union {nk_uint i; float f;} conv = {0}; + conv.f = n; + x2 = n * 0.5f; + conv.i = 0x5f375A84 - (conv.i >> 1); + conv.f = conv.f * (threehalfs - (x2 * conv.f * conv.f)); + return conv.f; +} +#endif +#ifndef NK_SIN +#define NK_SIN nk_sin +NK_LIB float +nk_sin(float x) +{ + NK_STORAGE const float a0 = +1.91059300966915117e-31f; + NK_STORAGE const float a1 = +1.00086760103908896f; + NK_STORAGE const float a2 = -1.21276126894734565e-2f; + NK_STORAGE const float a3 = -1.38078780785773762e-1f; + NK_STORAGE const float a4 = -2.67353392911981221e-2f; + NK_STORAGE const float a5 = +2.08026600266304389e-2f; + NK_STORAGE const float a6 = -3.03996055049204407e-3f; + NK_STORAGE const float a7 = +1.38235642404333740e-4f; + return a0 + x*(a1 + x*(a2 + x*(a3 + x*(a4 + x*(a5 + x*(a6 + x*a7)))))); +} +#endif +#ifndef NK_COS +#define NK_COS nk_cos +NK_LIB float +nk_cos(float x) +{ + /* New implementation. Also generated using lolremez. */ + /* Old version significantly deviated from expected results. */ + NK_STORAGE const float a0 = 9.9995999154986614e-1f; + NK_STORAGE const float a1 = 1.2548995793001028e-3f; + NK_STORAGE const float a2 = -5.0648546280678015e-1f; + NK_STORAGE const float a3 = 1.2942246466519995e-2f; + NK_STORAGE const float a4 = 2.8668384702547972e-2f; + NK_STORAGE const float a5 = 7.3726485210586547e-3f; + NK_STORAGE const float a6 = -3.8510875386947414e-3f; + NK_STORAGE const float a7 = 4.7196604604366623e-4f; + NK_STORAGE const float a8 = -1.8776444013090451e-5f; + return a0 + x*(a1 + x*(a2 + x*(a3 + x*(a4 + x*(a5 + x*(a6 + x*(a7 + x*a8))))))); +} +#endif +NK_LIB nk_uint +nk_round_up_pow2(nk_uint v) +{ + v--; + v |= v >> 1; + v |= v >> 2; + v |= v >> 4; + v |= v >> 8; + v |= v >> 16; + v++; + return v; +} +NK_LIB double +nk_pow(double x, int n) +{ + /* check the sign of n */ + double r = 1; + int plus = n >= 0; + n = (plus) ? n : -n; + while (n > 0) { + if ((n & 1) == 1) + r *= x; + n /= 2; + x *= x; + } + return plus ? r : 1.0 / r; +} +NK_LIB int +nk_ifloord(double x) +{ + x = (double)((int)x - ((x < 0.0) ? 1 : 0)); + return (int)x; +} +NK_LIB int +nk_ifloorf(float x) +{ + x = (float)((int)x - ((x < 0.0f) ? 1 : 0)); + return (int)x; +} +NK_LIB int +nk_iceilf(float x) +{ + if (x >= 0) { + int i = (int)x; + return (x > i) ? i+1: i; + } else { + int t = (int)x; + float r = x - (float)t; + return (r > 0.0f) ? t+1: t; + } +} +NK_LIB int +nk_log10(double n) +{ + int neg; + int ret; + int exp = 0; + + neg = (n < 0) ? 1 : 0; + ret = (neg) ? (int)-n : (int)n; + while ((ret / 10) > 0) { + ret /= 10; + exp++; + } + if (neg) exp = -exp; + return exp; +} +NK_API struct nk_rect +nk_get_null_rect(void) +{ + return nk_null_rect; +} +NK_API struct nk_rect +nk_rect(float x, float y, float w, float h) +{ + struct nk_rect r; + r.x = x; r.y = y; + r.w = w; r.h = h; + return r; +} +NK_API struct nk_rect +nk_recti(int x, int y, int w, int h) +{ + struct nk_rect r; + r.x = (float)x; + r.y = (float)y; + r.w = (float)w; + r.h = (float)h; + return r; +} +NK_API struct nk_rect +nk_recta(struct nk_vec2 pos, struct nk_vec2 size) +{ + return nk_rect(pos.x, pos.y, size.x, size.y); +} +NK_API struct nk_rect +nk_rectv(const float *r) +{ + return nk_rect(r[0], r[1], r[2], r[3]); +} +NK_API struct nk_rect +nk_rectiv(const int *r) +{ + return nk_recti(r[0], r[1], r[2], r[3]); +} +NK_API struct nk_vec2 +nk_rect_pos(struct nk_rect r) +{ + struct nk_vec2 ret; + ret.x = r.x; ret.y = r.y; + return ret; +} +NK_API struct nk_vec2 +nk_rect_size(struct nk_rect r) +{ + struct nk_vec2 ret; + ret.x = r.w; ret.y = r.h; + return ret; +} +NK_LIB struct nk_rect +nk_shrink_rect(struct nk_rect r, float amount) +{ + struct nk_rect res; + r.w = NK_MAX(r.w, 2 * amount); + r.h = NK_MAX(r.h, 2 * amount); + res.x = r.x + amount; + res.y = r.y + amount; + res.w = r.w - 2 * amount; + res.h = r.h - 2 * amount; + return res; +} +NK_LIB struct nk_rect +nk_pad_rect(struct nk_rect r, struct nk_vec2 pad) +{ + r.w = NK_MAX(r.w, 2 * pad.x); + r.h = NK_MAX(r.h, 2 * pad.y); + r.x += pad.x; r.y += pad.y; + r.w -= 2 * pad.x; + r.h -= 2 * pad.y; + return r; +} +NK_API struct nk_vec2 +nk_vec2(float x, float y) +{ + struct nk_vec2 ret; + ret.x = x; ret.y = y; + return ret; +} +NK_API struct nk_vec2 +nk_vec2i(int x, int y) +{ + struct nk_vec2 ret; + ret.x = (float)x; + ret.y = (float)y; + return ret; +} +NK_API struct nk_vec2 +nk_vec2v(const float *v) +{ + return nk_vec2(v[0], v[1]); +} +NK_API struct nk_vec2 +nk_vec2iv(const int *v) +{ + return nk_vec2i(v[0], v[1]); +} +NK_LIB void +nk_unify(struct nk_rect *clip, const struct nk_rect *a, float x0, float y0, + float x1, float y1) +{ + NK_ASSERT(a); + NK_ASSERT(clip); + clip->x = NK_MAX(a->x, x0); + clip->y = NK_MAX(a->y, y0); + clip->w = NK_MIN(a->x + a->w, x1) - clip->x; + clip->h = NK_MIN(a->y + a->h, y1) - clip->y; + clip->w = NK_MAX(0, clip->w); + clip->h = NK_MAX(0, clip->h); +} + +NK_API void +nk_triangle_from_direction(struct nk_vec2 *result, struct nk_rect r, + float pad_x, float pad_y, enum nk_heading direction) +{ + float w_half, h_half; + NK_ASSERT(result); + + r.w = NK_MAX(2 * pad_x, r.w); + r.h = NK_MAX(2 * pad_y, r.h); + r.w = r.w - 2 * pad_x; + r.h = r.h - 2 * pad_y; + + r.x = r.x + pad_x; + r.y = r.y + pad_y; + + w_half = r.w / 2.0f; + h_half = r.h / 2.0f; + + if (direction == NK_UP) { + result[0] = nk_vec2(r.x + w_half, r.y); + result[1] = nk_vec2(r.x + r.w, r.y + r.h); + result[2] = nk_vec2(r.x, r.y + r.h); + } else if (direction == NK_RIGHT) { + result[0] = nk_vec2(r.x, r.y); + result[1] = nk_vec2(r.x + r.w, r.y + h_half); + result[2] = nk_vec2(r.x, r.y + r.h); + } else if (direction == NK_DOWN) { + result[0] = nk_vec2(r.x, r.y); + result[1] = nk_vec2(r.x + r.w, r.y); + result[2] = nk_vec2(r.x + w_half, r.y + r.h); + } else { + result[0] = nk_vec2(r.x, r.y + h_half); + result[1] = nk_vec2(r.x + r.w, r.y); + result[2] = nk_vec2(r.x + r.w, r.y + r.h); + } +} + + + + + +/* =============================================================== + * + * UTIL + * + * ===============================================================*/ +NK_INTERN int nk_str_match_here(const char *regexp, const char *text); +NK_INTERN int nk_str_match_star(int c, const char *regexp, const char *text); +NK_LIB nk_bool nk_is_lower(int c) {return (c >= 'a' && c <= 'z') || (c >= 0xE0 && c <= 0xFF);} +NK_LIB nk_bool nk_is_upper(int c){return (c >= 'A' && c <= 'Z') || (c >= 0xC0 && c <= 0xDF);} +NK_LIB int nk_to_upper(int c) {return (c >= 'a' && c <= 'z') ? (c - ('a' - 'A')) : c;} +NK_LIB int nk_to_lower(int c) {return (c >= 'A' && c <= 'Z') ? (c - ('a' + 'A')) : c;} + +#ifndef NK_MEMCPY +#define NK_MEMCPY nk_memcopy +NK_LIB void* +nk_memcopy(void *dst0, const void *src0, nk_size length) +{ + nk_ptr t; + char *dst = (char*)dst0; + const char *src = (const char*)src0; + if (length == 0 || dst == src) + goto done; + + #define nk_word int + #define nk_wsize sizeof(nk_word) + #define nk_wmask (nk_wsize-1) + #define NK_TLOOP(s) if (t) NK_TLOOP1(s) + #define NK_TLOOP1(s) do { s; } while (--t) + + if (dst < src) { + t = (nk_ptr)src; /* only need low bits */ + if ((t | (nk_ptr)dst) & nk_wmask) { + if ((t ^ (nk_ptr)dst) & nk_wmask || length < nk_wsize) + t = length; + else + t = nk_wsize - (t & nk_wmask); + length -= t; + NK_TLOOP1(*dst++ = *src++); + } + t = length / nk_wsize; + NK_TLOOP(*(nk_word*)(void*)dst = *(const nk_word*)(const void*)src; + src += nk_wsize; dst += nk_wsize); + t = length & nk_wmask; + NK_TLOOP(*dst++ = *src++); + } else { + src += length; + dst += length; + t = (nk_ptr)src; + if ((t | (nk_ptr)dst) & nk_wmask) { + if ((t ^ (nk_ptr)dst) & nk_wmask || length <= nk_wsize) + t = length; + else + t &= nk_wmask; + length -= t; + NK_TLOOP1(*--dst = *--src); + } + t = length / nk_wsize; + NK_TLOOP(src -= nk_wsize; dst -= nk_wsize; + *(nk_word*)(void*)dst = *(const nk_word*)(const void*)src); + t = length & nk_wmask; + NK_TLOOP(*--dst = *--src); + } + #undef nk_word + #undef nk_wsize + #undef nk_wmask + #undef NK_TLOOP + #undef NK_TLOOP1 +done: + return (dst0); +} +#endif +#ifndef NK_MEMSET +#define NK_MEMSET nk_memset +NK_LIB void +nk_memset(void *ptr, int c0, nk_size size) +{ + #define nk_word unsigned + #define nk_wsize sizeof(nk_word) + #define nk_wmask (nk_wsize - 1) + nk_byte *dst = (nk_byte*)ptr; + unsigned c = 0; + nk_size t = 0; + + if ((c = (nk_byte)c0) != 0) { + c = (c << 8) | c; /* at least 16-bits */ + if (sizeof(unsigned int) > 2) + c = (c << 16) | c; /* at least 32-bits*/ + } + + /* too small of a word count */ + dst = (nk_byte*)ptr; + if (size < 3 * nk_wsize) { + while (size--) *dst++ = (nk_byte)c0; + return; + } + + /* align destination */ + if ((t = NK_PTR_TO_UINT(dst) & nk_wmask) != 0) { + t = nk_wsize -t; + size -= t; + do { + *dst++ = (nk_byte)c0; + } while (--t != 0); + } + + /* fill word */ + t = size / nk_wsize; + do { + *(nk_word*)((void*)dst) = c; + dst += nk_wsize; + } while (--t != 0); + + /* fill trailing bytes */ + t = (size & nk_wmask); + if (t != 0) { + do { + *dst++ = (nk_byte)c0; + } while (--t != 0); + } + + #undef nk_word + #undef nk_wsize + #undef nk_wmask +} +#endif +NK_LIB void +nk_zero(void *ptr, nk_size size) +{ + NK_ASSERT(ptr); + NK_MEMSET(ptr, 0, size); +} +NK_API int +nk_strlen(const char *str) +{ + int siz = 0; + NK_ASSERT(str); + while (str && *str++ != '\0') siz++; + return siz; +} +NK_API int +nk_strtoi(const char *str, const char **endptr) +{ + int neg = 1; + const char *p = str; + int value = 0; + + NK_ASSERT(str); + if (!str) return 0; + + /* skip whitespace */ + while (*p == ' ') p++; + if (*p == '-') { + neg = -1; + p++; + } + while (*p && *p >= '0' && *p <= '9') { + value = value * 10 + (int) (*p - '0'); + p++; + } + if (endptr) + *endptr = p; + return neg*value; +} +NK_API double +nk_strtod(const char *str, const char **endptr) +{ + double m; + double neg = 1.0; + const char *p = str; + double value = 0; + double number = 0; + + NK_ASSERT(str); + if (!str) return 0; + + /* skip whitespace */ + while (*p == ' ') p++; + if (*p == '-') { + neg = -1.0; + p++; + } + + while (*p && *p != '.' && *p != 'e') { + value = value * 10.0 + (double) (*p - '0'); + p++; + } + + if (*p == '.') { + p++; + for(m = 0.1; *p && *p != 'e'; p++ ) { + value = value + (double) (*p - '0') * m; + m *= 0.1; + } + } + if (*p == 'e') { + int i, pow, div; + p++; + if (*p == '-') { + div = nk_true; + p++; + } else if (*p == '+') { + div = nk_false; + p++; + } else div = nk_false; + + for (pow = 0; *p; p++) + pow = pow * 10 + (int) (*p - '0'); + + for (m = 1.0, i = 0; i < pow; i++) + m *= 10.0; + + if (div) + value /= m; + else value *= m; + } + number = value * neg; + if (endptr) + *endptr = p; + return number; +} +NK_API float +nk_strtof(const char *str, const char **endptr) +{ + float float_value; + double double_value; + double_value = NK_STRTOD(str, endptr); + float_value = (float)double_value; + return float_value; +} +NK_API int +nk_stricmp(const char *s1, const char *s2) +{ + nk_int c1,c2,d; + do { + c1 = *s1++; + c2 = *s2++; + d = c1 - c2; + while (d) { + if (c1 <= 'Z' && c1 >= 'A') { + d += ('a' - 'A'); + if (!d) break; + } + if (c2 <= 'Z' && c2 >= 'A') { + d -= ('a' - 'A'); + if (!d) break; + } + return ((d >= 0) << 1) - 1; + } + } while (c1); + return 0; +} +NK_API int +nk_stricmpn(const char *s1, const char *s2, int n) +{ + int c1,c2,d; + NK_ASSERT(n >= 0); + do { + c1 = *s1++; + c2 = *s2++; + if (!n--) return 0; + + d = c1 - c2; + while (d) { + if (c1 <= 'Z' && c1 >= 'A') { + d += ('a' - 'A'); + if (!d) break; + } + if (c2 <= 'Z' && c2 >= 'A') { + d -= ('a' - 'A'); + if (!d) break; + } + return ((d >= 0) << 1) - 1; + } + } while (c1); + return 0; +} +NK_INTERN int +nk_str_match_here(const char *regexp, const char *text) +{ + if (regexp[0] == '\0') + return 1; + if (regexp[1] == '*') + return nk_str_match_star(regexp[0], regexp+2, text); + if (regexp[0] == '$' && regexp[1] == '\0') + return *text == '\0'; + if (*text!='\0' && (regexp[0]=='.' || regexp[0]==*text)) + return nk_str_match_here(regexp+1, text+1); + return 0; +} +NK_INTERN int +nk_str_match_star(int c, const char *regexp, const char *text) +{ + do {/* a '* matches zero or more instances */ + if (nk_str_match_here(regexp, text)) + return 1; + } while (*text != '\0' && (*text++ == c || c == '.')); + return 0; +} +NK_API int +nk_strfilter(const char *text, const char *regexp) +{ + /* + c matches any literal character c + . matches any single character + ^ matches the beginning of the input string + $ matches the end of the input string + * matches zero or more occurrences of the previous character*/ + if (regexp[0] == '^') + return nk_str_match_here(regexp+1, text); + do { /* must look even if string is empty */ + if (nk_str_match_here(regexp, text)) + return 1; + } while (*text++ != '\0'); + return 0; +} +NK_API int +nk_strmatch_fuzzy_text(const char *str, int str_len, + const char *pattern, int *out_score) +{ + /* Returns true if each character in pattern is found sequentially within str + * if found then out_score is also set. Score value has no intrinsic meaning. + * Range varies with pattern. Can only compare scores with same search pattern. */ + + /* bonus for adjacent matches */ + #define NK_ADJACENCY_BONUS 5 + /* bonus if match occurs after a separator */ + #define NK_SEPARATOR_BONUS 10 + /* bonus if match is uppercase and prev is lower */ + #define NK_CAMEL_BONUS 10 + /* penalty applied for every letter in str before the first match */ + #define NK_LEADING_LETTER_PENALTY (-3) + /* maximum penalty for leading letters */ + #define NK_MAX_LEADING_LETTER_PENALTY (-9) + /* penalty for every letter that doesn't matter */ + #define NK_UNMATCHED_LETTER_PENALTY (-1) + + /* loop variables */ + int score = 0; + char const * pattern_iter = pattern; + int str_iter = 0; + int prev_matched = nk_false; + int prev_lower = nk_false; + /* true so if first letter match gets separator bonus*/ + int prev_separator = nk_true; + + /* use "best" matched letter if multiple string letters match the pattern */ + char const * best_letter = 0; + int best_letter_score = 0; + + /* loop over strings */ + NK_ASSERT(str); + NK_ASSERT(pattern); + if (!str || !str_len || !pattern) return 0; + while (str_iter < str_len) + { + const char pattern_letter = *pattern_iter; + const char str_letter = str[str_iter]; + + int next_match = *pattern_iter != '\0' && + nk_to_lower(pattern_letter) == nk_to_lower(str_letter); + int rematch = best_letter && nk_to_upper(*best_letter) == nk_to_upper(str_letter); + + int advanced = next_match && best_letter; + int pattern_repeat = best_letter && *pattern_iter != '\0'; + pattern_repeat = pattern_repeat && + nk_to_lower(*best_letter) == nk_to_lower(pattern_letter); + + if (advanced || pattern_repeat) { + score += best_letter_score; + best_letter = 0; + best_letter_score = 0; + } + + if (next_match || rematch) + { + int new_score = 0; + /* Apply penalty for each letter before the first pattern match */ + if (pattern_iter == pattern) { + int count = (int)(&str[str_iter] - str); + int penalty = NK_LEADING_LETTER_PENALTY * count; + if (penalty < NK_MAX_LEADING_LETTER_PENALTY) + penalty = NK_MAX_LEADING_LETTER_PENALTY; + + score += penalty; + } + + /* apply bonus for consecutive bonuses */ + if (prev_matched) + new_score += NK_ADJACENCY_BONUS; + + /* apply bonus for matches after a separator */ + if (prev_separator) + new_score += NK_SEPARATOR_BONUS; + + /* apply bonus across camel case boundaries */ + if (prev_lower && nk_is_upper(str_letter)) + new_score += NK_CAMEL_BONUS; + + /* update pattern iter IFF the next pattern letter was matched */ + if (next_match) + ++pattern_iter; + + /* update best letter in str which may be for a "next" letter or a rematch */ + if (new_score >= best_letter_score) { + /* apply penalty for now skipped letter */ + if (best_letter != 0) + score += NK_UNMATCHED_LETTER_PENALTY; + + best_letter = &str[str_iter]; + best_letter_score = new_score; + } + prev_matched = nk_true; + } else { + score += NK_UNMATCHED_LETTER_PENALTY; + prev_matched = nk_false; + } + + /* separators should be more easily defined */ + prev_lower = nk_is_lower(str_letter) != 0; + prev_separator = str_letter == '_' || str_letter == ' '; + + ++str_iter; + } + + /* apply score for last match */ + if (best_letter) + score += best_letter_score; + + /* did not match full pattern */ + if (*pattern_iter != '\0') + return nk_false; + + if (out_score) + *out_score = score; + return nk_true; +} +NK_API int +nk_strmatch_fuzzy_string(char const *str, char const *pattern, int *out_score) +{ + return nk_strmatch_fuzzy_text(str, nk_strlen(str), pattern, out_score); +} +NK_LIB int +nk_string_float_limit(char *string, int prec) +{ + int dot = 0; + char *c = string; + while (*c) { + if (*c == '.') { + dot = 1; + c++; + continue; + } + if (dot == (prec+1)) { + *c = 0; + break; + } + if (dot > 0) dot++; + c++; + } + return (int)(c - string); +} +NK_INTERN void +nk_strrev_ascii(char *s) +{ + int len = nk_strlen(s); + int end = len / 2; + int i = 0; + char t; + for (; i < end; ++i) { + t = s[i]; + s[i] = s[len - 1 - i]; + s[len -1 - i] = t; + } +} +NK_LIB char* +nk_itoa(char *s, long n) +{ + long i = 0; + if (n == 0) { + s[i++] = '0'; + s[i] = 0; + return s; + } + if (n < 0) { + s[i++] = '-'; + n = -n; + } + while (n > 0) { + s[i++] = (char)('0' + (n % 10)); + n /= 10; + } + s[i] = 0; + if (s[0] == '-') + ++s; + + nk_strrev_ascii(s); + return s; +} +#ifndef NK_DTOA +#define NK_DTOA nk_dtoa +NK_LIB char* +nk_dtoa(char *s, double n) +{ + int useExp = 0; + int digit = 0, m = 0, m1 = 0; + char *c = s; + int neg = 0; + + NK_ASSERT(s); + if (!s) return 0; + + if (n == 0.0) { + s[0] = '0'; s[1] = '\0'; + return s; + } + + neg = (n < 0); + if (neg) n = -n; + + /* calculate magnitude */ + m = nk_log10(n); + useExp = (m >= 14 || (neg && m >= 9) || m <= -9); + if (neg) *(c++) = '-'; + + /* set up for scientific notation */ + if (useExp) { + if (m < 0) + m -= 1; + n = n / (double)nk_pow(10.0, m); + m1 = m; + m = 0; + } + if (m < 1.0) { + m = 0; + } + + /* convert the number */ + while (n > NK_FLOAT_PRECISION || m >= 0) { + double weight = nk_pow(10.0, m); + if (weight > 0) { + double t = (double)n / weight; + digit = nk_ifloord(t); + n -= ((double)digit * weight); + *(c++) = (char)('0' + (char)digit); + } + if (m == 0 && n > 0) + *(c++) = '.'; + m--; + } + + if (useExp) { + /* convert the exponent */ + int i, j; + *(c++) = 'e'; + if (m1 > 0) { + *(c++) = '+'; + } else { + *(c++) = '-'; + m1 = -m1; + } + m = 0; + while (m1 > 0) { + *(c++) = (char)('0' + (char)(m1 % 10)); + m1 /= 10; + m++; + } + c -= m; + for (i = 0, j = m-1; i= buf_size) break; + iter++; + + /* flag arguments */ + while (*iter) { + if (*iter == '-') flag |= NK_ARG_FLAG_LEFT; + else if (*iter == '+') flag |= NK_ARG_FLAG_PLUS; + else if (*iter == ' ') flag |= NK_ARG_FLAG_SPACE; + else if (*iter == '#') flag |= NK_ARG_FLAG_NUM; + else if (*iter == '0') flag |= NK_ARG_FLAG_ZERO; + else break; + iter++; + } + + /* width argument */ + width = NK_DEFAULT; + if (*iter >= '1' && *iter <= '9') { + const char *end; + width = nk_strtoi(iter, &end); + if (end == iter) + width = -1; + else iter = end; + } else if (*iter == '*') { + width = va_arg(args, int); + iter++; + } + + /* precision argument */ + precision = NK_DEFAULT; + if (*iter == '.') { + iter++; + if (*iter == '*') { + precision = va_arg(args, int); + iter++; + } else { + const char *end; + precision = nk_strtoi(iter, &end); + if (end == iter) + precision = -1; + else iter = end; + } + } + + /* length modifier */ + if (*iter == 'h') { + if (*(iter+1) == 'h') { + arg_type = NK_ARG_TYPE_CHAR; + iter++; + } else arg_type = NK_ARG_TYPE_SHORT; + iter++; + } else if (*iter == 'l') { + arg_type = NK_ARG_TYPE_LONG; + iter++; + } else arg_type = NK_ARG_TYPE_DEFAULT; + + /* specifier */ + if (*iter == '%') { + NK_ASSERT(arg_type == NK_ARG_TYPE_DEFAULT); + NK_ASSERT(precision == NK_DEFAULT); + NK_ASSERT(width == NK_DEFAULT); + if (len < buf_size) + buf[len++] = '%'; + } else if (*iter == 's') { + /* string */ + const char *str = va_arg(args, const char*); + NK_ASSERT(str != buf && "buffer and argument are not allowed to overlap!"); + NK_ASSERT(arg_type == NK_ARG_TYPE_DEFAULT); + NK_ASSERT(precision == NK_DEFAULT); + NK_ASSERT(width == NK_DEFAULT); + if (str == buf) return -1; + while (str && *str && len < buf_size) + buf[len++] = *str++; + } else if (*iter == 'n') { + /* current length callback */ + signed int *n = va_arg(args, int*); + NK_ASSERT(arg_type == NK_ARG_TYPE_DEFAULT); + NK_ASSERT(precision == NK_DEFAULT); + NK_ASSERT(width == NK_DEFAULT); + if (n) *n = len; + } else if (*iter == 'c' || *iter == 'i' || *iter == 'd') { + /* signed integer */ + long value = 0; + const char *num_iter; + int num_len, num_print, padding; + int cur_precision = NK_MAX(precision, 1); + int cur_width = NK_MAX(width, 0); + + /* retrieve correct value type */ + if (arg_type == NK_ARG_TYPE_CHAR) + value = (signed char)va_arg(args, int); + else if (arg_type == NK_ARG_TYPE_SHORT) + value = (signed short)va_arg(args, int); + else if (arg_type == NK_ARG_TYPE_LONG) + value = va_arg(args, signed long); + else if (*iter == 'c') + value = (unsigned char)va_arg(args, int); + else value = va_arg(args, signed int); + + /* convert number to string */ + nk_itoa(number_buffer, value); + num_len = nk_strlen(number_buffer); + padding = NK_MAX(cur_width - NK_MAX(cur_precision, num_len), 0); + if ((flag & NK_ARG_FLAG_PLUS) || (flag & NK_ARG_FLAG_SPACE)) + padding = NK_MAX(padding-1, 0); + + /* fill left padding up to a total of `width` characters */ + if (!(flag & NK_ARG_FLAG_LEFT)) { + while (padding-- > 0 && (len < buf_size)) { + if ((flag & NK_ARG_FLAG_ZERO) && (precision == NK_DEFAULT)) + buf[len++] = '0'; + else buf[len++] = ' '; + } + } + + /* copy string value representation into buffer */ + if ((flag & NK_ARG_FLAG_PLUS) && value >= 0 && len < buf_size) + buf[len++] = '+'; + else if ((flag & NK_ARG_FLAG_SPACE) && value >= 0 && len < buf_size) + buf[len++] = ' '; + + /* fill up to precision number of digits with '0' */ + num_print = NK_MAX(cur_precision, num_len); + while (precision && (num_print > num_len) && (len < buf_size)) { + buf[len++] = '0'; + num_print--; + } + + /* copy string value representation into buffer */ + num_iter = number_buffer; + while (precision && *num_iter && len < buf_size) + buf[len++] = *num_iter++; + + /* fill right padding up to width characters */ + if (flag & NK_ARG_FLAG_LEFT) { + while ((padding-- > 0) && (len < buf_size)) + buf[len++] = ' '; + } + } else if (*iter == 'o' || *iter == 'x' || *iter == 'X' || *iter == 'u') { + /* unsigned integer */ + unsigned long value = 0; + int num_len = 0, num_print, padding = 0; + int cur_precision = NK_MAX(precision, 1); + int cur_width = NK_MAX(width, 0); + unsigned int base = (*iter == 'o') ? 8: (*iter == 'u')? 10: 16; + + /* print oct/hex/dec value */ + const char *upper_output_format = "0123456789ABCDEF"; + const char *lower_output_format = "0123456789abcdef"; + const char *output_format = (*iter == 'x') ? + lower_output_format: upper_output_format; + + /* retrieve correct value type */ + if (arg_type == NK_ARG_TYPE_CHAR) + value = (unsigned char)va_arg(args, int); + else if (arg_type == NK_ARG_TYPE_SHORT) + value = (unsigned short)va_arg(args, int); + else if (arg_type == NK_ARG_TYPE_LONG) + value = va_arg(args, unsigned long); + else value = va_arg(args, unsigned int); + + do { + /* convert decimal number into hex/oct number */ + int digit = output_format[value % base]; + if (num_len < NK_MAX_NUMBER_BUFFER) + number_buffer[num_len++] = (char)digit; + value /= base; + } while (value > 0); + + num_print = NK_MAX(cur_precision, num_len); + padding = NK_MAX(cur_width - NK_MAX(cur_precision, num_len), 0); + if (flag & NK_ARG_FLAG_NUM) + padding = NK_MAX(padding-1, 0); + + /* fill left padding up to a total of `width` characters */ + if (!(flag & NK_ARG_FLAG_LEFT)) { + while ((padding-- > 0) && (len < buf_size)) { + if ((flag & NK_ARG_FLAG_ZERO) && (precision == NK_DEFAULT)) + buf[len++] = '0'; + else buf[len++] = ' '; + } + } + + /* fill up to precision number of digits */ + if (num_print && (flag & NK_ARG_FLAG_NUM)) { + if ((*iter == 'o') && (len < buf_size)) { + buf[len++] = '0'; + } else if ((*iter == 'x') && ((len+1) < buf_size)) { + buf[len++] = '0'; + buf[len++] = 'x'; + } else if ((*iter == 'X') && ((len+1) < buf_size)) { + buf[len++] = '0'; + buf[len++] = 'X'; + } + } + while (precision && (num_print > num_len) && (len < buf_size)) { + buf[len++] = '0'; + num_print--; + } + + /* reverse number direction */ + while (num_len > 0) { + if (precision && (len < buf_size)) + buf[len++] = number_buffer[num_len-1]; + num_len--; + } + + /* fill right padding up to width characters */ + if (flag & NK_ARG_FLAG_LEFT) { + while ((padding-- > 0) && (len < buf_size)) + buf[len++] = ' '; + } + } else if (*iter == 'f') { + /* floating point */ + const char *num_iter; + int cur_precision = (precision < 0) ? 6: precision; + int prefix, cur_width = NK_MAX(width, 0); + double value = va_arg(args, double); + int num_len = 0, frac_len = 0, dot = 0; + int padding = 0; + + NK_ASSERT(arg_type == NK_ARG_TYPE_DEFAULT); + NK_DTOA(number_buffer, value); + num_len = nk_strlen(number_buffer); + + /* calculate padding */ + num_iter = number_buffer; + while (*num_iter && *num_iter != '.') + num_iter++; + + prefix = (*num_iter == '.')?(int)(num_iter - number_buffer)+1:0; + padding = NK_MAX(cur_width - (prefix + NK_MIN(cur_precision, num_len - prefix)) , 0); + if ((flag & NK_ARG_FLAG_PLUS) || (flag & NK_ARG_FLAG_SPACE)) + padding = NK_MAX(padding-1, 0); + + /* fill left padding up to a total of `width` characters */ + if (!(flag & NK_ARG_FLAG_LEFT)) { + while (padding-- > 0 && (len < buf_size)) { + if (flag & NK_ARG_FLAG_ZERO) + buf[len++] = '0'; + else buf[len++] = ' '; + } + } + + /* copy string value representation into buffer */ + num_iter = number_buffer; + if ((flag & NK_ARG_FLAG_PLUS) && (value >= 0) && (len < buf_size)) + buf[len++] = '+'; + else if ((flag & NK_ARG_FLAG_SPACE) && (value >= 0) && (len < buf_size)) + buf[len++] = ' '; + while (*num_iter) { + if (dot) frac_len++; + if (len < buf_size) + buf[len++] = *num_iter; + if (*num_iter == '.') dot = 1; + if (frac_len >= cur_precision) break; + num_iter++; + } + + /* fill number up to precision */ + while (frac_len < cur_precision) { + if (!dot && len < buf_size) { + buf[len++] = '.'; + dot = 1; + } + if (len < buf_size) + buf[len++] = '0'; + frac_len++; + } + + /* fill right padding up to width characters */ + if (flag & NK_ARG_FLAG_LEFT) { + while ((padding-- > 0) && (len < buf_size)) + buf[len++] = ' '; + } + } else { + /* Specifier not supported: g,G,e,E,p,z */ + NK_ASSERT(0 && "specifier is not supported!"); + return result; + } + } + buf[(len >= buf_size)?(buf_size-1):len] = 0; + result = (len >= buf_size)?-1:len; + return result; +} +#endif +NK_LIB int +nk_strfmt(char *buf, int buf_size, const char *fmt, va_list args) +{ + int result = -1; + NK_ASSERT(buf); + NK_ASSERT(buf_size); + if (!buf || !buf_size || !fmt) return 0; +#ifdef NK_INCLUDE_STANDARD_IO + result = NK_VSNPRINTF(buf, (nk_size)buf_size, fmt, args); + result = (result >= buf_size) ? -1: result; + buf[buf_size-1] = 0; +#else + result = nk_vsnprintf(buf, buf_size, fmt, args); +#endif + return result; +} +#endif +NK_API nk_hash +nk_murmur_hash(const void * key, int len, nk_hash seed) +{ + /* 32-Bit MurmurHash3: https://code.google.com/p/smhasher/wiki/MurmurHash3*/ + #define NK_ROTL(x,r) ((x) << (r) | ((x) >> (32 - r))) + + nk_uint h1 = seed; + nk_uint k1; + const nk_byte *data = (const nk_byte*)key; + const nk_byte *keyptr = data; + nk_byte *k1ptr; + const int bsize = sizeof(k1); + const int nblocks = len/4; + + const nk_uint c1 = 0xcc9e2d51; + const nk_uint c2 = 0x1b873593; + const nk_byte *tail; + int i; + + /* body */ + if (!key) return 0; + for (i = 0; i < nblocks; ++i, keyptr += bsize) { + k1ptr = (nk_byte*)&k1; + k1ptr[0] = keyptr[0]; + k1ptr[1] = keyptr[1]; + k1ptr[2] = keyptr[2]; + k1ptr[3] = keyptr[3]; + + k1 *= c1; + k1 = NK_ROTL(k1,15); + k1 *= c2; + + h1 ^= k1; + h1 = NK_ROTL(h1,13); + h1 = h1*5+0xe6546b64; + } + + /* tail */ + tail = (const nk_byte*)(data + nblocks*4); + k1 = 0; + switch (len & 3) { + case 3: k1 ^= (nk_uint)(tail[2] << 16); /* fallthrough */ + case 2: k1 ^= (nk_uint)(tail[1] << 8u); /* fallthrough */ + case 1: k1 ^= tail[0]; + k1 *= c1; + k1 = NK_ROTL(k1,15); + k1 *= c2; + h1 ^= k1; + break; + default: break; + } + + /* finalization */ + h1 ^= (nk_uint)len; + /* fmix32 */ + h1 ^= h1 >> 16; + h1 *= 0x85ebca6b; + h1 ^= h1 >> 13; + h1 *= 0xc2b2ae35; + h1 ^= h1 >> 16; + + #undef NK_ROTL + return h1; +} +#ifdef NK_INCLUDE_STANDARD_IO +NK_LIB char* +nk_file_load(const char* path, nk_size* siz, struct nk_allocator *alloc) +{ + char *buf; + FILE *fd; + long ret; + + NK_ASSERT(path); + NK_ASSERT(siz); + NK_ASSERT(alloc); + if (!path || !siz || !alloc) + return 0; + + fd = fopen(path, "rb"); + if (!fd) return 0; + fseek(fd, 0, SEEK_END); + ret = ftell(fd); + if (ret < 0) { + fclose(fd); + return 0; + } + *siz = (nk_size)ret; + fseek(fd, 0, SEEK_SET); + buf = (char*)alloc->alloc(alloc->userdata,0, *siz); + NK_ASSERT(buf); + if (!buf) { + fclose(fd); + return 0; + } + *siz = (nk_size)fread(buf, 1,*siz, fd); + fclose(fd); + return buf; +} +#endif +NK_LIB int +nk_text_clamp(const struct nk_user_font *font, const char *text, + int text_len, float space, int *glyphs, float *text_width, + nk_rune *sep_list, int sep_count) +{ + int i = 0; + int glyph_len = 0; + float last_width = 0; + nk_rune unicode = 0; + float width = 0; + int len = 0; + int g = 0; + float s; + + int sep_len = 0; + int sep_g = 0; + float sep_width = 0; + sep_count = NK_MAX(sep_count,0); + + glyph_len = nk_utf_decode(text, &unicode, text_len); + while (glyph_len && (width < space) && (len < text_len)) { + len += glyph_len; + s = font->width(font->userdata, font->height, text, len); + for (i = 0; i < sep_count; ++i) { + if (unicode != sep_list[i]) continue; + sep_width = last_width = width; + sep_g = g+1; + sep_len = len; + break; + } + if (i == sep_count){ + last_width = sep_width = width; + sep_g = g+1; + } + width = s; + glyph_len = nk_utf_decode(&text[len], &unicode, text_len - len); + g++; + } + if (len >= text_len) { + *glyphs = g; + *text_width = last_width; + return len; + } else { + *glyphs = sep_g; + *text_width = sep_width; + return (!sep_len) ? len: sep_len; + } +} +NK_LIB struct nk_vec2 +nk_text_calculate_text_bounds(const struct nk_user_font *font, + const char *begin, int byte_len, float row_height, const char **remaining, + struct nk_vec2 *out_offset, int *glyphs, int op) +{ + float line_height = row_height; + struct nk_vec2 text_size = nk_vec2(0,0); + float line_width = 0.0f; + + float glyph_width; + int glyph_len = 0; + nk_rune unicode = 0; + int text_len = 0; + if (!begin || byte_len <= 0 || !font) + return nk_vec2(0,row_height); + + glyph_len = nk_utf_decode(begin, &unicode, byte_len); + if (!glyph_len) return text_size; + glyph_width = font->width(font->userdata, font->height, begin, glyph_len); + + *glyphs = 0; + while ((text_len < byte_len) && glyph_len) { + if (unicode == '\n') { + text_size.x = NK_MAX(text_size.x, line_width); + text_size.y += line_height; + line_width = 0; + *glyphs+=1; + if (op == NK_STOP_ON_NEW_LINE) + break; + + text_len++; + glyph_len = nk_utf_decode(begin + text_len, &unicode, byte_len-text_len); + continue; + } + + if (unicode == '\r') { + text_len++; + *glyphs+=1; + glyph_len = nk_utf_decode(begin + text_len, &unicode, byte_len-text_len); + continue; + } + + *glyphs = *glyphs + 1; + text_len += glyph_len; + line_width += (float)glyph_width; + glyph_len = nk_utf_decode(begin + text_len, &unicode, byte_len-text_len); + glyph_width = font->width(font->userdata, font->height, begin+text_len, glyph_len); + continue; + } + + if (text_size.x < line_width) + text_size.x = line_width; + if (out_offset) + *out_offset = nk_vec2(line_width, text_size.y + line_height); + if (line_width > 0 || text_size.y == 0.0f) + text_size.y += line_height; + if (remaining) + *remaining = begin+text_len; + return text_size; +} + + + + + +/* ============================================================== + * + * COLOR + * + * ===============================================================*/ +NK_INTERN int +nk_parse_hex(const char *p, int length) +{ + int i = 0; + int len = 0; + while (len < length) { + i <<= 4; + if (p[len] >= 'a' && p[len] <= 'f') + i += ((p[len] - 'a') + 10); + else if (p[len] >= 'A' && p[len] <= 'F') + i += ((p[len] - 'A') + 10); + else i += (p[len] - '0'); + len++; + } + return i; +} +NK_API struct nk_color +nk_rgba(int r, int g, int b, int a) +{ + struct nk_color ret; + ret.r = (nk_byte)NK_CLAMP(0, r, 255); + ret.g = (nk_byte)NK_CLAMP(0, g, 255); + ret.b = (nk_byte)NK_CLAMP(0, b, 255); + ret.a = (nk_byte)NK_CLAMP(0, a, 255); + return ret; +} +NK_API struct nk_color +nk_rgb_hex(const char *rgb) +{ + struct nk_color col; + const char *c = rgb; + if (*c == '#') c++; + col.r = (nk_byte)nk_parse_hex(c, 2); + col.g = (nk_byte)nk_parse_hex(c+2, 2); + col.b = (nk_byte)nk_parse_hex(c+4, 2); + col.a = 255; + return col; +} +NK_API struct nk_color +nk_rgba_hex(const char *rgb) +{ + struct nk_color col; + const char *c = rgb; + if (*c == '#') c++; + col.r = (nk_byte)nk_parse_hex(c, 2); + col.g = (nk_byte)nk_parse_hex(c+2, 2); + col.b = (nk_byte)nk_parse_hex(c+4, 2); + col.a = (nk_byte)nk_parse_hex(c+6, 2); + return col; +} +NK_API void +nk_color_hex_rgba(char *output, struct nk_color col) +{ + #define NK_TO_HEX(i) ((i) <= 9 ? '0' + (i): 'A' - 10 + (i)) + output[0] = (char)NK_TO_HEX((col.r & 0xF0) >> 4); + output[1] = (char)NK_TO_HEX((col.r & 0x0F)); + output[2] = (char)NK_TO_HEX((col.g & 0xF0) >> 4); + output[3] = (char)NK_TO_HEX((col.g & 0x0F)); + output[4] = (char)NK_TO_HEX((col.b & 0xF0) >> 4); + output[5] = (char)NK_TO_HEX((col.b & 0x0F)); + output[6] = (char)NK_TO_HEX((col.a & 0xF0) >> 4); + output[7] = (char)NK_TO_HEX((col.a & 0x0F)); + output[8] = '\0'; + #undef NK_TO_HEX +} +NK_API void +nk_color_hex_rgb(char *output, struct nk_color col) +{ + #define NK_TO_HEX(i) ((i) <= 9 ? '0' + (i): 'A' - 10 + (i)) + output[0] = (char)NK_TO_HEX((col.r & 0xF0) >> 4); + output[1] = (char)NK_TO_HEX((col.r & 0x0F)); + output[2] = (char)NK_TO_HEX((col.g & 0xF0) >> 4); + output[3] = (char)NK_TO_HEX((col.g & 0x0F)); + output[4] = (char)NK_TO_HEX((col.b & 0xF0) >> 4); + output[5] = (char)NK_TO_HEX((col.b & 0x0F)); + output[6] = '\0'; + #undef NK_TO_HEX +} +NK_API struct nk_color +nk_rgba_iv(const int *c) +{ + return nk_rgba(c[0], c[1], c[2], c[3]); +} +NK_API struct nk_color +nk_rgba_bv(const nk_byte *c) +{ + return nk_rgba(c[0], c[1], c[2], c[3]); +} +NK_API struct nk_color +nk_rgb(int r, int g, int b) +{ + struct nk_color ret; + ret.r = (nk_byte)NK_CLAMP(0, r, 255); + ret.g = (nk_byte)NK_CLAMP(0, g, 255); + ret.b = (nk_byte)NK_CLAMP(0, b, 255); + ret.a = (nk_byte)255; + return ret; +} +NK_API struct nk_color +nk_rgb_iv(const int *c) +{ + return nk_rgb(c[0], c[1], c[2]); +} +NK_API struct nk_color +nk_rgb_bv(const nk_byte* c) +{ + return nk_rgb(c[0], c[1], c[2]); +} +NK_API struct nk_color +nk_rgba_u32(nk_uint in) +{ + struct nk_color ret; + ret.r = (in & 0xFF); + ret.g = ((in >> 8) & 0xFF); + ret.b = ((in >> 16) & 0xFF); + ret.a = (nk_byte)((in >> 24) & 0xFF); + return ret; +} +NK_API struct nk_color +nk_rgba_f(float r, float g, float b, float a) +{ + struct nk_color ret; + ret.r = (nk_byte)(NK_SATURATE(r) * 255.0f); + ret.g = (nk_byte)(NK_SATURATE(g) * 255.0f); + ret.b = (nk_byte)(NK_SATURATE(b) * 255.0f); + ret.a = (nk_byte)(NK_SATURATE(a) * 255.0f); + return ret; +} +NK_API struct nk_color +nk_rgba_fv(const float *c) +{ + return nk_rgba_f(c[0], c[1], c[2], c[3]); +} +NK_API struct nk_color +nk_rgba_cf(struct nk_colorf c) +{ + return nk_rgba_f(c.r, c.g, c.b, c.a); +} +NK_API struct nk_color +nk_rgb_f(float r, float g, float b) +{ + struct nk_color ret; + ret.r = (nk_byte)(NK_SATURATE(r) * 255.0f); + ret.g = (nk_byte)(NK_SATURATE(g) * 255.0f); + ret.b = (nk_byte)(NK_SATURATE(b) * 255.0f); + ret.a = 255; + return ret; +} +NK_API struct nk_color +nk_rgb_fv(const float *c) +{ + return nk_rgb_f(c[0], c[1], c[2]); +} +NK_API struct nk_color +nk_rgb_cf(struct nk_colorf c) +{ + return nk_rgb_f(c.r, c.g, c.b); +} +NK_API struct nk_color +nk_hsv(int h, int s, int v) +{ + return nk_hsva(h, s, v, 255); +} +NK_API struct nk_color +nk_hsv_iv(const int *c) +{ + return nk_hsv(c[0], c[1], c[2]); +} +NK_API struct nk_color +nk_hsv_bv(const nk_byte *c) +{ + return nk_hsv(c[0], c[1], c[2]); +} +NK_API struct nk_color +nk_hsv_f(float h, float s, float v) +{ + return nk_hsva_f(h, s, v, 1.0f); +} +NK_API struct nk_color +nk_hsv_fv(const float *c) +{ + return nk_hsv_f(c[0], c[1], c[2]); +} +NK_API struct nk_color +nk_hsva(int h, int s, int v, int a) +{ + float hf = ((float)NK_CLAMP(0, h, 255)) / 255.0f; + float sf = ((float)NK_CLAMP(0, s, 255)) / 255.0f; + float vf = ((float)NK_CLAMP(0, v, 255)) / 255.0f; + float af = ((float)NK_CLAMP(0, a, 255)) / 255.0f; + return nk_hsva_f(hf, sf, vf, af); +} +NK_API struct nk_color +nk_hsva_iv(const int *c) +{ + return nk_hsva(c[0], c[1], c[2], c[3]); +} +NK_API struct nk_color +nk_hsva_bv(const nk_byte *c) +{ + return nk_hsva(c[0], c[1], c[2], c[3]); +} +NK_API struct nk_colorf +nk_hsva_colorf(float h, float s, float v, float a) +{ + int i; + float p, q, t, f; + struct nk_colorf out = {0,0,0,0}; + if (s <= 0.0f) { + out.r = v; out.g = v; out.b = v; out.a = a; + return out; + } + h = h / (60.0f/360.0f); + i = (int)h; + f = h - (float)i; + p = v * (1.0f - s); + q = v * (1.0f - (s * f)); + t = v * (1.0f - s * (1.0f - f)); + + switch (i) { + case 0: default: out.r = v; out.g = t; out.b = p; break; + case 1: out.r = q; out.g = v; out.b = p; break; + case 2: out.r = p; out.g = v; out.b = t; break; + case 3: out.r = p; out.g = q; out.b = v; break; + case 4: out.r = t; out.g = p; out.b = v; break; + case 5: out.r = v; out.g = p; out.b = q; break;} + out.a = a; + return out; +} +NK_API struct nk_colorf +nk_hsva_colorfv(float *c) +{ + return nk_hsva_colorf(c[0], c[1], c[2], c[3]); +} +NK_API struct nk_color +nk_hsva_f(float h, float s, float v, float a) +{ + struct nk_colorf c = nk_hsva_colorf(h, s, v, a); + return nk_rgba_f(c.r, c.g, c.b, c.a); +} +NK_API struct nk_color +nk_hsva_fv(const float *c) +{ + return nk_hsva_f(c[0], c[1], c[2], c[3]); +} +NK_API nk_uint +nk_color_u32(struct nk_color in) +{ + nk_uint out = (nk_uint)in.r; + out |= ((nk_uint)in.g << 8); + out |= ((nk_uint)in.b << 16); + out |= ((nk_uint)in.a << 24); + return out; +} +NK_API void +nk_color_f(float *r, float *g, float *b, float *a, struct nk_color in) +{ + NK_STORAGE const float s = 1.0f/255.0f; + *r = (float)in.r * s; + *g = (float)in.g * s; + *b = (float)in.b * s; + *a = (float)in.a * s; +} +NK_API void +nk_color_fv(float *c, struct nk_color in) +{ + nk_color_f(&c[0], &c[1], &c[2], &c[3], in); +} +NK_API struct nk_colorf +nk_color_cf(struct nk_color in) +{ + struct nk_colorf o; + nk_color_f(&o.r, &o.g, &o.b, &o.a, in); + return o; +} +NK_API void +nk_color_d(double *r, double *g, double *b, double *a, struct nk_color in) +{ + NK_STORAGE const double s = 1.0/255.0; + *r = (double)in.r * s; + *g = (double)in.g * s; + *b = (double)in.b * s; + *a = (double)in.a * s; +} +NK_API void +nk_color_dv(double *c, struct nk_color in) +{ + nk_color_d(&c[0], &c[1], &c[2], &c[3], in); +} +NK_API void +nk_color_hsv_f(float *out_h, float *out_s, float *out_v, struct nk_color in) +{ + float a; + nk_color_hsva_f(out_h, out_s, out_v, &a, in); +} +NK_API void +nk_color_hsv_fv(float *out, struct nk_color in) +{ + float a; + nk_color_hsva_f(&out[0], &out[1], &out[2], &a, in); +} +NK_API void +nk_colorf_hsva_f(float *out_h, float *out_s, + float *out_v, float *out_a, struct nk_colorf in) +{ + float chroma; + float K = 0.0f; + if (in.g < in.b) { + const float t = in.g; in.g = in.b; in.b = t; + K = -1.f; + } + if (in.r < in.g) { + const float t = in.r; in.r = in.g; in.g = t; + K = -2.f/6.0f - K; + } + chroma = in.r - ((in.g < in.b) ? in.g: in.b); + *out_h = NK_ABS(K + (in.g - in.b)/(6.0f * chroma + 1e-20f)); + *out_s = chroma / (in.r + 1e-20f); + *out_v = in.r; + *out_a = in.a; + +} +NK_API void +nk_colorf_hsva_fv(float *hsva, struct nk_colorf in) +{ + nk_colorf_hsva_f(&hsva[0], &hsva[1], &hsva[2], &hsva[3], in); +} +NK_API void +nk_color_hsva_f(float *out_h, float *out_s, + float *out_v, float *out_a, struct nk_color in) +{ + struct nk_colorf col; + nk_color_f(&col.r,&col.g,&col.b,&col.a, in); + nk_colorf_hsva_f(out_h, out_s, out_v, out_a, col); +} +NK_API void +nk_color_hsva_fv(float *out, struct nk_color in) +{ + nk_color_hsva_f(&out[0], &out[1], &out[2], &out[3], in); +} +NK_API void +nk_color_hsva_i(int *out_h, int *out_s, int *out_v, + int *out_a, struct nk_color in) +{ + float h,s,v,a; + nk_color_hsva_f(&h, &s, &v, &a, in); + *out_h = (nk_byte)(h * 255.0f); + *out_s = (nk_byte)(s * 255.0f); + *out_v = (nk_byte)(v * 255.0f); + *out_a = (nk_byte)(a * 255.0f); +} +NK_API void +nk_color_hsva_iv(int *out, struct nk_color in) +{ + nk_color_hsva_i(&out[0], &out[1], &out[2], &out[3], in); +} +NK_API void +nk_color_hsva_bv(nk_byte *out, struct nk_color in) +{ + int tmp[4]; + nk_color_hsva_i(&tmp[0], &tmp[1], &tmp[2], &tmp[3], in); + out[0] = (nk_byte)tmp[0]; + out[1] = (nk_byte)tmp[1]; + out[2] = (nk_byte)tmp[2]; + out[3] = (nk_byte)tmp[3]; +} +NK_API void +nk_color_hsva_b(nk_byte *h, nk_byte *s, nk_byte *v, nk_byte *a, struct nk_color in) +{ + int tmp[4]; + nk_color_hsva_i(&tmp[0], &tmp[1], &tmp[2], &tmp[3], in); + *h = (nk_byte)tmp[0]; + *s = (nk_byte)tmp[1]; + *v = (nk_byte)tmp[2]; + *a = (nk_byte)tmp[3]; +} +NK_API void +nk_color_hsv_i(int *out_h, int *out_s, int *out_v, struct nk_color in) +{ + int a; + nk_color_hsva_i(out_h, out_s, out_v, &a, in); +} +NK_API void +nk_color_hsv_b(nk_byte *out_h, nk_byte *out_s, nk_byte *out_v, struct nk_color in) +{ + int tmp[4]; + nk_color_hsva_i(&tmp[0], &tmp[1], &tmp[2], &tmp[3], in); + *out_h = (nk_byte)tmp[0]; + *out_s = (nk_byte)tmp[1]; + *out_v = (nk_byte)tmp[2]; +} +NK_API void +nk_color_hsv_iv(int *out, struct nk_color in) +{ + nk_color_hsv_i(&out[0], &out[1], &out[2], in); +} +NK_API void +nk_color_hsv_bv(nk_byte *out, struct nk_color in) +{ + int tmp[4]; + nk_color_hsv_i(&tmp[0], &tmp[1], &tmp[2], in); + out[0] = (nk_byte)tmp[0]; + out[1] = (nk_byte)tmp[1]; + out[2] = (nk_byte)tmp[2]; +} + + + + + +/* =============================================================== + * + * UTF-8 + * + * ===============================================================*/ +NK_GLOBAL const nk_byte nk_utfbyte[NK_UTF_SIZE+1] = {0x80, 0, 0xC0, 0xE0, 0xF0}; +NK_GLOBAL const nk_byte nk_utfmask[NK_UTF_SIZE+1] = {0xC0, 0x80, 0xE0, 0xF0, 0xF8}; +NK_GLOBAL const nk_uint nk_utfmin[NK_UTF_SIZE+1] = {0, 0, 0x80, 0x800, 0x10000}; +NK_GLOBAL const nk_uint nk_utfmax[NK_UTF_SIZE+1] = {0x10FFFF, 0x7F, 0x7FF, 0xFFFF, 0x10FFFF}; + +NK_INTERN int +nk_utf_validate(nk_rune *u, int i) +{ + NK_ASSERT(u); + if (!u) return 0; + if (!NK_BETWEEN(*u, nk_utfmin[i], nk_utfmax[i]) || + NK_BETWEEN(*u, 0xD800, 0xDFFF)) + *u = NK_UTF_INVALID; + for (i = 1; *u > nk_utfmax[i]; ++i); + return i; +} +NK_INTERN nk_rune +nk_utf_decode_byte(char c, int *i) +{ + NK_ASSERT(i); + if (!i) return 0; + for(*i = 0; *i < (int)NK_LEN(nk_utfmask); ++(*i)) { + if (((nk_byte)c & nk_utfmask[*i]) == nk_utfbyte[*i]) + return (nk_byte)(c & ~nk_utfmask[*i]); + } + return 0; +} +NK_API int +nk_utf_decode(const char *c, nk_rune *u, int clen) +{ + int i, j, len, type=0; + nk_rune udecoded; + + NK_ASSERT(c); + NK_ASSERT(u); + + if (!c || !u) return 0; + if (!clen) return 0; + *u = NK_UTF_INVALID; + + udecoded = nk_utf_decode_byte(c[0], &len); + if (!NK_BETWEEN(len, 1, NK_UTF_SIZE)) + return 1; + + for (i = 1, j = 1; i < clen && j < len; ++i, ++j) { + udecoded = (udecoded << 6) | nk_utf_decode_byte(c[i], &type); + if (type != 0) + return j; + } + if (j < len) + return 0; + *u = udecoded; + nk_utf_validate(u, len); + return len; +} +NK_INTERN char +nk_utf_encode_byte(nk_rune u, int i) +{ + return (char)((nk_utfbyte[i]) | ((nk_byte)u & ~nk_utfmask[i])); +} +NK_API int +nk_utf_encode(nk_rune u, char *c, int clen) +{ + int len, i; + len = nk_utf_validate(&u, 0); + if (clen < len || !len || len > NK_UTF_SIZE) + return 0; + + for (i = len - 1; i != 0; --i) { + c[i] = nk_utf_encode_byte(u, 0); + u >>= 6; + } + c[0] = nk_utf_encode_byte(u, len); + return len; +} +NK_API int +nk_utf_len(const char *str, int len) +{ + const char *text; + int glyphs = 0; + int text_len; + int glyph_len; + int src_len = 0; + nk_rune unicode; + + NK_ASSERT(str); + if (!str || !len) return 0; + + text = str; + text_len = len; + glyph_len = nk_utf_decode(text, &unicode, text_len); + while (glyph_len && src_len < len) { + glyphs++; + src_len = src_len + glyph_len; + glyph_len = nk_utf_decode(text + src_len, &unicode, text_len - src_len); + } + return glyphs; +} +NK_API const char* +nk_utf_at(const char *buffer, int length, int index, + nk_rune *unicode, int *len) +{ + int i = 0; + int src_len = 0; + int glyph_len = 0; + const char *text; + int text_len; + + NK_ASSERT(buffer); + NK_ASSERT(unicode); + NK_ASSERT(len); + + if (!buffer || !unicode || !len) return 0; + if (index < 0) { + *unicode = NK_UTF_INVALID; + *len = 0; + return 0; + } + + text = buffer; + text_len = length; + glyph_len = nk_utf_decode(text, unicode, text_len); + while (glyph_len) { + if (i == index) { + *len = glyph_len; + break; + } + + i++; + src_len = src_len + glyph_len; + glyph_len = nk_utf_decode(text + src_len, unicode, text_len - src_len); + } + if (i != index) return 0; + return buffer + src_len; +} + + + + + +/* ============================================================== + * + * BUFFER + * + * ===============================================================*/ +#ifdef NK_INCLUDE_DEFAULT_ALLOCATOR +NK_LIB void* +nk_malloc(nk_handle unused, void *old,nk_size size) +{ + NK_UNUSED(unused); + NK_UNUSED(old); + return malloc(size); +} +NK_LIB void +nk_mfree(nk_handle unused, void *ptr) +{ + NK_UNUSED(unused); + free(ptr); +} +NK_API void +nk_buffer_init_default(struct nk_buffer *buffer) +{ + struct nk_allocator alloc; + alloc.userdata.ptr = 0; + alloc.alloc = nk_malloc; + alloc.free = nk_mfree; + nk_buffer_init(buffer, &alloc, NK_BUFFER_DEFAULT_INITIAL_SIZE); +} +#endif + +NK_API void +nk_buffer_init(struct nk_buffer *b, const struct nk_allocator *a, + nk_size initial_size) +{ + NK_ASSERT(b); + NK_ASSERT(a); + NK_ASSERT(initial_size); + if (!b || !a || !initial_size) return; + + nk_zero(b, sizeof(*b)); + b->type = NK_BUFFER_DYNAMIC; + b->memory.ptr = a->alloc(a->userdata,0, initial_size); + b->memory.size = initial_size; + b->size = initial_size; + b->grow_factor = 2.0f; + b->pool = *a; +} +NK_API void +nk_buffer_init_fixed(struct nk_buffer *b, void *m, nk_size size) +{ + NK_ASSERT(b); + NK_ASSERT(m); + NK_ASSERT(size); + if (!b || !m || !size) return; + + nk_zero(b, sizeof(*b)); + b->type = NK_BUFFER_FIXED; + b->memory.ptr = m; + b->memory.size = size; + b->size = size; +} +NK_LIB void* +nk_buffer_align(void *unaligned, + nk_size align, nk_size *alignment, + enum nk_buffer_allocation_type type) +{ + void *memory = 0; + switch (type) { + default: + case NK_BUFFER_MAX: + case NK_BUFFER_FRONT: + if (align) { + memory = NK_ALIGN_PTR(unaligned, align); + *alignment = (nk_size)((nk_byte*)memory - (nk_byte*)unaligned); + } else { + memory = unaligned; + *alignment = 0; + } + break; + case NK_BUFFER_BACK: + if (align) { + memory = NK_ALIGN_PTR_BACK(unaligned, align); + *alignment = (nk_size)((nk_byte*)unaligned - (nk_byte*)memory); + } else { + memory = unaligned; + *alignment = 0; + } + break; + } + return memory; +} +NK_LIB void* +nk_buffer_realloc(struct nk_buffer *b, nk_size capacity, nk_size *size) +{ + void *temp; + nk_size buffer_size; + + NK_ASSERT(b); + NK_ASSERT(size); + if (!b || !size || !b->pool.alloc || !b->pool.free) + return 0; + + buffer_size = b->memory.size; + temp = b->pool.alloc(b->pool.userdata, b->memory.ptr, capacity); + NK_ASSERT(temp); + if (!temp) return 0; + + *size = capacity; + if (temp != b->memory.ptr) { + NK_MEMCPY(temp, b->memory.ptr, buffer_size); + b->pool.free(b->pool.userdata, b->memory.ptr); + } + + if (b->size == buffer_size) { + /* no back buffer so just set correct size */ + b->size = capacity; + return temp; + } else { + /* copy back buffer to the end of the new buffer */ + void *dst, *src; + nk_size back_size; + back_size = buffer_size - b->size; + dst = nk_ptr_add(void, temp, capacity - back_size); + src = nk_ptr_add(void, temp, b->size); + NK_MEMCPY(dst, src, back_size); + b->size = capacity - back_size; + } + return temp; +} +NK_LIB void* +nk_buffer_alloc(struct nk_buffer *b, enum nk_buffer_allocation_type type, + nk_size size, nk_size align) +{ + int full; + nk_size alignment; + void *unaligned; + void *memory; + + NK_ASSERT(b); + NK_ASSERT(size); + if (!b || !size) return 0; + b->needed += size; + + /* calculate total size with needed alignment + size */ + if (type == NK_BUFFER_FRONT) + unaligned = nk_ptr_add(void, b->memory.ptr, b->allocated); + else unaligned = nk_ptr_add(void, b->memory.ptr, b->size - size); + memory = nk_buffer_align(unaligned, align, &alignment, type); + + /* check if buffer has enough memory*/ + if (type == NK_BUFFER_FRONT) + full = ((b->allocated + size + alignment) > b->size); + else full = ((b->size - NK_MIN(b->size,(size + alignment))) <= b->allocated); + + if (full) { + nk_size capacity; + if (b->type != NK_BUFFER_DYNAMIC) + return 0; + NK_ASSERT(b->pool.alloc && b->pool.free); + if (b->type != NK_BUFFER_DYNAMIC || !b->pool.alloc || !b->pool.free) + return 0; + + /* buffer is full so allocate bigger buffer if dynamic */ + capacity = (nk_size)((float)b->memory.size * b->grow_factor); + capacity = NK_MAX(capacity, nk_round_up_pow2((nk_uint)(b->allocated + size))); + b->memory.ptr = nk_buffer_realloc(b, capacity, &b->memory.size); + if (!b->memory.ptr) return 0; + + /* align newly allocated pointer */ + if (type == NK_BUFFER_FRONT) + unaligned = nk_ptr_add(void, b->memory.ptr, b->allocated); + else unaligned = nk_ptr_add(void, b->memory.ptr, b->size - size); + memory = nk_buffer_align(unaligned, align, &alignment, type); + } + if (type == NK_BUFFER_FRONT) + b->allocated += size + alignment; + else b->size -= (size + alignment); + b->needed += alignment; + b->calls++; + return memory; +} +NK_API void +nk_buffer_push(struct nk_buffer *b, enum nk_buffer_allocation_type type, + const void *memory, nk_size size, nk_size align) +{ + void *mem = nk_buffer_alloc(b, type, size, align); + if (!mem) return; + NK_MEMCPY(mem, memory, size); +} +NK_API void +nk_buffer_mark(struct nk_buffer *buffer, enum nk_buffer_allocation_type type) +{ + NK_ASSERT(buffer); + if (!buffer) return; + buffer->marker[type].active = nk_true; + if (type == NK_BUFFER_BACK) + buffer->marker[type].offset = buffer->size; + else buffer->marker[type].offset = buffer->allocated; +} +NK_API void +nk_buffer_reset(struct nk_buffer *buffer, enum nk_buffer_allocation_type type) +{ + NK_ASSERT(buffer); + if (!buffer) return; + if (type == NK_BUFFER_BACK) { + /* reset back buffer either back to marker or empty */ + buffer->needed -= (buffer->memory.size - buffer->marker[type].offset); + if (buffer->marker[type].active) + buffer->size = buffer->marker[type].offset; + else buffer->size = buffer->memory.size; + buffer->marker[type].active = nk_false; + } else { + /* reset front buffer either back to back marker or empty */ + buffer->needed -= (buffer->allocated - buffer->marker[type].offset); + if (buffer->marker[type].active) + buffer->allocated = buffer->marker[type].offset; + else buffer->allocated = 0; + buffer->marker[type].active = nk_false; + } +} +NK_API void +nk_buffer_clear(struct nk_buffer *b) +{ + NK_ASSERT(b); + if (!b) return; + b->allocated = 0; + b->size = b->memory.size; + b->calls = 0; + b->needed = 0; +} +NK_API void +nk_buffer_free(struct nk_buffer *b) +{ + NK_ASSERT(b); + if (!b || !b->memory.ptr) return; + if (b->type == NK_BUFFER_FIXED) return; + if (!b->pool.free) return; + NK_ASSERT(b->pool.free); + b->pool.free(b->pool.userdata, b->memory.ptr); +} +NK_API void +nk_buffer_info(struct nk_memory_status *s, struct nk_buffer *b) +{ + NK_ASSERT(b); + NK_ASSERT(s); + if (!s || !b) return; + s->allocated = b->allocated; + s->size = b->memory.size; + s->needed = b->needed; + s->memory = b->memory.ptr; + s->calls = b->calls; +} +NK_API void* +nk_buffer_memory(struct nk_buffer *buffer) +{ + NK_ASSERT(buffer); + if (!buffer) return 0; + return buffer->memory.ptr; +} +NK_API const void* +nk_buffer_memory_const(const struct nk_buffer *buffer) +{ + NK_ASSERT(buffer); + if (!buffer) return 0; + return buffer->memory.ptr; +} +NK_API nk_size +nk_buffer_total(struct nk_buffer *buffer) +{ + NK_ASSERT(buffer); + if (!buffer) return 0; + return buffer->memory.size; +} + + + + + +/* =============================================================== + * + * STRING + * + * ===============================================================*/ +#ifdef NK_INCLUDE_DEFAULT_ALLOCATOR +NK_API void +nk_str_init_default(struct nk_str *str) +{ + struct nk_allocator alloc; + alloc.userdata.ptr = 0; + alloc.alloc = nk_malloc; + alloc.free = nk_mfree; + nk_buffer_init(&str->buffer, &alloc, 32); + str->len = 0; +} +#endif + +NK_API void +nk_str_init(struct nk_str *str, const struct nk_allocator *alloc, nk_size size) +{ + nk_buffer_init(&str->buffer, alloc, size); + str->len = 0; +} +NK_API void +nk_str_init_fixed(struct nk_str *str, void *memory, nk_size size) +{ + nk_buffer_init_fixed(&str->buffer, memory, size); + str->len = 0; +} +NK_API int +nk_str_append_text_char(struct nk_str *s, const char *str, int len) +{ + char *mem; + NK_ASSERT(s); + NK_ASSERT(str); + if (!s || !str || !len) return 0; + mem = (char*)nk_buffer_alloc(&s->buffer, NK_BUFFER_FRONT, (nk_size)len * sizeof(char), 0); + if (!mem) return 0; + NK_MEMCPY(mem, str, (nk_size)len * sizeof(char)); + s->len += nk_utf_len(str, len); + return len; +} +NK_API int +nk_str_append_str_char(struct nk_str *s, const char *str) +{ + return nk_str_append_text_char(s, str, nk_strlen(str)); +} +NK_API int +nk_str_append_text_utf8(struct nk_str *str, const char *text, int len) +{ + int i = 0; + int byte_len = 0; + nk_rune unicode; + if (!str || !text || !len) return 0; + for (i = 0; i < len; ++i) + byte_len += nk_utf_decode(text+byte_len, &unicode, 4); + nk_str_append_text_char(str, text, byte_len); + return len; +} +NK_API int +nk_str_append_str_utf8(struct nk_str *str, const char *text) +{ + int byte_len = 0; + int num_runes = 0; + int glyph_len = 0; + nk_rune unicode; + if (!str || !text) return 0; + + glyph_len = byte_len = nk_utf_decode(text+byte_len, &unicode, 4); + while (unicode != '\0' && glyph_len) { + glyph_len = nk_utf_decode(text+byte_len, &unicode, 4); + byte_len += glyph_len; + num_runes++; + } + nk_str_append_text_char(str, text, byte_len); + return num_runes; +} +NK_API int +nk_str_append_text_runes(struct nk_str *str, const nk_rune *text, int len) +{ + int i = 0; + int byte_len = 0; + nk_glyph glyph; + + NK_ASSERT(str); + if (!str || !text || !len) return 0; + for (i = 0; i < len; ++i) { + byte_len = nk_utf_encode(text[i], glyph, NK_UTF_SIZE); + if (!byte_len) break; + nk_str_append_text_char(str, glyph, byte_len); + } + return len; +} +NK_API int +nk_str_append_str_runes(struct nk_str *str, const nk_rune *runes) +{ + int i = 0; + nk_glyph glyph; + int byte_len; + NK_ASSERT(str); + if (!str || !runes) return 0; + while (runes[i] != '\0') { + byte_len = nk_utf_encode(runes[i], glyph, NK_UTF_SIZE); + nk_str_append_text_char(str, glyph, byte_len); + i++; + } + return i; +} +NK_API int +nk_str_insert_at_char(struct nk_str *s, int pos, const char *str, int len) +{ + int i; + void *mem; + char *src; + char *dst; + + int copylen; + NK_ASSERT(s); + NK_ASSERT(str); + NK_ASSERT(len >= 0); + if (!s || !str || !len || (nk_size)pos > s->buffer.allocated) return 0; + if ((s->buffer.allocated + (nk_size)len >= s->buffer.memory.size) && + (s->buffer.type == NK_BUFFER_FIXED)) return 0; + + copylen = (int)s->buffer.allocated - pos; + if (!copylen) { + nk_str_append_text_char(s, str, len); + return 1; + } + mem = nk_buffer_alloc(&s->buffer, NK_BUFFER_FRONT, (nk_size)len * sizeof(char), 0); + if (!mem) return 0; + + /* memmove */ + NK_ASSERT(((int)pos + (int)len + ((int)copylen - 1)) >= 0); + NK_ASSERT(((int)pos + ((int)copylen - 1)) >= 0); + dst = nk_ptr_add(char, s->buffer.memory.ptr, pos + len + (copylen - 1)); + src = nk_ptr_add(char, s->buffer.memory.ptr, pos + (copylen-1)); + for (i = 0; i < copylen; ++i) *dst-- = *src--; + mem = nk_ptr_add(void, s->buffer.memory.ptr, pos); + NK_MEMCPY(mem, str, (nk_size)len * sizeof(char)); + s->len = nk_utf_len((char *)s->buffer.memory.ptr, (int)s->buffer.allocated); + return 1; +} +NK_API int +nk_str_insert_at_rune(struct nk_str *str, int pos, const char *cstr, int len) +{ + int glyph_len; + nk_rune unicode; + const char *begin; + const char *buffer; + + NK_ASSERT(str); + NK_ASSERT(cstr); + NK_ASSERT(len); + if (!str || !cstr || !len) return 0; + begin = nk_str_at_rune(str, pos, &unicode, &glyph_len); + if (!str->len) + return nk_str_append_text_char(str, cstr, len); + buffer = nk_str_get_const(str); + if (!begin) return 0; + return nk_str_insert_at_char(str, (int)(begin - buffer), cstr, len); +} +NK_API int +nk_str_insert_text_char(struct nk_str *str, int pos, const char *text, int len) +{ + return nk_str_insert_text_utf8(str, pos, text, len); +} +NK_API int +nk_str_insert_str_char(struct nk_str *str, int pos, const char *text) +{ + return nk_str_insert_text_utf8(str, pos, text, nk_strlen(text)); +} +NK_API int +nk_str_insert_text_utf8(struct nk_str *str, int pos, const char *text, int len) +{ + int i = 0; + int byte_len = 0; + nk_rune unicode; + + NK_ASSERT(str); + NK_ASSERT(text); + if (!str || !text || !len) return 0; + for (i = 0; i < len; ++i) + byte_len += nk_utf_decode(text+byte_len, &unicode, 4); + nk_str_insert_at_rune(str, pos, text, byte_len); + return len; +} +NK_API int +nk_str_insert_str_utf8(struct nk_str *str, int pos, const char *text) +{ + int byte_len = 0; + int num_runes = 0; + int glyph_len = 0; + nk_rune unicode; + if (!str || !text) return 0; + + glyph_len = byte_len = nk_utf_decode(text+byte_len, &unicode, 4); + while (unicode != '\0' && glyph_len) { + glyph_len = nk_utf_decode(text+byte_len, &unicode, 4); + byte_len += glyph_len; + num_runes++; + } + nk_str_insert_at_rune(str, pos, text, byte_len); + return num_runes; +} +NK_API int +nk_str_insert_text_runes(struct nk_str *str, int pos, const nk_rune *runes, int len) +{ + int i = 0; + int byte_len = 0; + nk_glyph glyph; + + NK_ASSERT(str); + if (!str || !runes || !len) return 0; + for (i = 0; i < len; ++i) { + byte_len = nk_utf_encode(runes[i], glyph, NK_UTF_SIZE); + if (!byte_len) break; + nk_str_insert_at_rune(str, pos+i, glyph, byte_len); + } + return len; +} +NK_API int +nk_str_insert_str_runes(struct nk_str *str, int pos, const nk_rune *runes) +{ + int i = 0; + nk_glyph glyph; + int byte_len; + NK_ASSERT(str); + if (!str || !runes) return 0; + while (runes[i] != '\0') { + byte_len = nk_utf_encode(runes[i], glyph, NK_UTF_SIZE); + nk_str_insert_at_rune(str, pos+i, glyph, byte_len); + i++; + } + return i; +} +NK_API void +nk_str_remove_chars(struct nk_str *s, int len) +{ + NK_ASSERT(s); + NK_ASSERT(len >= 0); + if (!s || len < 0 || (nk_size)len > s->buffer.allocated) return; + NK_ASSERT(((int)s->buffer.allocated - (int)len) >= 0); + s->buffer.allocated -= (nk_size)len; + s->len = nk_utf_len((char *)s->buffer.memory.ptr, (int)s->buffer.allocated); +} +NK_API void +nk_str_remove_runes(struct nk_str *str, int len) +{ + int index; + const char *begin; + const char *end; + nk_rune unicode; + + NK_ASSERT(str); + NK_ASSERT(len >= 0); + if (!str || len < 0) return; + if (len >= str->len) { + str->len = 0; + return; + } + + index = str->len - len; + begin = nk_str_at_rune(str, index, &unicode, &len); + end = (const char*)str->buffer.memory.ptr + str->buffer.allocated; + nk_str_remove_chars(str, (int)(end-begin)+1); +} +NK_API void +nk_str_delete_chars(struct nk_str *s, int pos, int len) +{ + NK_ASSERT(s); + if (!s || !len || (nk_size)pos > s->buffer.allocated || + (nk_size)(pos + len) > s->buffer.allocated) return; + + if ((nk_size)(pos + len) < s->buffer.allocated) { + /* memmove */ + char *dst = nk_ptr_add(char, s->buffer.memory.ptr, pos); + char *src = nk_ptr_add(char, s->buffer.memory.ptr, pos + len); + NK_MEMCPY(dst, src, s->buffer.allocated - (nk_size)(pos + len)); + NK_ASSERT(((int)s->buffer.allocated - (int)len) >= 0); + s->buffer.allocated -= (nk_size)len; + } else nk_str_remove_chars(s, len); + s->len = nk_utf_len((char *)s->buffer.memory.ptr, (int)s->buffer.allocated); +} +NK_API void +nk_str_delete_runes(struct nk_str *s, int pos, int len) +{ + char *temp; + nk_rune unicode; + char *begin; + char *end; + int unused; + + NK_ASSERT(s); + NK_ASSERT(s->len >= pos + len); + if (s->len < pos + len) + len = NK_CLAMP(0, (s->len - pos), s->len); + if (!len) return; + + temp = (char *)s->buffer.memory.ptr; + begin = nk_str_at_rune(s, pos, &unicode, &unused); + if (!begin) return; + s->buffer.memory.ptr = begin; + end = nk_str_at_rune(s, len, &unicode, &unused); + s->buffer.memory.ptr = temp; + if (!end) return; + nk_str_delete_chars(s, (int)(begin - temp), (int)(end - begin)); +} +NK_API char* +nk_str_at_char(struct nk_str *s, int pos) +{ + NK_ASSERT(s); + if (!s || pos > (int)s->buffer.allocated) return 0; + return nk_ptr_add(char, s->buffer.memory.ptr, pos); +} +NK_API char* +nk_str_at_rune(struct nk_str *str, int pos, nk_rune *unicode, int *len) +{ + int i = 0; + int src_len = 0; + int glyph_len = 0; + char *text; + int text_len; + + NK_ASSERT(str); + NK_ASSERT(unicode); + NK_ASSERT(len); + + if (!str || !unicode || !len) return 0; + if (pos < 0) { + *unicode = 0; + *len = 0; + return 0; + } + + text = (char*)str->buffer.memory.ptr; + text_len = (int)str->buffer.allocated; + glyph_len = nk_utf_decode(text, unicode, text_len); + while (glyph_len) { + if (i == pos) { + *len = glyph_len; + break; + } + + i++; + src_len = src_len + glyph_len; + glyph_len = nk_utf_decode(text + src_len, unicode, text_len - src_len); + } + if (i != pos) return 0; + return text + src_len; +} +NK_API const char* +nk_str_at_char_const(const struct nk_str *s, int pos) +{ + NK_ASSERT(s); + if (!s || pos > (int)s->buffer.allocated) return 0; + return nk_ptr_add(char, s->buffer.memory.ptr, pos); +} +NK_API const char* +nk_str_at_const(const struct nk_str *str, int pos, nk_rune *unicode, int *len) +{ + int i = 0; + int src_len = 0; + int glyph_len = 0; + char *text; + int text_len; + + NK_ASSERT(str); + NK_ASSERT(unicode); + NK_ASSERT(len); + + if (!str || !unicode || !len) return 0; + if (pos < 0) { + *unicode = 0; + *len = 0; + return 0; + } + + text = (char*)str->buffer.memory.ptr; + text_len = (int)str->buffer.allocated; + glyph_len = nk_utf_decode(text, unicode, text_len); + while (glyph_len) { + if (i == pos) { + *len = glyph_len; + break; + } + + i++; + src_len = src_len + glyph_len; + glyph_len = nk_utf_decode(text + src_len, unicode, text_len - src_len); + } + if (i != pos) return 0; + return text + src_len; +} +NK_API nk_rune +nk_str_rune_at(const struct nk_str *str, int pos) +{ + int len; + nk_rune unicode = 0; + nk_str_at_const(str, pos, &unicode, &len); + return unicode; +} +NK_API char* +nk_str_get(struct nk_str *s) +{ + NK_ASSERT(s); + if (!s || !s->len || !s->buffer.allocated) return 0; + return (char*)s->buffer.memory.ptr; +} +NK_API const char* +nk_str_get_const(const struct nk_str *s) +{ + NK_ASSERT(s); + if (!s || !s->len || !s->buffer.allocated) return 0; + return (const char*)s->buffer.memory.ptr; +} +NK_API int +nk_str_len(struct nk_str *s) +{ + NK_ASSERT(s); + if (!s || !s->len || !s->buffer.allocated) return 0; + return s->len; +} +NK_API int +nk_str_len_char(struct nk_str *s) +{ + NK_ASSERT(s); + if (!s || !s->len || !s->buffer.allocated) return 0; + return (int)s->buffer.allocated; +} +NK_API void +nk_str_clear(struct nk_str *str) +{ + NK_ASSERT(str); + nk_buffer_clear(&str->buffer); + str->len = 0; +} +NK_API void +nk_str_free(struct nk_str *str) +{ + NK_ASSERT(str); + nk_buffer_free(&str->buffer); + str->len = 0; +} + + + + + +/* ============================================================== + * + * DRAW + * + * ===============================================================*/ +NK_LIB void +nk_command_buffer_init(struct nk_command_buffer *cb, + struct nk_buffer *b, enum nk_command_clipping clip) +{ + NK_ASSERT(cb); + NK_ASSERT(b); + if (!cb || !b) return; + cb->base = b; + cb->use_clipping = (int)clip; + cb->begin = b->allocated; + cb->end = b->allocated; + cb->last = b->allocated; +} +NK_LIB void +nk_command_buffer_reset(struct nk_command_buffer *b) +{ + NK_ASSERT(b); + if (!b) return; + b->begin = 0; + b->end = 0; + b->last = 0; + b->clip = nk_null_rect; +#ifdef NK_INCLUDE_COMMAND_USERDATA + b->userdata.ptr = 0; +#endif +} +NK_LIB void* +nk_command_buffer_push(struct nk_command_buffer* b, + enum nk_command_type t, nk_size size) +{ + NK_STORAGE const nk_size align = NK_ALIGNOF(struct nk_command); + struct nk_command *cmd; + nk_size alignment; + void *unaligned; + void *memory; + + NK_ASSERT(b); + NK_ASSERT(b->base); + if (!b) return 0; + cmd = (struct nk_command*)nk_buffer_alloc(b->base,NK_BUFFER_FRONT,size,align); + if (!cmd) return 0; + + /* make sure the offset to the next command is aligned */ + b->last = (nk_size)((nk_byte*)cmd - (nk_byte*)b->base->memory.ptr); + unaligned = (nk_byte*)cmd + size; + memory = NK_ALIGN_PTR(unaligned, align); + alignment = (nk_size)((nk_byte*)memory - (nk_byte*)unaligned); +#ifdef NK_ZERO_COMMAND_MEMORY + NK_MEMSET(cmd, 0, size + alignment); +#endif + + cmd->type = t; + cmd->next = b->base->allocated + alignment; +#ifdef NK_INCLUDE_COMMAND_USERDATA + cmd->userdata = b->userdata; +#endif + b->end = cmd->next; + return cmd; +} +NK_API void +nk_push_scissor(struct nk_command_buffer *b, struct nk_rect r) +{ + struct nk_command_scissor *cmd; + NK_ASSERT(b); + if (!b) return; + + b->clip.x = r.x; + b->clip.y = r.y; + b->clip.w = r.w; + b->clip.h = r.h; + cmd = (struct nk_command_scissor*) + nk_command_buffer_push(b, NK_COMMAND_SCISSOR, sizeof(*cmd)); + + if (!cmd) return; + cmd->x = (short)r.x; + cmd->y = (short)r.y; + cmd->w = (unsigned short)NK_MAX(0, r.w); + cmd->h = (unsigned short)NK_MAX(0, r.h); +} +NK_API void +nk_stroke_line(struct nk_command_buffer *b, float x0, float y0, + float x1, float y1, float line_thickness, struct nk_color c) +{ + struct nk_command_line *cmd; + NK_ASSERT(b); + if (!b || line_thickness <= 0) return; + cmd = (struct nk_command_line*) + nk_command_buffer_push(b, NK_COMMAND_LINE, sizeof(*cmd)); + if (!cmd) return; + cmd->line_thickness = (unsigned short)line_thickness; + cmd->begin.x = (short)x0; + cmd->begin.y = (short)y0; + cmd->end.x = (short)x1; + cmd->end.y = (short)y1; + cmd->color = c; +} +NK_API void +nk_stroke_curve(struct nk_command_buffer *b, float ax, float ay, + float ctrl0x, float ctrl0y, float ctrl1x, float ctrl1y, + float bx, float by, float line_thickness, struct nk_color col) +{ + struct nk_command_curve *cmd; + NK_ASSERT(b); + if (!b || col.a == 0 || line_thickness <= 0) return; + + cmd = (struct nk_command_curve*) + nk_command_buffer_push(b, NK_COMMAND_CURVE, sizeof(*cmd)); + if (!cmd) return; + cmd->line_thickness = (unsigned short)line_thickness; + cmd->begin.x = (short)ax; + cmd->begin.y = (short)ay; + cmd->ctrl[0].x = (short)ctrl0x; + cmd->ctrl[0].y = (short)ctrl0y; + cmd->ctrl[1].x = (short)ctrl1x; + cmd->ctrl[1].y = (short)ctrl1y; + cmd->end.x = (short)bx; + cmd->end.y = (short)by; + cmd->color = col; +} +NK_API void +nk_stroke_rect(struct nk_command_buffer *b, struct nk_rect rect, + float rounding, float line_thickness, struct nk_color c) +{ + struct nk_command_rect *cmd; + NK_ASSERT(b); + if (!b || c.a == 0 || rect.w == 0 || rect.h == 0 || line_thickness <= 0) return; + if (b->use_clipping) { + const struct nk_rect *clip = &b->clip; + if (!NK_INTERSECT(rect.x, rect.y, rect.w, rect.h, + clip->x, clip->y, clip->w, clip->h)) return; + } + cmd = (struct nk_command_rect*) + nk_command_buffer_push(b, NK_COMMAND_RECT, sizeof(*cmd)); + if (!cmd) return; + cmd->rounding = (unsigned short)rounding; + cmd->line_thickness = (unsigned short)line_thickness; + cmd->x = (short)rect.x; + cmd->y = (short)rect.y; + cmd->w = (unsigned short)NK_MAX(0, rect.w); + cmd->h = (unsigned short)NK_MAX(0, rect.h); + cmd->color = c; +} +NK_API void +nk_fill_rect(struct nk_command_buffer *b, struct nk_rect rect, + float rounding, struct nk_color c) +{ + struct nk_command_rect_filled *cmd; + NK_ASSERT(b); + if (!b || c.a == 0 || rect.w == 0 || rect.h == 0) return; + if (b->use_clipping) { + const struct nk_rect *clip = &b->clip; + if (!NK_INTERSECT(rect.x, rect.y, rect.w, rect.h, + clip->x, clip->y, clip->w, clip->h)) return; + } + + cmd = (struct nk_command_rect_filled*) + nk_command_buffer_push(b, NK_COMMAND_RECT_FILLED, sizeof(*cmd)); + if (!cmd) return; + cmd->rounding = (unsigned short)rounding; + cmd->x = (short)rect.x; + cmd->y = (short)rect.y; + cmd->w = (unsigned short)NK_MAX(0, rect.w); + cmd->h = (unsigned short)NK_MAX(0, rect.h); + cmd->color = c; +} +NK_API void +nk_fill_rect_multi_color(struct nk_command_buffer *b, struct nk_rect rect, + struct nk_color left, struct nk_color top, struct nk_color right, + struct nk_color bottom) +{ + struct nk_command_rect_multi_color *cmd; + NK_ASSERT(b); + if (!b || rect.w == 0 || rect.h == 0) return; + if (b->use_clipping) { + const struct nk_rect *clip = &b->clip; + if (!NK_INTERSECT(rect.x, rect.y, rect.w, rect.h, + clip->x, clip->y, clip->w, clip->h)) return; + } + + cmd = (struct nk_command_rect_multi_color*) + nk_command_buffer_push(b, NK_COMMAND_RECT_MULTI_COLOR, sizeof(*cmd)); + if (!cmd) return; + cmd->x = (short)rect.x; + cmd->y = (short)rect.y; + cmd->w = (unsigned short)NK_MAX(0, rect.w); + cmd->h = (unsigned short)NK_MAX(0, rect.h); + cmd->left = left; + cmd->top = top; + cmd->right = right; + cmd->bottom = bottom; +} +NK_API void +nk_stroke_circle(struct nk_command_buffer *b, struct nk_rect r, + float line_thickness, struct nk_color c) +{ + struct nk_command_circle *cmd; + if (!b || r.w == 0 || r.h == 0 || line_thickness <= 0) return; + if (b->use_clipping) { + const struct nk_rect *clip = &b->clip; + if (!NK_INTERSECT(r.x, r.y, r.w, r.h, clip->x, clip->y, clip->w, clip->h)) + return; + } + + cmd = (struct nk_command_circle*) + nk_command_buffer_push(b, NK_COMMAND_CIRCLE, sizeof(*cmd)); + if (!cmd) return; + cmd->line_thickness = (unsigned short)line_thickness; + cmd->x = (short)r.x; + cmd->y = (short)r.y; + cmd->w = (unsigned short)NK_MAX(r.w, 0); + cmd->h = (unsigned short)NK_MAX(r.h, 0); + cmd->color = c; +} +NK_API void +nk_fill_circle(struct nk_command_buffer *b, struct nk_rect r, struct nk_color c) +{ + struct nk_command_circle_filled *cmd; + NK_ASSERT(b); + if (!b || c.a == 0 || r.w == 0 || r.h == 0) return; + if (b->use_clipping) { + const struct nk_rect *clip = &b->clip; + if (!NK_INTERSECT(r.x, r.y, r.w, r.h, clip->x, clip->y, clip->w, clip->h)) + return; + } + + cmd = (struct nk_command_circle_filled*) + nk_command_buffer_push(b, NK_COMMAND_CIRCLE_FILLED, sizeof(*cmd)); + if (!cmd) return; + cmd->x = (short)r.x; + cmd->y = (short)r.y; + cmd->w = (unsigned short)NK_MAX(r.w, 0); + cmd->h = (unsigned short)NK_MAX(r.h, 0); + cmd->color = c; +} +NK_API void +nk_stroke_arc(struct nk_command_buffer *b, float cx, float cy, float radius, + float a_min, float a_max, float line_thickness, struct nk_color c) +{ + struct nk_command_arc *cmd; + if (!b || c.a == 0 || line_thickness <= 0) return; + cmd = (struct nk_command_arc*) + nk_command_buffer_push(b, NK_COMMAND_ARC, sizeof(*cmd)); + if (!cmd) return; + cmd->line_thickness = (unsigned short)line_thickness; + cmd->cx = (short)cx; + cmd->cy = (short)cy; + cmd->r = (unsigned short)radius; + cmd->a[0] = a_min; + cmd->a[1] = a_max; + cmd->color = c; +} +NK_API void +nk_fill_arc(struct nk_command_buffer *b, float cx, float cy, float radius, + float a_min, float a_max, struct nk_color c) +{ + struct nk_command_arc_filled *cmd; + NK_ASSERT(b); + if (!b || c.a == 0) return; + cmd = (struct nk_command_arc_filled*) + nk_command_buffer_push(b, NK_COMMAND_ARC_FILLED, sizeof(*cmd)); + if (!cmd) return; + cmd->cx = (short)cx; + cmd->cy = (short)cy; + cmd->r = (unsigned short)radius; + cmd->a[0] = a_min; + cmd->a[1] = a_max; + cmd->color = c; +} +NK_API void +nk_stroke_triangle(struct nk_command_buffer *b, float x0, float y0, float x1, + float y1, float x2, float y2, float line_thickness, struct nk_color c) +{ + struct nk_command_triangle *cmd; + NK_ASSERT(b); + if (!b || c.a == 0 || line_thickness <= 0) return; + if (b->use_clipping) { + const struct nk_rect *clip = &b->clip; + if (!NK_INBOX(x0, y0, clip->x, clip->y, clip->w, clip->h) && + !NK_INBOX(x1, y1, clip->x, clip->y, clip->w, clip->h) && + !NK_INBOX(x2, y2, clip->x, clip->y, clip->w, clip->h)) + return; + } + + cmd = (struct nk_command_triangle*) + nk_command_buffer_push(b, NK_COMMAND_TRIANGLE, sizeof(*cmd)); + if (!cmd) return; + cmd->line_thickness = (unsigned short)line_thickness; + cmd->a.x = (short)x0; + cmd->a.y = (short)y0; + cmd->b.x = (short)x1; + cmd->b.y = (short)y1; + cmd->c.x = (short)x2; + cmd->c.y = (short)y2; + cmd->color = c; +} +NK_API void +nk_fill_triangle(struct nk_command_buffer *b, float x0, float y0, float x1, + float y1, float x2, float y2, struct nk_color c) +{ + struct nk_command_triangle_filled *cmd; + NK_ASSERT(b); + if (!b || c.a == 0) return; + if (!b) return; + if (b->use_clipping) { + const struct nk_rect *clip = &b->clip; + if (!NK_INBOX(x0, y0, clip->x, clip->y, clip->w, clip->h) && + !NK_INBOX(x1, y1, clip->x, clip->y, clip->w, clip->h) && + !NK_INBOX(x2, y2, clip->x, clip->y, clip->w, clip->h)) + return; + } + + cmd = (struct nk_command_triangle_filled*) + nk_command_buffer_push(b, NK_COMMAND_TRIANGLE_FILLED, sizeof(*cmd)); + if (!cmd) return; + cmd->a.x = (short)x0; + cmd->a.y = (short)y0; + cmd->b.x = (short)x1; + cmd->b.y = (short)y1; + cmd->c.x = (short)x2; + cmd->c.y = (short)y2; + cmd->color = c; +} +NK_API void +nk_stroke_polygon(struct nk_command_buffer *b, float *points, int point_count, + float line_thickness, struct nk_color col) +{ + int i; + nk_size size = 0; + struct nk_command_polygon *cmd; + + NK_ASSERT(b); + if (!b || col.a == 0 || line_thickness <= 0) return; + size = sizeof(*cmd) + sizeof(short) * 2 * (nk_size)point_count; + cmd = (struct nk_command_polygon*) nk_command_buffer_push(b, NK_COMMAND_POLYGON, size); + if (!cmd) return; + cmd->color = col; + cmd->line_thickness = (unsigned short)line_thickness; + cmd->point_count = (unsigned short)point_count; + for (i = 0; i < point_count; ++i) { + cmd->points[i].x = (short)points[i*2]; + cmd->points[i].y = (short)points[i*2+1]; + } +} +NK_API void +nk_fill_polygon(struct nk_command_buffer *b, float *points, int point_count, + struct nk_color col) +{ + int i; + nk_size size = 0; + struct nk_command_polygon_filled *cmd; + + NK_ASSERT(b); + if (!b || col.a == 0) return; + size = sizeof(*cmd) + sizeof(short) * 2 * (nk_size)point_count; + cmd = (struct nk_command_polygon_filled*) + nk_command_buffer_push(b, NK_COMMAND_POLYGON_FILLED, size); + if (!cmd) return; + cmd->color = col; + cmd->point_count = (unsigned short)point_count; + for (i = 0; i < point_count; ++i) { + cmd->points[i].x = (short)points[i*2+0]; + cmd->points[i].y = (short)points[i*2+1]; + } +} +NK_API void +nk_stroke_polyline(struct nk_command_buffer *b, float *points, int point_count, + float line_thickness, struct nk_color col) +{ + int i; + nk_size size = 0; + struct nk_command_polyline *cmd; + + NK_ASSERT(b); + if (!b || col.a == 0 || line_thickness <= 0) return; + size = sizeof(*cmd) + sizeof(short) * 2 * (nk_size)point_count; + cmd = (struct nk_command_polyline*) nk_command_buffer_push(b, NK_COMMAND_POLYLINE, size); + if (!cmd) return; + cmd->color = col; + cmd->point_count = (unsigned short)point_count; + cmd->line_thickness = (unsigned short)line_thickness; + for (i = 0; i < point_count; ++i) { + cmd->points[i].x = (short)points[i*2]; + cmd->points[i].y = (short)points[i*2+1]; + } +} +NK_API void +nk_draw_image(struct nk_command_buffer *b, struct nk_rect r, + const struct nk_image *img, struct nk_color col) +{ + struct nk_command_image *cmd; + NK_ASSERT(b); + if (!b) return; + if (b->use_clipping) { + const struct nk_rect *c = &b->clip; + if (c->w == 0 || c->h == 0 || !NK_INTERSECT(r.x, r.y, r.w, r.h, c->x, c->y, c->w, c->h)) + return; + } + + cmd = (struct nk_command_image*) + nk_command_buffer_push(b, NK_COMMAND_IMAGE, sizeof(*cmd)); + if (!cmd) return; + cmd->x = (short)r.x; + cmd->y = (short)r.y; + cmd->w = (unsigned short)NK_MAX(0, r.w); + cmd->h = (unsigned short)NK_MAX(0, r.h); + cmd->img = *img; + cmd->col = col; +} +NK_API void +nk_draw_nine_slice(struct nk_command_buffer *b, struct nk_rect r, + const struct nk_nine_slice *slc, struct nk_color col) +{ + struct nk_image img; + const struct nk_image *slcimg = (const struct nk_image*)slc; + nk_ushort rgnX, rgnY, rgnW, rgnH; + rgnX = slcimg->region[0]; + rgnY = slcimg->region[1]; + rgnW = slcimg->region[2]; + rgnH = slcimg->region[3]; + + /* top-left */ + img.handle = slcimg->handle; + img.w = slcimg->w; + img.h = slcimg->h; + img.region[0] = rgnX; + img.region[1] = rgnY; + img.region[2] = slc->l; + img.region[3] = slc->t; + + nk_draw_image(b, + nk_rect(r.x, r.y, (float)slc->l, (float)slc->t), + &img, col); + +#define IMG_RGN(x, y, w, h) img.region[0] = (nk_ushort)(x); img.region[1] = (nk_ushort)(y); img.region[2] = (nk_ushort)(w); img.region[3] = (nk_ushort)(h); + + /* top-center */ + IMG_RGN(rgnX + slc->l, rgnY, rgnW - slc->l - slc->r, slc->t); + nk_draw_image(b, + nk_rect(r.x + (float)slc->l, r.y, (float)(r.w - slc->l - slc->r), (float)slc->t), + &img, col); + + /* top-right */ + IMG_RGN(rgnX + rgnW - slc->r, rgnY, slc->r, slc->t); + nk_draw_image(b, + nk_rect(r.x + r.w - (float)slc->r, r.y, (float)slc->r, (float)slc->t), + &img, col); + + /* center-left */ + IMG_RGN(rgnX, rgnY + slc->t, slc->l, rgnH - slc->t - slc->b); + nk_draw_image(b, + nk_rect(r.x, r.y + (float)slc->t, (float)slc->l, (float)(r.h - slc->t - slc->b)), + &img, col); + + /* center */ + IMG_RGN(rgnX + slc->l, rgnY + slc->t, rgnW - slc->l - slc->r, rgnH - slc->t - slc->b); + nk_draw_image(b, + nk_rect(r.x + (float)slc->l, r.y + (float)slc->t, (float)(r.w - slc->l - slc->r), (float)(r.h - slc->t - slc->b)), + &img, col); + + /* center-right */ + IMG_RGN(rgnX + rgnW - slc->r, rgnY + slc->t, slc->r, rgnH - slc->t - slc->b); + nk_draw_image(b, + nk_rect(r.x + r.w - (float)slc->r, r.y + (float)slc->t, (float)slc->r, (float)(r.h - slc->t - slc->b)), + &img, col); + + /* bottom-left */ + IMG_RGN(rgnX, rgnY + rgnH - slc->b, slc->l, slc->b); + nk_draw_image(b, + nk_rect(r.x, r.y + r.h - (float)slc->b, (float)slc->l, (float)slc->b), + &img, col); + + /* bottom-center */ + IMG_RGN(rgnX + slc->l, rgnY + rgnH - slc->b, rgnW - slc->l - slc->r, slc->b); + nk_draw_image(b, + nk_rect(r.x + (float)slc->l, r.y + r.h - (float)slc->b, (float)(r.w - slc->l - slc->r), (float)slc->b), + &img, col); + + /* bottom-right */ + IMG_RGN(rgnX + rgnW - slc->r, rgnY + rgnH - slc->b, slc->r, slc->b); + nk_draw_image(b, + nk_rect(r.x + r.w - (float)slc->r, r.y + r.h - (float)slc->b, (float)slc->r, (float)slc->b), + &img, col); + +#undef IMG_RGN +} +NK_API void +nk_push_custom(struct nk_command_buffer *b, struct nk_rect r, + nk_command_custom_callback cb, nk_handle usr) +{ + struct nk_command_custom *cmd; + NK_ASSERT(b); + if (!b) return; + if (b->use_clipping) { + const struct nk_rect *c = &b->clip; + if (c->w == 0 || c->h == 0 || !NK_INTERSECT(r.x, r.y, r.w, r.h, c->x, c->y, c->w, c->h)) + return; + } + + cmd = (struct nk_command_custom*) + nk_command_buffer_push(b, NK_COMMAND_CUSTOM, sizeof(*cmd)); + if (!cmd) return; + cmd->x = (short)r.x; + cmd->y = (short)r.y; + cmd->w = (unsigned short)NK_MAX(0, r.w); + cmd->h = (unsigned short)NK_MAX(0, r.h); + cmd->callback_data = usr; + cmd->callback = cb; +} +NK_API void +nk_draw_text(struct nk_command_buffer *b, struct nk_rect r, + const char *string, int length, const struct nk_user_font *font, + struct nk_color bg, struct nk_color fg) +{ + float text_width = 0; + struct nk_command_text *cmd; + + NK_ASSERT(b); + NK_ASSERT(font); + if (!b || !string || !length || (bg.a == 0 && fg.a == 0)) return; + if (b->use_clipping) { + const struct nk_rect *c = &b->clip; + if (c->w == 0 || c->h == 0 || !NK_INTERSECT(r.x, r.y, r.w, r.h, c->x, c->y, c->w, c->h)) + return; + } + + /* make sure text fits inside bounds */ + text_width = font->width(font->userdata, font->height, string, length); + if (text_width > r.w){ + int glyphs = 0; + float txt_width = (float)text_width; + length = nk_text_clamp(font, string, length, r.w, &glyphs, &txt_width, 0,0); + } + + if (!length) return; + cmd = (struct nk_command_text*) + nk_command_buffer_push(b, NK_COMMAND_TEXT, sizeof(*cmd) + (nk_size)(length + 1)); + if (!cmd) return; + cmd->x = (short)r.x; + cmd->y = (short)r.y; + cmd->w = (unsigned short)r.w; + cmd->h = (unsigned short)r.h; + cmd->background = bg; + cmd->foreground = fg; + cmd->font = font; + cmd->length = length; + cmd->height = font->height; + NK_MEMCPY(cmd->string, string, (nk_size)length); + cmd->string[length] = '\0'; +} + + + + + +/* =============================================================== + * + * VERTEX + * + * ===============================================================*/ +#ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT +NK_API void +nk_draw_list_init(struct nk_draw_list *list) +{ + nk_size i = 0; + NK_ASSERT(list); + if (!list) return; + nk_zero(list, sizeof(*list)); + for (i = 0; i < NK_LEN(list->circle_vtx); ++i) { + const float a = ((float)i / (float)NK_LEN(list->circle_vtx)) * 2 * NK_PI; + list->circle_vtx[i].x = (float)NK_COS(a); + list->circle_vtx[i].y = (float)NK_SIN(a); + } +} +NK_API void +nk_draw_list_setup(struct nk_draw_list *canvas, const struct nk_convert_config *config, + struct nk_buffer *cmds, struct nk_buffer *vertices, struct nk_buffer *elements, + enum nk_anti_aliasing line_aa, enum nk_anti_aliasing shape_aa) +{ + NK_ASSERT(canvas); + NK_ASSERT(config); + NK_ASSERT(cmds); + NK_ASSERT(vertices); + NK_ASSERT(elements); + if (!canvas || !config || !cmds || !vertices || !elements) + return; + + canvas->buffer = cmds; + canvas->config = *config; + canvas->elements = elements; + canvas->vertices = vertices; + canvas->line_AA = line_aa; + canvas->shape_AA = shape_aa; + canvas->clip_rect = nk_null_rect; + + canvas->cmd_offset = 0; + canvas->element_count = 0; + canvas->vertex_count = 0; + canvas->cmd_offset = 0; + canvas->cmd_count = 0; + canvas->path_count = 0; +} +NK_API const struct nk_draw_command* +nk__draw_list_begin(const struct nk_draw_list *canvas, const struct nk_buffer *buffer) +{ + nk_byte *memory; + nk_size offset; + const struct nk_draw_command *cmd; + + NK_ASSERT(buffer); + if (!buffer || !buffer->size || !canvas->cmd_count) + return 0; + + memory = (nk_byte*)buffer->memory.ptr; + offset = buffer->memory.size - canvas->cmd_offset; + cmd = nk_ptr_add(const struct nk_draw_command, memory, offset); + return cmd; +} +NK_API const struct nk_draw_command* +nk__draw_list_end(const struct nk_draw_list *canvas, const struct nk_buffer *buffer) +{ + nk_size size; + nk_size offset; + nk_byte *memory; + const struct nk_draw_command *end; + + NK_ASSERT(buffer); + NK_ASSERT(canvas); + if (!buffer || !canvas) + return 0; + + memory = (nk_byte*)buffer->memory.ptr; + size = buffer->memory.size; + offset = size - canvas->cmd_offset; + end = nk_ptr_add(const struct nk_draw_command, memory, offset); + end -= (canvas->cmd_count-1); + return end; +} +NK_API const struct nk_draw_command* +nk__draw_list_next(const struct nk_draw_command *cmd, + const struct nk_buffer *buffer, const struct nk_draw_list *canvas) +{ + const struct nk_draw_command *end; + NK_ASSERT(buffer); + NK_ASSERT(canvas); + if (!cmd || !buffer || !canvas) + return 0; + + end = nk__draw_list_end(canvas, buffer); + if (cmd <= end) return 0; + return (cmd-1); +} +NK_INTERN struct nk_vec2* +nk_draw_list_alloc_path(struct nk_draw_list *list, int count) +{ + struct nk_vec2 *points; + NK_STORAGE const nk_size point_align = NK_ALIGNOF(struct nk_vec2); + NK_STORAGE const nk_size point_size = sizeof(struct nk_vec2); + points = (struct nk_vec2*) + nk_buffer_alloc(list->buffer, NK_BUFFER_FRONT, + point_size * (nk_size)count, point_align); + + if (!points) return 0; + if (!list->path_offset) { + void *memory = nk_buffer_memory(list->buffer); + list->path_offset = (unsigned int)((nk_byte*)points - (nk_byte*)memory); + } + list->path_count += (unsigned int)count; + return points; +} +NK_INTERN struct nk_vec2 +nk_draw_list_path_last(struct nk_draw_list *list) +{ + void *memory; + struct nk_vec2 *point; + NK_ASSERT(list->path_count); + memory = nk_buffer_memory(list->buffer); + point = nk_ptr_add(struct nk_vec2, memory, list->path_offset); + point += (list->path_count-1); + return *point; +} +NK_INTERN struct nk_draw_command* +nk_draw_list_push_command(struct nk_draw_list *list, struct nk_rect clip, + nk_handle texture) +{ + NK_STORAGE const nk_size cmd_align = NK_ALIGNOF(struct nk_draw_command); + NK_STORAGE const nk_size cmd_size = sizeof(struct nk_draw_command); + struct nk_draw_command *cmd; + + NK_ASSERT(list); + cmd = (struct nk_draw_command*) + nk_buffer_alloc(list->buffer, NK_BUFFER_BACK, cmd_size, cmd_align); + + if (!cmd) return 0; + if (!list->cmd_count) { + nk_byte *memory = (nk_byte*)nk_buffer_memory(list->buffer); + nk_size total = nk_buffer_total(list->buffer); + memory = nk_ptr_add(nk_byte, memory, total); + list->cmd_offset = (nk_size)(memory - (nk_byte*)cmd); + } + + cmd->elem_count = 0; + cmd->clip_rect = clip; + cmd->texture = texture; +#ifdef NK_INCLUDE_COMMAND_USERDATA + cmd->userdata = list->userdata; +#endif + + list->cmd_count++; + list->clip_rect = clip; + return cmd; +} +NK_INTERN struct nk_draw_command* +nk_draw_list_command_last(struct nk_draw_list *list) +{ + void *memory; + nk_size size; + struct nk_draw_command *cmd; + NK_ASSERT(list->cmd_count); + + memory = nk_buffer_memory(list->buffer); + size = nk_buffer_total(list->buffer); + cmd = nk_ptr_add(struct nk_draw_command, memory, size - list->cmd_offset); + return (cmd - (list->cmd_count-1)); +} +NK_INTERN void +nk_draw_list_add_clip(struct nk_draw_list *list, struct nk_rect rect) +{ + NK_ASSERT(list); + if (!list) return; + if (!list->cmd_count) { + nk_draw_list_push_command(list, rect, list->config.tex_null.texture); + } else { + struct nk_draw_command *prev = nk_draw_list_command_last(list); + if (prev->elem_count == 0) + prev->clip_rect = rect; + nk_draw_list_push_command(list, rect, prev->texture); + } +} +NK_INTERN void +nk_draw_list_push_image(struct nk_draw_list *list, nk_handle texture) +{ + NK_ASSERT(list); + if (!list) return; + if (!list->cmd_count) { + nk_draw_list_push_command(list, nk_null_rect, texture); + } else { + struct nk_draw_command *prev = nk_draw_list_command_last(list); + if (prev->elem_count == 0) { + prev->texture = texture; + #ifdef NK_INCLUDE_COMMAND_USERDATA + prev->userdata = list->userdata; + #endif + } else if (prev->texture.id != texture.id + #ifdef NK_INCLUDE_COMMAND_USERDATA + || prev->userdata.id != list->userdata.id + #endif + ) nk_draw_list_push_command(list, prev->clip_rect, texture); + } +} +#ifdef NK_INCLUDE_COMMAND_USERDATA +NK_API void +nk_draw_list_push_userdata(struct nk_draw_list *list, nk_handle userdata) +{ + list->userdata = userdata; +} +#endif +NK_INTERN void* +nk_draw_list_alloc_vertices(struct nk_draw_list *list, nk_size count) +{ + void *vtx; + NK_ASSERT(list); + if (!list) return 0; + vtx = nk_buffer_alloc(list->vertices, NK_BUFFER_FRONT, + list->config.vertex_size*count, list->config.vertex_alignment); + if (!vtx) return 0; + list->vertex_count += (unsigned int)count; + + /* This assert triggers because your are drawing a lot of stuff and nuklear + * defined `nk_draw_index` as `nk_ushort` to safe space be default. + * + * So you reached the maximum number of indices or rather vertexes. + * To solve this issue please change typedef `nk_draw_index` to `nk_uint` + * and don't forget to specify the new element size in your drawing + * backend (OpenGL, DirectX, ...). For example in OpenGL for `glDrawElements` + * instead of specifying `GL_UNSIGNED_SHORT` you have to define `GL_UNSIGNED_INT`. + * Sorry for the inconvenience. */ + if(sizeof(nk_draw_index)==2) NK_ASSERT((list->vertex_count < NK_USHORT_MAX && + "To many vertices for 16-bit vertex indices. Please read comment above on how to solve this problem")); + return vtx; +} +NK_INTERN nk_draw_index* +nk_draw_list_alloc_elements(struct nk_draw_list *list, nk_size count) +{ + nk_draw_index *ids; + struct nk_draw_command *cmd; + NK_STORAGE const nk_size elem_align = NK_ALIGNOF(nk_draw_index); + NK_STORAGE const nk_size elem_size = sizeof(nk_draw_index); + NK_ASSERT(list); + if (!list) return 0; + + ids = (nk_draw_index*) + nk_buffer_alloc(list->elements, NK_BUFFER_FRONT, elem_size*count, elem_align); + if (!ids) return 0; + cmd = nk_draw_list_command_last(list); + list->element_count += (unsigned int)count; + cmd->elem_count += (unsigned int)count; + return ids; +} +NK_INTERN int +nk_draw_vertex_layout_element_is_end_of_layout( + const struct nk_draw_vertex_layout_element *element) +{ + return (element->attribute == NK_VERTEX_ATTRIBUTE_COUNT || + element->format == NK_FORMAT_COUNT); +} +NK_INTERN void +nk_draw_vertex_color(void *attr, const float *vals, + enum nk_draw_vertex_layout_format format) +{ + /* if this triggers you tried to provide a value format for a color */ + float val[4]; + NK_ASSERT(format >= NK_FORMAT_COLOR_BEGIN); + NK_ASSERT(format <= NK_FORMAT_COLOR_END); + if (format < NK_FORMAT_COLOR_BEGIN || format > NK_FORMAT_COLOR_END) return; + + val[0] = NK_SATURATE(vals[0]); + val[1] = NK_SATURATE(vals[1]); + val[2] = NK_SATURATE(vals[2]); + val[3] = NK_SATURATE(vals[3]); + + switch (format) { + default: NK_ASSERT(0 && "Invalid vertex layout color format"); break; + case NK_FORMAT_R8G8B8A8: + case NK_FORMAT_R8G8B8: { + struct nk_color col = nk_rgba_fv(val); + NK_MEMCPY(attr, &col.r, sizeof(col)); + } break; + case NK_FORMAT_B8G8R8A8: { + struct nk_color col = nk_rgba_fv(val); + struct nk_color bgra = nk_rgba(col.b, col.g, col.r, col.a); + NK_MEMCPY(attr, &bgra, sizeof(bgra)); + } break; + case NK_FORMAT_R16G15B16: { + nk_ushort col[3]; + col[0] = (nk_ushort)(val[0]*(float)NK_USHORT_MAX); + col[1] = (nk_ushort)(val[1]*(float)NK_USHORT_MAX); + col[2] = (nk_ushort)(val[2]*(float)NK_USHORT_MAX); + NK_MEMCPY(attr, col, sizeof(col)); + } break; + case NK_FORMAT_R16G15B16A16: { + nk_ushort col[4]; + col[0] = (nk_ushort)(val[0]*(float)NK_USHORT_MAX); + col[1] = (nk_ushort)(val[1]*(float)NK_USHORT_MAX); + col[2] = (nk_ushort)(val[2]*(float)NK_USHORT_MAX); + col[3] = (nk_ushort)(val[3]*(float)NK_USHORT_MAX); + NK_MEMCPY(attr, col, sizeof(col)); + } break; + case NK_FORMAT_R32G32B32: { + nk_uint col[3]; + col[0] = (nk_uint)(val[0]*(float)NK_UINT_MAX); + col[1] = (nk_uint)(val[1]*(float)NK_UINT_MAX); + col[2] = (nk_uint)(val[2]*(float)NK_UINT_MAX); + NK_MEMCPY(attr, col, sizeof(col)); + } break; + case NK_FORMAT_R32G32B32A32: { + nk_uint col[4]; + col[0] = (nk_uint)(val[0]*(float)NK_UINT_MAX); + col[1] = (nk_uint)(val[1]*(float)NK_UINT_MAX); + col[2] = (nk_uint)(val[2]*(float)NK_UINT_MAX); + col[3] = (nk_uint)(val[3]*(float)NK_UINT_MAX); + NK_MEMCPY(attr, col, sizeof(col)); + } break; + case NK_FORMAT_R32G32B32A32_FLOAT: + NK_MEMCPY(attr, val, sizeof(float)*4); + break; + case NK_FORMAT_R32G32B32A32_DOUBLE: { + double col[4]; + col[0] = (double)val[0]; + col[1] = (double)val[1]; + col[2] = (double)val[2]; + col[3] = (double)val[3]; + NK_MEMCPY(attr, col, sizeof(col)); + } break; + case NK_FORMAT_RGB32: + case NK_FORMAT_RGBA32: { + struct nk_color col = nk_rgba_fv(val); + nk_uint color = nk_color_u32(col); + NK_MEMCPY(attr, &color, sizeof(color)); + } break; } +} +NK_INTERN void +nk_draw_vertex_element(void *dst, const float *values, int value_count, + enum nk_draw_vertex_layout_format format) +{ + int value_index; + void *attribute = dst; + /* if this triggers you tried to provide a color format for a value */ + NK_ASSERT(format < NK_FORMAT_COLOR_BEGIN); + if (format >= NK_FORMAT_COLOR_BEGIN && format <= NK_FORMAT_COLOR_END) return; + for (value_index = 0; value_index < value_count; ++value_index) { + switch (format) { + default: NK_ASSERT(0 && "invalid vertex layout format"); break; + case NK_FORMAT_SCHAR: { + char value = (char)NK_CLAMP((float)NK_SCHAR_MIN, values[value_index], (float)NK_SCHAR_MAX); + NK_MEMCPY(attribute, &value, sizeof(value)); + attribute = (void*)((char*)attribute + sizeof(char)); + } break; + case NK_FORMAT_SSHORT: { + nk_short value = (nk_short)NK_CLAMP((float)NK_SSHORT_MIN, values[value_index], (float)NK_SSHORT_MAX); + NK_MEMCPY(attribute, &value, sizeof(value)); + attribute = (void*)((char*)attribute + sizeof(value)); + } break; + case NK_FORMAT_SINT: { + nk_int value = (nk_int)NK_CLAMP((float)NK_SINT_MIN, values[value_index], (float)NK_SINT_MAX); + NK_MEMCPY(attribute, &value, sizeof(value)); + attribute = (void*)((char*)attribute + sizeof(nk_int)); + } break; + case NK_FORMAT_UCHAR: { + unsigned char value = (unsigned char)NK_CLAMP((float)NK_UCHAR_MIN, values[value_index], (float)NK_UCHAR_MAX); + NK_MEMCPY(attribute, &value, sizeof(value)); + attribute = (void*)((char*)attribute + sizeof(unsigned char)); + } break; + case NK_FORMAT_USHORT: { + nk_ushort value = (nk_ushort)NK_CLAMP((float)NK_USHORT_MIN, values[value_index], (float)NK_USHORT_MAX); + NK_MEMCPY(attribute, &value, sizeof(value)); + attribute = (void*)((char*)attribute + sizeof(value)); + } break; + case NK_FORMAT_UINT: { + nk_uint value = (nk_uint)NK_CLAMP((float)NK_UINT_MIN, values[value_index], (float)NK_UINT_MAX); + NK_MEMCPY(attribute, &value, sizeof(value)); + attribute = (void*)((char*)attribute + sizeof(nk_uint)); + } break; + case NK_FORMAT_FLOAT: + NK_MEMCPY(attribute, &values[value_index], sizeof(values[value_index])); + attribute = (void*)((char*)attribute + sizeof(float)); + break; + case NK_FORMAT_DOUBLE: { + double value = (double)values[value_index]; + NK_MEMCPY(attribute, &value, sizeof(value)); + attribute = (void*)((char*)attribute + sizeof(double)); + } break; + } + } +} +NK_INTERN void* +nk_draw_vertex(void *dst, const struct nk_convert_config *config, + struct nk_vec2 pos, struct nk_vec2 uv, struct nk_colorf color) +{ + void *result = (void*)((char*)dst + config->vertex_size); + const struct nk_draw_vertex_layout_element *elem_iter = config->vertex_layout; + while (!nk_draw_vertex_layout_element_is_end_of_layout(elem_iter)) { + void *address = (void*)((char*)dst + elem_iter->offset); + switch (elem_iter->attribute) { + case NK_VERTEX_ATTRIBUTE_COUNT: + default: NK_ASSERT(0 && "wrong element attribute"); break; + case NK_VERTEX_POSITION: nk_draw_vertex_element(address, &pos.x, 2, elem_iter->format); break; + case NK_VERTEX_TEXCOORD: nk_draw_vertex_element(address, &uv.x, 2, elem_iter->format); break; + case NK_VERTEX_COLOR: nk_draw_vertex_color(address, &color.r, elem_iter->format); break; + } + elem_iter++; + } + return result; +} +NK_API void +nk_draw_list_stroke_poly_line(struct nk_draw_list *list, const struct nk_vec2 *points, + const unsigned int points_count, struct nk_color color, enum nk_draw_list_stroke closed, + float thickness, enum nk_anti_aliasing aliasing) +{ + nk_size count; + int thick_line; + struct nk_colorf col; + struct nk_colorf col_trans; + NK_ASSERT(list); + if (!list || points_count < 2) return; + + color.a = (nk_byte)((float)color.a * list->config.global_alpha); + count = points_count; + if (!closed) count = points_count-1; + thick_line = thickness > 1.0f; + +#ifdef NK_INCLUDE_COMMAND_USERDATA + nk_draw_list_push_userdata(list, list->userdata); +#endif + + color.a = (nk_byte)((float)color.a * list->config.global_alpha); + nk_color_fv(&col.r, color); + col_trans = col; + col_trans.a = 0; + + if (aliasing == NK_ANTI_ALIASING_ON) { + /* ANTI-ALIASED STROKE */ + const float AA_SIZE = 1.0f; + NK_STORAGE const nk_size pnt_align = NK_ALIGNOF(struct nk_vec2); + NK_STORAGE const nk_size pnt_size = sizeof(struct nk_vec2); + + /* allocate vertices and elements */ + nk_size i1 = 0; + nk_size vertex_offset; + nk_size index = list->vertex_count; + + const nk_size idx_count = (thick_line) ? (count * 18) : (count * 12); + const nk_size vtx_count = (thick_line) ? (points_count * 4): (points_count *3); + + void *vtx = nk_draw_list_alloc_vertices(list, vtx_count); + nk_draw_index *ids = nk_draw_list_alloc_elements(list, idx_count); + + nk_size size; + struct nk_vec2 *normals, *temp; + if (!vtx || !ids) return; + + /* temporary allocate normals + points */ + vertex_offset = (nk_size)((nk_byte*)vtx - (nk_byte*)list->vertices->memory.ptr); + nk_buffer_mark(list->vertices, NK_BUFFER_FRONT); + size = pnt_size * ((thick_line) ? 5 : 3) * points_count; + normals = (struct nk_vec2*) nk_buffer_alloc(list->vertices, NK_BUFFER_FRONT, size, pnt_align); + if (!normals) return; + temp = normals + points_count; + + /* make sure vertex pointer is still correct */ + vtx = (void*)((nk_byte*)list->vertices->memory.ptr + vertex_offset); + + /* calculate normals */ + for (i1 = 0; i1 < count; ++i1) { + const nk_size i2 = ((i1 + 1) == points_count) ? 0 : (i1 + 1); + struct nk_vec2 diff = nk_vec2_sub(points[i2], points[i1]); + float len; + + /* vec2 inverted length */ + len = nk_vec2_len_sqr(diff); + if (len != 0.0f) + len = NK_INV_SQRT(len); + else len = 1.0f; + + diff = nk_vec2_muls(diff, len); + normals[i1].x = diff.y; + normals[i1].y = -diff.x; + } + + if (!closed) + normals[points_count-1] = normals[points_count-2]; + + if (!thick_line) { + nk_size idx1, i; + if (!closed) { + struct nk_vec2 d; + temp[0] = nk_vec2_add(points[0], nk_vec2_muls(normals[0], AA_SIZE)); + temp[1] = nk_vec2_sub(points[0], nk_vec2_muls(normals[0], AA_SIZE)); + d = nk_vec2_muls(normals[points_count-1], AA_SIZE); + temp[(points_count-1) * 2 + 0] = nk_vec2_add(points[points_count-1], d); + temp[(points_count-1) * 2 + 1] = nk_vec2_sub(points[points_count-1], d); + } + + /* fill elements */ + idx1 = index; + for (i1 = 0; i1 < count; i1++) { + struct nk_vec2 dm; + float dmr2; + nk_size i2 = ((i1 + 1) == points_count) ? 0 : (i1 + 1); + nk_size idx2 = ((i1+1) == points_count) ? index: (idx1 + 3); + + /* average normals */ + dm = nk_vec2_muls(nk_vec2_add(normals[i1], normals[i2]), 0.5f); + dmr2 = dm.x * dm.x + dm.y* dm.y; + if (dmr2 > 0.000001f) { + float scale = 1.0f/dmr2; + scale = NK_MIN(100.0f, scale); + dm = nk_vec2_muls(dm, scale); + } + + dm = nk_vec2_muls(dm, AA_SIZE); + temp[i2*2+0] = nk_vec2_add(points[i2], dm); + temp[i2*2+1] = nk_vec2_sub(points[i2], dm); + + ids[0] = (nk_draw_index)(idx2 + 0); ids[1] = (nk_draw_index)(idx1+0); + ids[2] = (nk_draw_index)(idx1 + 2); ids[3] = (nk_draw_index)(idx1+2); + ids[4] = (nk_draw_index)(idx2 + 2); ids[5] = (nk_draw_index)(idx2+0); + ids[6] = (nk_draw_index)(idx2 + 1); ids[7] = (nk_draw_index)(idx1+1); + ids[8] = (nk_draw_index)(idx1 + 0); ids[9] = (nk_draw_index)(idx1+0); + ids[10]= (nk_draw_index)(idx2 + 0); ids[11]= (nk_draw_index)(idx2+1); + ids += 12; + idx1 = idx2; + } + + /* fill vertices */ + for (i = 0; i < points_count; ++i) { + const struct nk_vec2 uv = list->config.tex_null.uv; + vtx = nk_draw_vertex(vtx, &list->config, points[i], uv, col); + vtx = nk_draw_vertex(vtx, &list->config, temp[i*2+0], uv, col_trans); + vtx = nk_draw_vertex(vtx, &list->config, temp[i*2+1], uv, col_trans); + } + } else { + nk_size idx1, i; + const float half_inner_thickness = (thickness - AA_SIZE) * 0.5f; + if (!closed) { + struct nk_vec2 d1 = nk_vec2_muls(normals[0], half_inner_thickness + AA_SIZE); + struct nk_vec2 d2 = nk_vec2_muls(normals[0], half_inner_thickness); + + temp[0] = nk_vec2_add(points[0], d1); + temp[1] = nk_vec2_add(points[0], d2); + temp[2] = nk_vec2_sub(points[0], d2); + temp[3] = nk_vec2_sub(points[0], d1); + + d1 = nk_vec2_muls(normals[points_count-1], half_inner_thickness + AA_SIZE); + d2 = nk_vec2_muls(normals[points_count-1], half_inner_thickness); + + temp[(points_count-1)*4+0] = nk_vec2_add(points[points_count-1], d1); + temp[(points_count-1)*4+1] = nk_vec2_add(points[points_count-1], d2); + temp[(points_count-1)*4+2] = nk_vec2_sub(points[points_count-1], d2); + temp[(points_count-1)*4+3] = nk_vec2_sub(points[points_count-1], d1); + } + + /* add all elements */ + idx1 = index; + for (i1 = 0; i1 < count; ++i1) { + struct nk_vec2 dm_out, dm_in; + const nk_size i2 = ((i1+1) == points_count) ? 0: (i1 + 1); + nk_size idx2 = ((i1+1) == points_count) ? index: (idx1 + 4); + + /* average normals */ + struct nk_vec2 dm = nk_vec2_muls(nk_vec2_add(normals[i1], normals[i2]), 0.5f); + float dmr2 = dm.x * dm.x + dm.y* dm.y; + if (dmr2 > 0.000001f) { + float scale = 1.0f/dmr2; + scale = NK_MIN(100.0f, scale); + dm = nk_vec2_muls(dm, scale); + } + + dm_out = nk_vec2_muls(dm, ((half_inner_thickness) + AA_SIZE)); + dm_in = nk_vec2_muls(dm, half_inner_thickness); + temp[i2*4+0] = nk_vec2_add(points[i2], dm_out); + temp[i2*4+1] = nk_vec2_add(points[i2], dm_in); + temp[i2*4+2] = nk_vec2_sub(points[i2], dm_in); + temp[i2*4+3] = nk_vec2_sub(points[i2], dm_out); + + /* add indexes */ + ids[0] = (nk_draw_index)(idx2 + 1); ids[1] = (nk_draw_index)(idx1+1); + ids[2] = (nk_draw_index)(idx1 + 2); ids[3] = (nk_draw_index)(idx1+2); + ids[4] = (nk_draw_index)(idx2 + 2); ids[5] = (nk_draw_index)(idx2+1); + ids[6] = (nk_draw_index)(idx2 + 1); ids[7] = (nk_draw_index)(idx1+1); + ids[8] = (nk_draw_index)(idx1 + 0); ids[9] = (nk_draw_index)(idx1+0); + ids[10]= (nk_draw_index)(idx2 + 0); ids[11] = (nk_draw_index)(idx2+1); + ids[12]= (nk_draw_index)(idx2 + 2); ids[13] = (nk_draw_index)(idx1+2); + ids[14]= (nk_draw_index)(idx1 + 3); ids[15] = (nk_draw_index)(idx1+3); + ids[16]= (nk_draw_index)(idx2 + 3); ids[17] = (nk_draw_index)(idx2+2); + ids += 18; + idx1 = idx2; + } + + /* add vertices */ + for (i = 0; i < points_count; ++i) { + const struct nk_vec2 uv = list->config.tex_null.uv; + vtx = nk_draw_vertex(vtx, &list->config, temp[i*4+0], uv, col_trans); + vtx = nk_draw_vertex(vtx, &list->config, temp[i*4+1], uv, col); + vtx = nk_draw_vertex(vtx, &list->config, temp[i*4+2], uv, col); + vtx = nk_draw_vertex(vtx, &list->config, temp[i*4+3], uv, col_trans); + } + } + /* free temporary normals + points */ + nk_buffer_reset(list->vertices, NK_BUFFER_FRONT); + } else { + /* NON ANTI-ALIASED STROKE */ + nk_size i1 = 0; + nk_size idx = list->vertex_count; + const nk_size idx_count = count * 6; + const nk_size vtx_count = count * 4; + void *vtx = nk_draw_list_alloc_vertices(list, vtx_count); + nk_draw_index *ids = nk_draw_list_alloc_elements(list, idx_count); + if (!vtx || !ids) return; + + for (i1 = 0; i1 < count; ++i1) { + float dx, dy; + const struct nk_vec2 uv = list->config.tex_null.uv; + const nk_size i2 = ((i1+1) == points_count) ? 0 : i1 + 1; + const struct nk_vec2 p1 = points[i1]; + const struct nk_vec2 p2 = points[i2]; + struct nk_vec2 diff = nk_vec2_sub(p2, p1); + float len; + + /* vec2 inverted length */ + len = nk_vec2_len_sqr(diff); + if (len != 0.0f) + len = NK_INV_SQRT(len); + else len = 1.0f; + diff = nk_vec2_muls(diff, len); + + /* add vertices */ + dx = diff.x * (thickness * 0.5f); + dy = diff.y * (thickness * 0.5f); + + vtx = nk_draw_vertex(vtx, &list->config, nk_vec2(p1.x + dy, p1.y - dx), uv, col); + vtx = nk_draw_vertex(vtx, &list->config, nk_vec2(p2.x + dy, p2.y - dx), uv, col); + vtx = nk_draw_vertex(vtx, &list->config, nk_vec2(p2.x - dy, p2.y + dx), uv, col); + vtx = nk_draw_vertex(vtx, &list->config, nk_vec2(p1.x - dy, p1.y + dx), uv, col); + + ids[0] = (nk_draw_index)(idx+0); ids[1] = (nk_draw_index)(idx+1); + ids[2] = (nk_draw_index)(idx+2); ids[3] = (nk_draw_index)(idx+0); + ids[4] = (nk_draw_index)(idx+2); ids[5] = (nk_draw_index)(idx+3); + + ids += 6; + idx += 4; + } + } +} +NK_API void +nk_draw_list_fill_poly_convex(struct nk_draw_list *list, + const struct nk_vec2 *points, const unsigned int points_count, + struct nk_color color, enum nk_anti_aliasing aliasing) +{ + struct nk_colorf col; + struct nk_colorf col_trans; + + NK_STORAGE const nk_size pnt_align = NK_ALIGNOF(struct nk_vec2); + NK_STORAGE const nk_size pnt_size = sizeof(struct nk_vec2); + NK_ASSERT(list); + if (!list || points_count < 3) return; + +#ifdef NK_INCLUDE_COMMAND_USERDATA + nk_draw_list_push_userdata(list, list->userdata); +#endif + + color.a = (nk_byte)((float)color.a * list->config.global_alpha); + nk_color_fv(&col.r, color); + col_trans = col; + col_trans.a = 0; + + if (aliasing == NK_ANTI_ALIASING_ON) { + nk_size i = 0; + nk_size i0 = 0; + nk_size i1 = 0; + + const float AA_SIZE = 1.0f; + nk_size vertex_offset = 0; + nk_size index = list->vertex_count; + + const nk_size idx_count = (points_count-2)*3 + points_count*6; + const nk_size vtx_count = (points_count*2); + + void *vtx = nk_draw_list_alloc_vertices(list, vtx_count); + nk_draw_index *ids = nk_draw_list_alloc_elements(list, idx_count); + + nk_size size = 0; + struct nk_vec2 *normals = 0; + unsigned int vtx_inner_idx = (unsigned int)(index + 0); + unsigned int vtx_outer_idx = (unsigned int)(index + 1); + if (!vtx || !ids) return; + + /* temporary allocate normals */ + vertex_offset = (nk_size)((nk_byte*)vtx - (nk_byte*)list->vertices->memory.ptr); + nk_buffer_mark(list->vertices, NK_BUFFER_FRONT); + size = pnt_size * points_count; + normals = (struct nk_vec2*) nk_buffer_alloc(list->vertices, NK_BUFFER_FRONT, size, pnt_align); + if (!normals) return; + vtx = (void*)((nk_byte*)list->vertices->memory.ptr + vertex_offset); + + /* add elements */ + for (i = 2; i < points_count; i++) { + ids[0] = (nk_draw_index)(vtx_inner_idx); + ids[1] = (nk_draw_index)(vtx_inner_idx + ((i-1) << 1)); + ids[2] = (nk_draw_index)(vtx_inner_idx + (i << 1)); + ids += 3; + } + + /* compute normals */ + for (i0 = points_count-1, i1 = 0; i1 < points_count; i0 = i1++) { + struct nk_vec2 p0 = points[i0]; + struct nk_vec2 p1 = points[i1]; + struct nk_vec2 diff = nk_vec2_sub(p1, p0); + + /* vec2 inverted length */ + float len = nk_vec2_len_sqr(diff); + if (len != 0.0f) + len = NK_INV_SQRT(len); + else len = 1.0f; + diff = nk_vec2_muls(diff, len); + + normals[i0].x = diff.y; + normals[i0].y = -diff.x; + } + + /* add vertices + indexes */ + for (i0 = points_count-1, i1 = 0; i1 < points_count; i0 = i1++) { + const struct nk_vec2 uv = list->config.tex_null.uv; + struct nk_vec2 n0 = normals[i0]; + struct nk_vec2 n1 = normals[i1]; + struct nk_vec2 dm = nk_vec2_muls(nk_vec2_add(n0, n1), 0.5f); + float dmr2 = dm.x*dm.x + dm.y*dm.y; + if (dmr2 > 0.000001f) { + float scale = 1.0f / dmr2; + scale = NK_MIN(scale, 100.0f); + dm = nk_vec2_muls(dm, scale); + } + dm = nk_vec2_muls(dm, AA_SIZE * 0.5f); + + /* add vertices */ + vtx = nk_draw_vertex(vtx, &list->config, nk_vec2_sub(points[i1], dm), uv, col); + vtx = nk_draw_vertex(vtx, &list->config, nk_vec2_add(points[i1], dm), uv, col_trans); + + /* add indexes */ + ids[0] = (nk_draw_index)(vtx_inner_idx+(i1<<1)); + ids[1] = (nk_draw_index)(vtx_inner_idx+(i0<<1)); + ids[2] = (nk_draw_index)(vtx_outer_idx+(i0<<1)); + ids[3] = (nk_draw_index)(vtx_outer_idx+(i0<<1)); + ids[4] = (nk_draw_index)(vtx_outer_idx+(i1<<1)); + ids[5] = (nk_draw_index)(vtx_inner_idx+(i1<<1)); + ids += 6; + } + /* free temporary normals + points */ + nk_buffer_reset(list->vertices, NK_BUFFER_FRONT); + } else { + nk_size i = 0; + nk_size index = list->vertex_count; + const nk_size idx_count = (points_count-2)*3; + const nk_size vtx_count = points_count; + void *vtx = nk_draw_list_alloc_vertices(list, vtx_count); + nk_draw_index *ids = nk_draw_list_alloc_elements(list, idx_count); + + if (!vtx || !ids) return; + for (i = 0; i < vtx_count; ++i) + vtx = nk_draw_vertex(vtx, &list->config, points[i], list->config.tex_null.uv, col); + for (i = 2; i < points_count; ++i) { + ids[0] = (nk_draw_index)index; + ids[1] = (nk_draw_index)(index+ i - 1); + ids[2] = (nk_draw_index)(index+i); + ids += 3; + } + } +} +NK_API void +nk_draw_list_path_clear(struct nk_draw_list *list) +{ + NK_ASSERT(list); + if (!list) return; + nk_buffer_reset(list->buffer, NK_BUFFER_FRONT); + list->path_count = 0; + list->path_offset = 0; +} +NK_API void +nk_draw_list_path_line_to(struct nk_draw_list *list, struct nk_vec2 pos) +{ + struct nk_vec2 *points = 0; + struct nk_draw_command *cmd = 0; + NK_ASSERT(list); + if (!list) return; + if (!list->cmd_count) + nk_draw_list_add_clip(list, nk_null_rect); + + cmd = nk_draw_list_command_last(list); + if (cmd && cmd->texture.ptr != list->config.tex_null.texture.ptr) + nk_draw_list_push_image(list, list->config.tex_null.texture); + + points = nk_draw_list_alloc_path(list, 1); + if (!points) return; + points[0] = pos; +} +NK_API void +nk_draw_list_path_arc_to_fast(struct nk_draw_list *list, struct nk_vec2 center, + float radius, int a_min, int a_max) +{ + int a = 0; + NK_ASSERT(list); + if (!list) return; + if (a_min <= a_max) { + for (a = a_min; a <= a_max; a++) { + const struct nk_vec2 c = list->circle_vtx[(nk_size)a % NK_LEN(list->circle_vtx)]; + const float x = center.x + c.x * radius; + const float y = center.y + c.y * radius; + nk_draw_list_path_line_to(list, nk_vec2(x, y)); + } + } +} +NK_API void +nk_draw_list_path_arc_to(struct nk_draw_list *list, struct nk_vec2 center, + float radius, float a_min, float a_max, unsigned int segments) +{ + unsigned int i = 0; + NK_ASSERT(list); + if (!list) return; + if (radius == 0.0f) return; + + /* This algorithm for arc drawing relies on these two trigonometric identities[1]: + sin(a + b) = sin(a) * cos(b) + cos(a) * sin(b) + cos(a + b) = cos(a) * cos(b) - sin(a) * sin(b) + + Two coordinates (x, y) of a point on a circle centered on + the origin can be written in polar form as: + x = r * cos(a) + y = r * sin(a) + where r is the radius of the circle, + a is the angle between (x, y) and the origin. + + This allows us to rotate the coordinates around the + origin by an angle b using the following transformation: + x' = r * cos(a + b) = x * cos(b) - y * sin(b) + y' = r * sin(a + b) = y * cos(b) + x * sin(b) + + [1] https://en.wikipedia.org/wiki/List_of_trigonometric_identities#Angle_sum_and_difference_identities + */ + {const float d_angle = (a_max - a_min) / (float)segments; + const float sin_d = (float)NK_SIN(d_angle); + const float cos_d = (float)NK_COS(d_angle); + + float cx = (float)NK_COS(a_min) * radius; + float cy = (float)NK_SIN(a_min) * radius; + for(i = 0; i <= segments; ++i) { + float new_cx, new_cy; + const float x = center.x + cx; + const float y = center.y + cy; + nk_draw_list_path_line_to(list, nk_vec2(x, y)); + + new_cx = cx * cos_d - cy * sin_d; + new_cy = cy * cos_d + cx * sin_d; + cx = new_cx; + cy = new_cy; + }} +} +NK_API void +nk_draw_list_path_rect_to(struct nk_draw_list *list, struct nk_vec2 a, + struct nk_vec2 b, float rounding) +{ + float r; + NK_ASSERT(list); + if (!list) return; + r = rounding; + r = NK_MIN(r, ((b.x-a.x) < 0) ? -(b.x-a.x): (b.x-a.x)); + r = NK_MIN(r, ((b.y-a.y) < 0) ? -(b.y-a.y): (b.y-a.y)); + + if (r == 0.0f) { + nk_draw_list_path_line_to(list, a); + nk_draw_list_path_line_to(list, nk_vec2(b.x,a.y)); + nk_draw_list_path_line_to(list, b); + nk_draw_list_path_line_to(list, nk_vec2(a.x,b.y)); + } else { + nk_draw_list_path_arc_to_fast(list, nk_vec2(a.x + r, a.y + r), r, 6, 9); + nk_draw_list_path_arc_to_fast(list, nk_vec2(b.x - r, a.y + r), r, 9, 12); + nk_draw_list_path_arc_to_fast(list, nk_vec2(b.x - r, b.y - r), r, 0, 3); + nk_draw_list_path_arc_to_fast(list, nk_vec2(a.x + r, b.y - r), r, 3, 6); + } +} +NK_API void +nk_draw_list_path_curve_to(struct nk_draw_list *list, struct nk_vec2 p2, + struct nk_vec2 p3, struct nk_vec2 p4, unsigned int num_segments) +{ + float t_step; + unsigned int i_step; + struct nk_vec2 p1; + + NK_ASSERT(list); + NK_ASSERT(list->path_count); + if (!list || !list->path_count) return; + num_segments = NK_MAX(num_segments, 1); + + p1 = nk_draw_list_path_last(list); + t_step = 1.0f/(float)num_segments; + for (i_step = 1; i_step <= num_segments; ++i_step) { + float t = t_step * (float)i_step; + float u = 1.0f - t; + float w1 = u*u*u; + float w2 = 3*u*u*t; + float w3 = 3*u*t*t; + float w4 = t * t *t; + float x = w1 * p1.x + w2 * p2.x + w3 * p3.x + w4 * p4.x; + float y = w1 * p1.y + w2 * p2.y + w3 * p3.y + w4 * p4.y; + nk_draw_list_path_line_to(list, nk_vec2(x,y)); + } +} +NK_API void +nk_draw_list_path_fill(struct nk_draw_list *list, struct nk_color color) +{ + struct nk_vec2 *points; + NK_ASSERT(list); + if (!list) return; + points = (struct nk_vec2*)nk_buffer_memory(list->buffer); + nk_draw_list_fill_poly_convex(list, points, list->path_count, color, list->config.shape_AA); + nk_draw_list_path_clear(list); +} +NK_API void +nk_draw_list_path_stroke(struct nk_draw_list *list, struct nk_color color, + enum nk_draw_list_stroke closed, float thickness) +{ + struct nk_vec2 *points; + NK_ASSERT(list); + if (!list) return; + points = (struct nk_vec2*)nk_buffer_memory(list->buffer); + nk_draw_list_stroke_poly_line(list, points, list->path_count, color, + closed, thickness, list->config.line_AA); + nk_draw_list_path_clear(list); +} +NK_API void +nk_draw_list_stroke_line(struct nk_draw_list *list, struct nk_vec2 a, + struct nk_vec2 b, struct nk_color col, float thickness) +{ + NK_ASSERT(list); + if (!list || !col.a) return; + if (list->line_AA == NK_ANTI_ALIASING_ON) { + nk_draw_list_path_line_to(list, a); + nk_draw_list_path_line_to(list, b); + } else { + nk_draw_list_path_line_to(list, nk_vec2_sub(a,nk_vec2(0.5f,0.5f))); + nk_draw_list_path_line_to(list, nk_vec2_sub(b,nk_vec2(0.5f,0.5f))); + } + nk_draw_list_path_stroke(list, col, NK_STROKE_OPEN, thickness); +} +NK_API void +nk_draw_list_fill_rect(struct nk_draw_list *list, struct nk_rect rect, + struct nk_color col, float rounding) +{ + NK_ASSERT(list); + if (!list || !col.a) return; + + if (list->line_AA == NK_ANTI_ALIASING_ON) { + nk_draw_list_path_rect_to(list, nk_vec2(rect.x, rect.y), + nk_vec2(rect.x + rect.w, rect.y + rect.h), rounding); + } else { + nk_draw_list_path_rect_to(list, nk_vec2(rect.x-0.5f, rect.y-0.5f), + nk_vec2(rect.x + rect.w, rect.y + rect.h), rounding); + } nk_draw_list_path_fill(list, col); +} +NK_API void +nk_draw_list_stroke_rect(struct nk_draw_list *list, struct nk_rect rect, + struct nk_color col, float rounding, float thickness) +{ + NK_ASSERT(list); + if (!list || !col.a) return; + if (list->line_AA == NK_ANTI_ALIASING_ON) { + nk_draw_list_path_rect_to(list, nk_vec2(rect.x, rect.y), + nk_vec2(rect.x + rect.w, rect.y + rect.h), rounding); + } else { + nk_draw_list_path_rect_to(list, nk_vec2(rect.x-0.5f, rect.y-0.5f), + nk_vec2(rect.x + rect.w, rect.y + rect.h), rounding); + } nk_draw_list_path_stroke(list, col, NK_STROKE_CLOSED, thickness); +} +NK_API void +nk_draw_list_fill_rect_multi_color(struct nk_draw_list *list, struct nk_rect rect, + struct nk_color left, struct nk_color top, struct nk_color right, + struct nk_color bottom) +{ + void *vtx; + struct nk_colorf col_left, col_top; + struct nk_colorf col_right, col_bottom; + nk_draw_index *idx; + nk_draw_index index; + + nk_color_fv(&col_left.r, left); + nk_color_fv(&col_right.r, right); + nk_color_fv(&col_top.r, top); + nk_color_fv(&col_bottom.r, bottom); + + NK_ASSERT(list); + if (!list) return; + + nk_draw_list_push_image(list, list->config.tex_null.texture); + index = (nk_draw_index)list->vertex_count; + vtx = nk_draw_list_alloc_vertices(list, 4); + idx = nk_draw_list_alloc_elements(list, 6); + if (!vtx || !idx) return; + + idx[0] = (nk_draw_index)(index+0); idx[1] = (nk_draw_index)(index+1); + idx[2] = (nk_draw_index)(index+2); idx[3] = (nk_draw_index)(index+0); + idx[4] = (nk_draw_index)(index+2); idx[5] = (nk_draw_index)(index+3); + + vtx = nk_draw_vertex(vtx, &list->config, nk_vec2(rect.x, rect.y), list->config.tex_null.uv, col_left); + vtx = nk_draw_vertex(vtx, &list->config, nk_vec2(rect.x + rect.w, rect.y), list->config.tex_null.uv, col_top); + vtx = nk_draw_vertex(vtx, &list->config, nk_vec2(rect.x + rect.w, rect.y + rect.h), list->config.tex_null.uv, col_right); + vtx = nk_draw_vertex(vtx, &list->config, nk_vec2(rect.x, rect.y + rect.h), list->config.tex_null.uv, col_bottom); +} +NK_API void +nk_draw_list_fill_triangle(struct nk_draw_list *list, struct nk_vec2 a, + struct nk_vec2 b, struct nk_vec2 c, struct nk_color col) +{ + NK_ASSERT(list); + if (!list || !col.a) return; + nk_draw_list_path_line_to(list, a); + nk_draw_list_path_line_to(list, b); + nk_draw_list_path_line_to(list, c); + nk_draw_list_path_fill(list, col); +} +NK_API void +nk_draw_list_stroke_triangle(struct nk_draw_list *list, struct nk_vec2 a, + struct nk_vec2 b, struct nk_vec2 c, struct nk_color col, float thickness) +{ + NK_ASSERT(list); + if (!list || !col.a) return; + nk_draw_list_path_line_to(list, a); + nk_draw_list_path_line_to(list, b); + nk_draw_list_path_line_to(list, c); + nk_draw_list_path_stroke(list, col, NK_STROKE_CLOSED, thickness); +} +NK_API void +nk_draw_list_fill_circle(struct nk_draw_list *list, struct nk_vec2 center, + float radius, struct nk_color col, unsigned int segs) +{ + float a_max; + NK_ASSERT(list); + if (!list || !col.a) return; + a_max = NK_PI * 2.0f * ((float)segs - 1.0f) / (float)segs; + nk_draw_list_path_arc_to(list, center, radius, 0.0f, a_max, segs); + nk_draw_list_path_fill(list, col); +} +NK_API void +nk_draw_list_stroke_circle(struct nk_draw_list *list, struct nk_vec2 center, + float radius, struct nk_color col, unsigned int segs, float thickness) +{ + float a_max; + NK_ASSERT(list); + if (!list || !col.a) return; + a_max = NK_PI * 2.0f * ((float)segs - 1.0f) / (float)segs; + nk_draw_list_path_arc_to(list, center, radius, 0.0f, a_max, segs); + nk_draw_list_path_stroke(list, col, NK_STROKE_CLOSED, thickness); +} +NK_API void +nk_draw_list_stroke_curve(struct nk_draw_list *list, struct nk_vec2 p0, + struct nk_vec2 cp0, struct nk_vec2 cp1, struct nk_vec2 p1, + struct nk_color col, unsigned int segments, float thickness) +{ + NK_ASSERT(list); + if (!list || !col.a) return; + nk_draw_list_path_line_to(list, p0); + nk_draw_list_path_curve_to(list, cp0, cp1, p1, segments); + nk_draw_list_path_stroke(list, col, NK_STROKE_OPEN, thickness); +} +NK_INTERN void +nk_draw_list_push_rect_uv(struct nk_draw_list *list, struct nk_vec2 a, + struct nk_vec2 c, struct nk_vec2 uva, struct nk_vec2 uvc, + struct nk_color color) +{ + void *vtx; + struct nk_vec2 uvb; + struct nk_vec2 uvd; + struct nk_vec2 b; + struct nk_vec2 d; + + struct nk_colorf col; + nk_draw_index *idx; + nk_draw_index index; + NK_ASSERT(list); + if (!list) return; + + nk_color_fv(&col.r, color); + uvb = nk_vec2(uvc.x, uva.y); + uvd = nk_vec2(uva.x, uvc.y); + b = nk_vec2(c.x, a.y); + d = nk_vec2(a.x, c.y); + + index = (nk_draw_index)list->vertex_count; + vtx = nk_draw_list_alloc_vertices(list, 4); + idx = nk_draw_list_alloc_elements(list, 6); + if (!vtx || !idx) return; + + idx[0] = (nk_draw_index)(index+0); idx[1] = (nk_draw_index)(index+1); + idx[2] = (nk_draw_index)(index+2); idx[3] = (nk_draw_index)(index+0); + idx[4] = (nk_draw_index)(index+2); idx[5] = (nk_draw_index)(index+3); + + vtx = nk_draw_vertex(vtx, &list->config, a, uva, col); + vtx = nk_draw_vertex(vtx, &list->config, b, uvb, col); + vtx = nk_draw_vertex(vtx, &list->config, c, uvc, col); + vtx = nk_draw_vertex(vtx, &list->config, d, uvd, col); +} +NK_API void +nk_draw_list_add_image(struct nk_draw_list *list, struct nk_image texture, + struct nk_rect rect, struct nk_color color) +{ + NK_ASSERT(list); + if (!list) return; + /* push new command with given texture */ + nk_draw_list_push_image(list, texture.handle); + if (nk_image_is_subimage(&texture)) { + /* add region inside of the texture */ + struct nk_vec2 uv[2]; + uv[0].x = (float)texture.region[0]/(float)texture.w; + uv[0].y = (float)texture.region[1]/(float)texture.h; + uv[1].x = (float)(texture.region[0] + texture.region[2])/(float)texture.w; + uv[1].y = (float)(texture.region[1] + texture.region[3])/(float)texture.h; + nk_draw_list_push_rect_uv(list, nk_vec2(rect.x, rect.y), + nk_vec2(rect.x + rect.w, rect.y + rect.h), uv[0], uv[1], color); + } else nk_draw_list_push_rect_uv(list, nk_vec2(rect.x, rect.y), + nk_vec2(rect.x + rect.w, rect.y + rect.h), + nk_vec2(0.0f, 0.0f), nk_vec2(1.0f, 1.0f),color); +} +NK_API void +nk_draw_list_add_text(struct nk_draw_list *list, const struct nk_user_font *font, + struct nk_rect rect, const char *text, int len, float font_height, + struct nk_color fg) +{ + float x = 0; + int text_len = 0; + nk_rune unicode = 0; + nk_rune next = 0; + int glyph_len = 0; + int next_glyph_len = 0; + struct nk_user_font_glyph g; + + NK_ASSERT(list); + if (!list || !len || !text) return; + if (!NK_INTERSECT(rect.x, rect.y, rect.w, rect.h, + list->clip_rect.x, list->clip_rect.y, list->clip_rect.w, list->clip_rect.h)) return; + + nk_draw_list_push_image(list, font->texture); + x = rect.x; + glyph_len = nk_utf_decode(text, &unicode, len); + if (!glyph_len) return; + + /* draw every glyph image */ + fg.a = (nk_byte)((float)fg.a * list->config.global_alpha); + while (text_len < len && glyph_len) { + float gx, gy, gh, gw; + float char_width = 0; + if (unicode == NK_UTF_INVALID) break; + + /* query currently drawn glyph information */ + next_glyph_len = nk_utf_decode(text + text_len + glyph_len, &next, (int)len - text_len); + font->query(font->userdata, font_height, &g, unicode, + (next == NK_UTF_INVALID) ? '\0' : next); + + /* calculate and draw glyph drawing rectangle and image */ + gx = x + g.offset.x; + gy = rect.y + g.offset.y; + gw = g.width; gh = g.height; + char_width = g.xadvance; + nk_draw_list_push_rect_uv(list, nk_vec2(gx,gy), nk_vec2(gx + gw, gy+ gh), + g.uv[0], g.uv[1], fg); + + /* offset next glyph */ + text_len += glyph_len; + x += char_width; + glyph_len = next_glyph_len; + unicode = next; + } +} +NK_API nk_flags +nk_convert(struct nk_context *ctx, struct nk_buffer *cmds, + struct nk_buffer *vertices, struct nk_buffer *elements, + const struct nk_convert_config *config) +{ + nk_flags res = NK_CONVERT_SUCCESS; + const struct nk_command *cmd; + NK_ASSERT(ctx); + NK_ASSERT(cmds); + NK_ASSERT(vertices); + NK_ASSERT(elements); + NK_ASSERT(config); + NK_ASSERT(config->vertex_layout); + NK_ASSERT(config->vertex_size); + if (!ctx || !cmds || !vertices || !elements || !config || !config->vertex_layout) + return NK_CONVERT_INVALID_PARAM; + + nk_draw_list_setup(&ctx->draw_list, config, cmds, vertices, elements, + config->line_AA, config->shape_AA); + nk_foreach(cmd, ctx) + { +#ifdef NK_INCLUDE_COMMAND_USERDATA + ctx->draw_list.userdata = cmd->userdata; +#endif + switch (cmd->type) { + case NK_COMMAND_NOP: break; + case NK_COMMAND_SCISSOR: { + const struct nk_command_scissor *s = (const struct nk_command_scissor*)cmd; + nk_draw_list_add_clip(&ctx->draw_list, nk_rect(s->x, s->y, s->w, s->h)); + } break; + case NK_COMMAND_LINE: { + const struct nk_command_line *l = (const struct nk_command_line*)cmd; + nk_draw_list_stroke_line(&ctx->draw_list, nk_vec2(l->begin.x, l->begin.y), + nk_vec2(l->end.x, l->end.y), l->color, l->line_thickness); + } break; + case NK_COMMAND_CURVE: { + const struct nk_command_curve *q = (const struct nk_command_curve*)cmd; + nk_draw_list_stroke_curve(&ctx->draw_list, nk_vec2(q->begin.x, q->begin.y), + nk_vec2(q->ctrl[0].x, q->ctrl[0].y), nk_vec2(q->ctrl[1].x, + q->ctrl[1].y), nk_vec2(q->end.x, q->end.y), q->color, + config->curve_segment_count, q->line_thickness); + } break; + case NK_COMMAND_RECT: { + const struct nk_command_rect *r = (const struct nk_command_rect*)cmd; + nk_draw_list_stroke_rect(&ctx->draw_list, nk_rect(r->x, r->y, r->w, r->h), + r->color, (float)r->rounding, r->line_thickness); + } break; + case NK_COMMAND_RECT_FILLED: { + const struct nk_command_rect_filled *r = (const struct nk_command_rect_filled*)cmd; + nk_draw_list_fill_rect(&ctx->draw_list, nk_rect(r->x, r->y, r->w, r->h), + r->color, (float)r->rounding); + } break; + case NK_COMMAND_RECT_MULTI_COLOR: { + const struct nk_command_rect_multi_color *r = (const struct nk_command_rect_multi_color*)cmd; + nk_draw_list_fill_rect_multi_color(&ctx->draw_list, nk_rect(r->x, r->y, r->w, r->h), + r->left, r->top, r->right, r->bottom); + } break; + case NK_COMMAND_CIRCLE: { + const struct nk_command_circle *c = (const struct nk_command_circle*)cmd; + nk_draw_list_stroke_circle(&ctx->draw_list, nk_vec2((float)c->x + (float)c->w/2, + (float)c->y + (float)c->h/2), (float)c->w/2, c->color, + config->circle_segment_count, c->line_thickness); + } break; + case NK_COMMAND_CIRCLE_FILLED: { + const struct nk_command_circle_filled *c = (const struct nk_command_circle_filled *)cmd; + nk_draw_list_fill_circle(&ctx->draw_list, nk_vec2((float)c->x + (float)c->w/2, + (float)c->y + (float)c->h/2), (float)c->w/2, c->color, + config->circle_segment_count); + } break; + case NK_COMMAND_ARC: { + const struct nk_command_arc *c = (const struct nk_command_arc*)cmd; + nk_draw_list_path_line_to(&ctx->draw_list, nk_vec2(c->cx, c->cy)); + nk_draw_list_path_arc_to(&ctx->draw_list, nk_vec2(c->cx, c->cy), c->r, + c->a[0], c->a[1], config->arc_segment_count); + nk_draw_list_path_stroke(&ctx->draw_list, c->color, NK_STROKE_CLOSED, c->line_thickness); + } break; + case NK_COMMAND_ARC_FILLED: { + const struct nk_command_arc_filled *c = (const struct nk_command_arc_filled*)cmd; + nk_draw_list_path_line_to(&ctx->draw_list, nk_vec2(c->cx, c->cy)); + nk_draw_list_path_arc_to(&ctx->draw_list, nk_vec2(c->cx, c->cy), c->r, + c->a[0], c->a[1], config->arc_segment_count); + nk_draw_list_path_fill(&ctx->draw_list, c->color); + } break; + case NK_COMMAND_TRIANGLE: { + const struct nk_command_triangle *t = (const struct nk_command_triangle*)cmd; + nk_draw_list_stroke_triangle(&ctx->draw_list, nk_vec2(t->a.x, t->a.y), + nk_vec2(t->b.x, t->b.y), nk_vec2(t->c.x, t->c.y), t->color, + t->line_thickness); + } break; + case NK_COMMAND_TRIANGLE_FILLED: { + const struct nk_command_triangle_filled *t = (const struct nk_command_triangle_filled*)cmd; + nk_draw_list_fill_triangle(&ctx->draw_list, nk_vec2(t->a.x, t->a.y), + nk_vec2(t->b.x, t->b.y), nk_vec2(t->c.x, t->c.y), t->color); + } break; + case NK_COMMAND_POLYGON: { + int i; + const struct nk_command_polygon*p = (const struct nk_command_polygon*)cmd; + for (i = 0; i < p->point_count; ++i) { + struct nk_vec2 pnt = nk_vec2((float)p->points[i].x, (float)p->points[i].y); + nk_draw_list_path_line_to(&ctx->draw_list, pnt); + } + nk_draw_list_path_stroke(&ctx->draw_list, p->color, NK_STROKE_CLOSED, p->line_thickness); + } break; + case NK_COMMAND_POLYGON_FILLED: { + int i; + const struct nk_command_polygon_filled *p = (const struct nk_command_polygon_filled*)cmd; + for (i = 0; i < p->point_count; ++i) { + struct nk_vec2 pnt = nk_vec2((float)p->points[i].x, (float)p->points[i].y); + nk_draw_list_path_line_to(&ctx->draw_list, pnt); + } + nk_draw_list_path_fill(&ctx->draw_list, p->color); + } break; + case NK_COMMAND_POLYLINE: { + int i; + const struct nk_command_polyline *p = (const struct nk_command_polyline*)cmd; + for (i = 0; i < p->point_count; ++i) { + struct nk_vec2 pnt = nk_vec2((float)p->points[i].x, (float)p->points[i].y); + nk_draw_list_path_line_to(&ctx->draw_list, pnt); + } + nk_draw_list_path_stroke(&ctx->draw_list, p->color, NK_STROKE_OPEN, p->line_thickness); + } break; + case NK_COMMAND_TEXT: { + const struct nk_command_text *t = (const struct nk_command_text*)cmd; + nk_draw_list_add_text(&ctx->draw_list, t->font, nk_rect(t->x, t->y, t->w, t->h), + t->string, t->length, t->height, t->foreground); + } break; + case NK_COMMAND_IMAGE: { + const struct nk_command_image *i = (const struct nk_command_image*)cmd; + nk_draw_list_add_image(&ctx->draw_list, i->img, nk_rect(i->x, i->y, i->w, i->h), i->col); + } break; + case NK_COMMAND_CUSTOM: { + const struct nk_command_custom *c = (const struct nk_command_custom*)cmd; + c->callback(&ctx->draw_list, c->x, c->y, c->w, c->h, c->callback_data); + } break; + default: break; + } + } + res |= (cmds->needed > cmds->allocated + (cmds->memory.size - cmds->size)) ? NK_CONVERT_COMMAND_BUFFER_FULL: 0; + res |= (vertices->needed > vertices->allocated) ? NK_CONVERT_VERTEX_BUFFER_FULL: 0; + res |= (elements->needed > elements->allocated) ? NK_CONVERT_ELEMENT_BUFFER_FULL: 0; + return res; +} +NK_API const struct nk_draw_command* +nk__draw_begin(const struct nk_context *ctx, + const struct nk_buffer *buffer) +{ + return nk__draw_list_begin(&ctx->draw_list, buffer); +} +NK_API const struct nk_draw_command* +nk__draw_end(const struct nk_context *ctx, const struct nk_buffer *buffer) +{ + return nk__draw_list_end(&ctx->draw_list, buffer); +} +NK_API const struct nk_draw_command* +nk__draw_next(const struct nk_draw_command *cmd, + const struct nk_buffer *buffer, const struct nk_context *ctx) +{ + return nk__draw_list_next(cmd, buffer, &ctx->draw_list); +} +#endif + + +/* stb_rect_pack.h - v1.01 - public domain - rectangle packing */ +/* Sean Barrett 2014 */ +/* */ +/* Useful for e.g. packing rectangular textures into an atlas. */ +/* Does not do rotation. */ +/* */ +/* Before #including, */ +/* */ +/* #define STB_RECT_PACK_IMPLEMENTATION */ +/* */ +/* in the file that you want to have the implementation. */ +/* */ +/* Not necessarily the awesomest packing method, but better than */ +/* the totally naive one in stb_truetype (which is primarily what */ +/* this is meant to replace). */ +/* */ +/* Has only had a few tests run, may have issues. */ +/* */ +/* More docs to come. */ +/* */ +/* No memory allocations; uses qsort() and assert() from stdlib. */ +/* Can override those by defining STBRP_SORT and STBRP_ASSERT. */ +/* */ +/* This library currently uses the Skyline Bottom-Left algorithm. */ +/* */ +/* Please note: better rectangle packers are welcome! Please */ +/* implement them to the same API, but with a different init */ +/* function. */ +/* */ +/* Credits */ +/* */ +/* Library */ +/* Sean Barrett */ +/* Minor features */ +/* Martins Mozeiko */ +/* github:IntellectualKitty */ +/* */ +/* Bugfixes / warning fixes */ +/* Jeremy Jaussaud */ +/* Fabian Giesen */ +/* */ +/* Version history: */ +/* */ +/* 1.01 (2021-07-11) always use large rect mode, expose STBRP__MAXVAL in public section */ +/* 1.00 (2019-02-25) avoid small space waste; gracefully fail too-wide rectangles */ +/* 0.99 (2019-02-07) warning fixes */ +/* 0.11 (2017-03-03) return packing success/fail result */ +/* 0.10 (2016-10-25) remove cast-away-const to avoid warnings */ +/* 0.09 (2016-08-27) fix compiler warnings */ +/* 0.08 (2015-09-13) really fix bug with empty rects (w=0 or h=0) */ +/* 0.07 (2015-09-13) fix bug with empty rects (w=0 or h=0) */ +/* 0.06 (2015-04-15) added STBRP_SORT to allow replacing qsort */ +/* 0.05: added STBRP_ASSERT to allow replacing assert */ +/* 0.04: fixed minor bug in STBRP_LARGE_RECTS support */ +/* 0.01: initial release */ +/* */ +/* LICENSE */ +/* */ +/* See end of file for license information. */ + +/* //////////////////////////////////////////////////////////////////////////// */ +/* */ +/* INCLUDE SECTION */ +/* */ + +#ifndef STB_INCLUDE_STB_RECT_PACK_H +#define STB_INCLUDE_STB_RECT_PACK_H + +#define STB_RECT_PACK_VERSION 1 + +#ifdef STBRP_STATIC +#define STBRP_DEF static +#else +#define STBRP_DEF extern +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct stbrp_context stbrp_context; +typedef struct stbrp_node stbrp_node; +typedef struct stbrp_rect stbrp_rect; + +typedef int stbrp_coord; + +#define STBRP__MAXVAL 0x7fffffff +/* Mostly for internal use, but this is the maximum supported coordinate value. */ + +STBRP_DEF int stbrp_pack_rects (stbrp_context *context, stbrp_rect *rects, int num_rects); +/* Assign packed locations to rectangles. The rectangles are of type */ +/* 'stbrp_rect' defined below, stored in the array 'rects', and there */ +/* are 'num_rects' many of them. */ +/* */ +/* Rectangles which are successfully packed have the 'was_packed' flag */ +/* set to a non-zero value and 'x' and 'y' store the minimum location */ +/* on each axis (i.e. bottom-left in cartesian coordinates, top-left */ +/* if you imagine y increasing downwards). Rectangles which do not fit */ +/* have the 'was_packed' flag set to 0. */ +/* */ +/* You should not try to access the 'rects' array from another thread */ +/* while this function is running, as the function temporarily reorders */ +/* the array while it executes. */ +/* */ +/* To pack into another rectangle, you need to call stbrp_init_target */ +/* again. To continue packing into the same rectangle, you can call */ +/* this function again. Calling this multiple times with multiple rect */ +/* arrays will probably produce worse packing results than calling it */ +/* a single time with the full rectangle array, but the option is */ +/* available. */ +/* */ +/* The function returns 1 if all of the rectangles were successfully */ +/* packed and 0 otherwise. */ + +struct stbrp_rect +{ + /* reserved for your use: */ + int id; + + /* input: */ + stbrp_coord w, h; + + /* output: */ + stbrp_coord x, y; + int was_packed; /* non-zero if valid packing */ + +}; /* 16 bytes, nominally */ + + +STBRP_DEF void stbrp_init_target (stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes); +/* Initialize a rectangle packer to: */ +/* pack a rectangle that is 'width' by 'height' in dimensions */ +/* using temporary storage provided by the array 'nodes', which is 'num_nodes' long */ +/* */ +/* You must call this function every time you start packing into a new target. */ +/* */ +/* There is no "shutdown" function. The 'nodes' memory must stay valid for */ +/* the following stbrp_pack_rects() call (or calls), but can be freed after */ +/* the call (or calls) finish. */ +/* */ +/* Note: to guarantee best results, either: */ +/* 1. make sure 'num_nodes' >= 'width' */ +/* or 2. call stbrp_allow_out_of_mem() defined below with 'allow_out_of_mem = 1' */ +/* */ +/* If you don't do either of the above things, widths will be quantized to multiples */ +/* of small integers to guarantee the algorithm doesn't run out of temporary storage. */ +/* */ +/* If you do #2, then the non-quantized algorithm will be used, but the algorithm */ +/* may run out of temporary storage and be unable to pack some rectangles. */ + +STBRP_DEF void stbrp_setup_allow_out_of_mem (stbrp_context *context, int allow_out_of_mem); +/* Optionally call this function after init but before doing any packing to */ +/* change the handling of the out-of-temp-memory scenario, described above. */ +/* If you call init again, this will be reset to the default (false). */ + + +STBRP_DEF void stbrp_setup_heuristic (stbrp_context *context, int heuristic); +/* Optionally select which packing heuristic the library should use. Different */ +/* heuristics will produce better/worse results for different data sets. */ +/* If you call init again, this will be reset to the default. */ + +enum +{ + STBRP_HEURISTIC_Skyline_default=0, + STBRP_HEURISTIC_Skyline_BL_sortHeight = STBRP_HEURISTIC_Skyline_default, + STBRP_HEURISTIC_Skyline_BF_sortHeight +}; + + +/* //////////////////////////////////////////////////////////////////////////// */ +/* */ +/* the details of the following structures don't matter to you, but they must */ +/* be visible so you can handle the memory allocations for them */ + +struct stbrp_node +{ + stbrp_coord x,y; + stbrp_node *next; +}; + +struct stbrp_context +{ + int width; + int height; + int align; + int init_mode; + int heuristic; + int num_nodes; + stbrp_node *active_head; + stbrp_node *free_head; + stbrp_node extra[2]; /* we allocate two extra nodes so optimal user-node-count is 'width' not 'width+2' */ +}; + +#ifdef __cplusplus +} +#endif + +#endif + +/* //////////////////////////////////////////////////////////////////////////// */ +/* */ +/* IMPLEMENTATION SECTION */ +/* */ + +#ifdef STB_RECT_PACK_IMPLEMENTATION +#ifndef STBRP_SORT +#include +#define STBRP_SORT qsort +#endif + +#ifndef STBRP_ASSERT +#include +#define STBRP_ASSERT assert +#endif + +#ifdef _MSC_VER +#define STBRP__NOTUSED(v) (void)(v) +#define STBRP__CDECL __cdecl +#else +#define STBRP__NOTUSED(v) (void)sizeof(v) +#define STBRP__CDECL +#endif + +enum +{ + STBRP__INIT_skyline = 1 +}; + +STBRP_DEF void stbrp_setup_heuristic(stbrp_context *context, int heuristic) +{ + switch (context->init_mode) { + case STBRP__INIT_skyline: + STBRP_ASSERT(heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight || heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight); + context->heuristic = heuristic; + break; + default: + STBRP_ASSERT(0); + } +} + +STBRP_DEF void stbrp_setup_allow_out_of_mem(stbrp_context *context, int allow_out_of_mem) +{ + if (allow_out_of_mem) + /* if it's ok to run out of memory, then don't bother aligning them; */ + /* this gives better packing, but may fail due to OOM (even though */ + /* the rectangles easily fit). @TODO a smarter approach would be to only */ + /* quantize once we've hit OOM, then we could get rid of this parameter. */ + context->align = 1; + else { + /* if it's not ok to run out of memory, then quantize the widths */ + /* so that num_nodes is always enough nodes. */ + /* */ + /* I.e. num_nodes * align >= width */ + /* align >= width / num_nodes */ + /* align = ceil(width/num_nodes) */ + + context->align = (context->width + context->num_nodes-1) / context->num_nodes; + } +} + +STBRP_DEF void stbrp_init_target(stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes) +{ + int i; + + for (i=0; i < num_nodes-1; ++i) + nodes[i].next = &nodes[i+1]; + nodes[i].next = NULL; + context->init_mode = STBRP__INIT_skyline; + context->heuristic = STBRP_HEURISTIC_Skyline_default; + context->free_head = &nodes[0]; + context->active_head = &context->extra[0]; + context->width = width; + context->height = height; + context->num_nodes = num_nodes; + stbrp_setup_allow_out_of_mem(context, 0); + + /* node 0 is the full width, node 1 is the sentinel (lets us not store width explicitly) */ + context->extra[0].x = 0; + context->extra[0].y = 0; + context->extra[0].next = &context->extra[1]; + context->extra[1].x = (stbrp_coord) width; + context->extra[1].y = (1<<30); + context->extra[1].next = NULL; +} + +/* find minimum y position if it starts at x1 */ +static int stbrp__skyline_find_min_y(stbrp_context *c, stbrp_node *first, int x0, int width, int *pwaste) +{ + stbrp_node *node = first; + int x1 = x0 + width; + int min_y, visited_width, waste_area; + + STBRP__NOTUSED(c); + + STBRP_ASSERT(first->x <= x0); + + #if 0 + /* skip in case we're past the node */ + while (node->next->x <= x0) + ++node; + #else + STBRP_ASSERT(node->next->x > x0); /* we ended up handling this in the caller for efficiency */ + #endif + + STBRP_ASSERT(node->x <= x0); + + min_y = 0; + waste_area = 0; + visited_width = 0; + while (node->x < x1) { + if (node->y > min_y) { + /* raise min_y higher. */ + /* we've accounted for all waste up to min_y, */ + /* but we'll now add more waste for everything we've visted */ + waste_area += visited_width * (node->y - min_y); + min_y = node->y; + /* the first time through, visited_width might be reduced */ + if (node->x < x0) + visited_width += node->next->x - x0; + else + visited_width += node->next->x - node->x; + } else { + /* add waste area */ + int under_width = node->next->x - node->x; + if (under_width + visited_width > width) + under_width = width - visited_width; + waste_area += under_width * (min_y - node->y); + visited_width += under_width; + } + node = node->next; + } + + *pwaste = waste_area; + return min_y; +} + +typedef struct +{ + int x,y; + stbrp_node **prev_link; +} stbrp__findresult; + +static stbrp__findresult stbrp__skyline_find_best_pos(stbrp_context *c, int width, int height) +{ + int best_waste = (1<<30), best_x, best_y = (1 << 30); + stbrp__findresult fr; + stbrp_node **prev, *node, *tail, **best = NULL; + + /* align to multiple of c->align */ + width = (width + c->align - 1); + width -= width % c->align; + STBRP_ASSERT(width % c->align == 0); + + /* if it can't possibly fit, bail immediately */ + if (width > c->width || height > c->height) { + fr.prev_link = NULL; + fr.x = fr.y = 0; + return fr; + } + + node = c->active_head; + prev = &c->active_head; + while (node->x + width <= c->width) { + int y,waste; + y = stbrp__skyline_find_min_y(c, node, node->x, width, &waste); + if (c->heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight) { /* actually just want to test BL */ + /* bottom left */ + if (y < best_y) { + best_y = y; + best = prev; + } + } else { + /* best-fit */ + if (y + height <= c->height) { + /* can only use it if it first vertically */ + if (y < best_y || (y == best_y && waste < best_waste)) { + best_y = y; + best_waste = waste; + best = prev; + } + } + } + prev = &node->next; + node = node->next; + } + + best_x = (best == NULL) ? 0 : (*best)->x; + + /* if doing best-fit (BF), we also have to try aligning right edge to each node position */ + /* */ + /* e.g, if fitting */ + /* */ + /* ____________________ */ + /* |____________________| */ + /* */ + /* into */ + /* */ + /* | | */ + /* | ____________| */ + /* |____________| */ + /* */ + /* then right-aligned reduces waste, but bottom-left BL is always chooses left-aligned */ + /* */ + /* This makes BF take about 2x the time */ + + if (c->heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight) { + tail = c->active_head; + node = c->active_head; + prev = &c->active_head; + /* find first node that's admissible */ + while (tail->x < width) + tail = tail->next; + while (tail) { + int xpos = tail->x - width; + int y,waste; + STBRP_ASSERT(xpos >= 0); + /* find the left position that matches this */ + while (node->next->x <= xpos) { + prev = &node->next; + node = node->next; + } + STBRP_ASSERT(node->next->x > xpos && node->x <= xpos); + y = stbrp__skyline_find_min_y(c, node, xpos, width, &waste); + if (y + height <= c->height) { + if (y <= best_y) { + if (y < best_y || waste < best_waste || (waste==best_waste && xpos < best_x)) { + best_x = xpos; + STBRP_ASSERT(y <= best_y); + best_y = y; + best_waste = waste; + best = prev; + } + } + } + tail = tail->next; + } + } + + fr.prev_link = best; + fr.x = best_x; + fr.y = best_y; + return fr; +} + +static stbrp__findresult stbrp__skyline_pack_rectangle(stbrp_context *context, int width, int height) +{ + /* find best position according to heuristic */ + stbrp__findresult res = stbrp__skyline_find_best_pos(context, width, height); + stbrp_node *node, *cur; + + /* bail if: */ + /* 1. it failed */ + /* 2. the best node doesn't fit (we don't always check this) */ + /* 3. we're out of memory */ + if (res.prev_link == NULL || res.y + height > context->height || context->free_head == NULL) { + res.prev_link = NULL; + return res; + } + + /* on success, create new node */ + node = context->free_head; + node->x = (stbrp_coord) res.x; + node->y = (stbrp_coord) (res.y + height); + + context->free_head = node->next; + + /* insert the new node into the right starting point, and */ + /* let 'cur' point to the remaining nodes needing to be */ + /* stiched back in */ + + cur = *res.prev_link; + if (cur->x < res.x) { + /* preserve the existing one, so start testing with the next one */ + stbrp_node *next = cur->next; + cur->next = node; + cur = next; + } else { + *res.prev_link = node; + } + + /* from here, traverse cur and free the nodes, until we get to one */ + /* that shouldn't be freed */ + while (cur->next && cur->next->x <= res.x + width) { + stbrp_node *next = cur->next; + /* move the current node to the free list */ + cur->next = context->free_head; + context->free_head = cur; + cur = next; + } + + /* stitch the list back in */ + node->next = cur; + + if (cur->x < res.x + width) + cur->x = (stbrp_coord) (res.x + width); + +#ifdef _DEBUG + cur = context->active_head; + while (cur->x < context->width) { + STBRP_ASSERT(cur->x < cur->next->x); + cur = cur->next; + } + STBRP_ASSERT(cur->next == NULL); + + { + int count=0; + cur = context->active_head; + while (cur) { + cur = cur->next; + ++count; + } + cur = context->free_head; + while (cur) { + cur = cur->next; + ++count; + } + STBRP_ASSERT(count == context->num_nodes+2); + } +#endif + + return res; +} + +static int STBRP__CDECL rect_height_compare(const void *a, const void *b) +{ + const stbrp_rect *p = (const stbrp_rect *) a; + const stbrp_rect *q = (const stbrp_rect *) b; + if (p->h > q->h) + return -1; + if (p->h < q->h) + return 1; + return (p->w > q->w) ? -1 : (p->w < q->w); +} + +static int STBRP__CDECL rect_original_order(const void *a, const void *b) +{ + const stbrp_rect *p = (const stbrp_rect *) a; + const stbrp_rect *q = (const stbrp_rect *) b; + return (p->was_packed < q->was_packed) ? -1 : (p->was_packed > q->was_packed); +} + +STBRP_DEF int stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int num_rects) +{ + int i, all_rects_packed = 1; + + /* we use the 'was_packed' field internally to allow sorting/unsorting */ + for (i=0; i < num_rects; ++i) { + rects[i].was_packed = i; + } + + /* sort according to heuristic */ + STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_height_compare); + + for (i=0; i < num_rects; ++i) { + if (rects[i].w == 0 || rects[i].h == 0) { + rects[i].x = rects[i].y = 0; /* empty rect needs no space */ + } else { + stbrp__findresult fr = stbrp__skyline_pack_rectangle(context, rects[i].w, rects[i].h); + if (fr.prev_link) { + rects[i].x = (stbrp_coord) fr.x; + rects[i].y = (stbrp_coord) fr.y; + } else { + rects[i].x = rects[i].y = STBRP__MAXVAL; + } + } + } + + /* unsort */ + STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_original_order); + + /* set was_packed flags and all_rects_packed status */ + for (i=0; i < num_rects; ++i) { + rects[i].was_packed = !(rects[i].x == STBRP__MAXVAL && rects[i].y == STBRP__MAXVAL); + if (!rects[i].was_packed) + all_rects_packed = 0; + } + + /* return the all_rects_packed status */ + return all_rects_packed; +} +#endif + +/* +------------------------------------------------------------------------------ +This software is available under 2 licenses -- choose whichever you prefer. +------------------------------------------------------------------------------ +ALTERNATIVE A - MIT License +Copyright (c) 2017 Sean Barrett +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +------------------------------------------------------------------------------ +ALTERNATIVE B - Public Domain (www.unlicense.org) +This is free and unencumbered software released into the public domain. +Anyone is free to copy, modify, publish, use, compile, sell, or distribute this +software, either in source code form or as a compiled binary, for any purpose, +commercial or non-commercial, and by any means. +In jurisdictions that recognize copyright laws, the author or authors of this +software dedicate any and all copyright interest in the software to the public +domain. We make this dedication for the benefit of the public at large and to +the detriment of our heirs and successors. We intend this dedication to be an +overt act of relinquishment in perpetuity of all present and future rights to +this software under copyright law. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +------------------------------------------------------------------------------ +*/ + +/* stb_truetype.h - v1.26 - public domain */ +/* authored from 2009-2021 by Sean Barrett / RAD Game Tools */ +/* */ +/* ======================================================================= */ +/* */ +/* NO SECURITY GUARANTEE -- DO NOT USE THIS ON UNTRUSTED FONT FILES */ +/* */ +/* This library does no range checking of the offsets found in the file, */ +/* meaning an attacker can use it to read arbitrary memory. */ +/* */ +/* ======================================================================= */ +/* */ +/* This library processes TrueType files: */ +/* parse files */ +/* extract glyph metrics */ +/* extract glyph shapes */ +/* render glyphs to one-channel bitmaps with antialiasing (box filter) */ +/* render glyphs to one-channel SDF bitmaps (signed-distance field/function) */ +/* */ +/* Todo: */ +/* non-MS cmaps */ +/* crashproof on bad data */ +/* hinting? (no longer patented) */ +/* cleartype-style AA? */ +/* optimize: use simple memory allocator for intermediates */ +/* optimize: build edge-list directly from curves */ +/* optimize: rasterize directly from curves? */ +/* */ +/* ADDITIONAL CONTRIBUTORS */ +/* */ +/* Mikko Mononen: compound shape support, more cmap formats */ +/* Tor Andersson: kerning, subpixel rendering */ +/* Dougall Johnson: OpenType / Type 2 font handling */ +/* Daniel Ribeiro Maciel: basic GPOS-based kerning */ +/* */ +/* Misc other: */ +/* Ryan Gordon */ +/* Simon Glass */ +/* github:IntellectualKitty */ +/* Imanol Celaya */ +/* Daniel Ribeiro Maciel */ +/* */ +/* Bug/warning reports/fixes: */ +/* "Zer" on mollyrocket Fabian "ryg" Giesen github:NiLuJe */ +/* Cass Everitt Martins Mozeiko github:aloucks */ +/* stoiko (Haemimont Games) Cap Petschulat github:oyvindjam */ +/* Brian Hook Omar Cornut github:vassvik */ +/* Walter van Niftrik Ryan Griege */ +/* David Gow Peter LaValle */ +/* David Given Sergey Popov */ +/* Ivan-Assen Ivanov Giumo X. Clanjor */ +/* Anthony Pesch Higor Euripedes */ +/* Johan Duparc Thomas Fields */ +/* Hou Qiming Derek Vinyard */ +/* Rob Loach Cort Stratton */ +/* Kenney Phillis Jr. Brian Costabile */ +/* Ken Voskuil (kaesve) */ +/* */ +/* VERSION HISTORY */ +/* */ +/* 1.26 (2021-08-28) fix broken rasterizer */ +/* 1.25 (2021-07-11) many fixes */ +/* 1.24 (2020-02-05) fix warning */ +/* 1.23 (2020-02-02) query SVG data for glyphs; query whole kerning table (but only kern not GPOS) */ +/* 1.22 (2019-08-11) minimize missing-glyph duplication; fix kerning if both 'GPOS' and 'kern' are defined */ +/* 1.21 (2019-02-25) fix warning */ +/* 1.20 (2019-02-07) PackFontRange skips missing codepoints; GetScaleFontVMetrics() */ +/* 1.19 (2018-02-11) GPOS kerning, STBTT_fmod */ +/* 1.18 (2018-01-29) add missing function */ +/* 1.17 (2017-07-23) make more arguments const; doc fix */ +/* 1.16 (2017-07-12) SDF support */ +/* 1.15 (2017-03-03) make more arguments const */ +/* 1.14 (2017-01-16) num-fonts-in-TTC function */ +/* 1.13 (2017-01-02) support OpenType fonts, certain Apple fonts */ +/* 1.12 (2016-10-25) suppress warnings about casting away const with -Wcast-qual */ +/* 1.11 (2016-04-02) fix unused-variable warning */ +/* 1.10 (2016-04-02) user-defined fabs(); rare memory leak; remove duplicate typedef */ +/* 1.09 (2016-01-16) warning fix; avoid crash on outofmem; use allocation userdata properly */ +/* 1.08 (2015-09-13) document stbtt_Rasterize(); fixes for vertical & horizontal edges */ +/* 1.07 (2015-08-01) allow PackFontRanges to accept arrays of sparse codepoints; */ +/* variant PackFontRanges to pack and render in separate phases; */ +/* fix stbtt_GetFontOFfsetForIndex (never worked for non-0 input?); */ +/* fixed an assert() bug in the new rasterizer */ +/* replace assert() with STBTT_assert() in new rasterizer */ +/* */ +/* Full history can be found at the end of this file. */ +/* */ +/* LICENSE */ +/* */ +/* See end of file for license information. */ +/* */ +/* USAGE */ +/* */ +/* Include this file in whatever places need to refer to it. In ONE C/C++ */ +/* file, write: */ +/* #define STB_TRUETYPE_IMPLEMENTATION */ +/* before the #include of this file. This expands out the actual */ +/* implementation into that C/C++ file. */ +/* */ +/* To make the implementation private to the file that generates the implementation, */ +/* #define STBTT_STATIC */ +/* */ +/* Simple 3D API (don't ship this, but it's fine for tools and quick start) */ +/* stbtt_BakeFontBitmap() -- bake a font to a bitmap for use as texture */ +/* stbtt_GetBakedQuad() -- compute quad to draw for a given char */ +/* */ +/* Improved 3D API (more shippable): */ +/* #include "stb_rect_pack.h" -- optional, but you really want it */ +/* stbtt_PackBegin() */ +/* stbtt_PackSetOversampling() -- for improved quality on small fonts */ +/* stbtt_PackFontRanges() -- pack and renders */ +/* stbtt_PackEnd() */ +/* stbtt_GetPackedQuad() */ +/* */ +/* "Load" a font file from a memory buffer (you have to keep the buffer loaded) */ +/* stbtt_InitFont() */ +/* stbtt_GetFontOffsetForIndex() -- indexing for TTC font collections */ +/* stbtt_GetNumberOfFonts() -- number of fonts for TTC font collections */ +/* */ +/* Render a unicode codepoint to a bitmap */ +/* stbtt_GetCodepointBitmap() -- allocates and returns a bitmap */ +/* stbtt_MakeCodepointBitmap() -- renders into bitmap you provide */ +/* stbtt_GetCodepointBitmapBox() -- how big the bitmap must be */ +/* */ +/* Character advance/positioning */ +/* stbtt_GetCodepointHMetrics() */ +/* stbtt_GetFontVMetrics() */ +/* stbtt_GetFontVMetricsOS2() */ +/* stbtt_GetCodepointKernAdvance() */ +/* */ +/* Starting with version 1.06, the rasterizer was replaced with a new, */ +/* faster and generally-more-precise rasterizer. The new rasterizer more */ +/* accurately measures pixel coverage for anti-aliasing, except in the case */ +/* where multiple shapes overlap, in which case it overestimates the AA pixel */ +/* coverage. Thus, anti-aliasing of intersecting shapes may look wrong. If */ +/* this turns out to be a problem, you can re-enable the old rasterizer with */ +/* #define STBTT_RASTERIZER_VERSION 1 */ +/* which will incur about a 15% speed hit. */ +/* */ +/* ADDITIONAL DOCUMENTATION */ +/* */ +/* Immediately after this block comment are a series of sample programs. */ +/* */ +/* After the sample programs is the "header file" section. This section */ +/* includes documentation for each API function. */ +/* */ +/* Some important concepts to understand to use this library: */ +/* */ +/* Codepoint */ +/* Characters are defined by unicode codepoints, e.g. 65 is */ +/* uppercase A, 231 is lowercase c with a cedilla, 0x7e30 is */ +/* the hiragana for "ma". */ +/* */ +/* Glyph */ +/* A visual character shape (every codepoint is rendered as */ +/* some glyph) */ +/* */ +/* Glyph index */ +/* A font-specific integer ID representing a glyph */ +/* */ +/* Baseline */ +/* Glyph shapes are defined relative to a baseline, which is the */ +/* bottom of uppercase characters. Characters extend both above */ +/* and below the baseline. */ +/* */ +/* Current Point */ +/* As you draw text to the screen, you keep track of a "current point" */ +/* which is the origin of each character. The current point's vertical */ +/* position is the baseline. Even "baked fonts" use this model. */ +/* */ +/* Vertical Font Metrics */ +/* The vertical qualities of the font, used to vertically position */ +/* and space the characters. See docs for stbtt_GetFontVMetrics. */ +/* */ +/* Font Size in Pixels or Points */ +/* The preferred interface for specifying font sizes in stb_truetype */ +/* is to specify how tall the font's vertical extent should be in pixels. */ +/* If that sounds good enough, skip the next paragraph. */ +/* */ +/* Most font APIs instead use "points", which are a common typographic */ +/* measurement for describing font size, defined as 72 points per inch. */ +/* stb_truetype provides a point API for compatibility. However, true */ +/* "per inch" conventions don't make much sense on computer displays */ +/* since different monitors have different number of pixels per */ +/* inch. For example, Windows traditionally uses a convention that */ +/* there are 96 pixels per inch, thus making 'inch' measurements have */ +/* nothing to do with inches, and thus effectively defining a point to */ +/* be 1.333 pixels. Additionally, the TrueType font data provides */ +/* an explicit scale factor to scale a given font's glyphs to points, */ +/* but the author has observed that this scale factor is often wrong */ +/* for non-commercial fonts, thus making fonts scaled in points */ +/* according to the TrueType spec incoherently sized in practice. */ +/* */ +/* DETAILED USAGE: */ +/* */ +/* Scale: */ +/* Select how high you want the font to be, in points or pixels. */ +/* Call ScaleForPixelHeight or ScaleForMappingEmToPixels to compute */ +/* a scale factor SF that will be used by all other functions. */ +/* */ +/* Baseline: */ +/* You need to select a y-coordinate that is the baseline of where */ +/* your text will appear. Call GetFontBoundingBox to get the baseline-relative */ +/* bounding box for all characters. SF*-y0 will be the distance in pixels */ +/* that the worst-case character could extend above the baseline, so if */ +/* you want the top edge of characters to appear at the top of the */ +/* screen where y=0, then you would set the baseline to SF*-y0. */ +/* */ +/* Current point: */ +/* Set the current point where the first character will appear. The */ +/* first character could extend left of the current point; this is font */ +/* dependent. You can either choose a current point that is the leftmost */ +/* point and hope, or add some padding, or check the bounding box or */ +/* left-side-bearing of the first character to be displayed and set */ +/* the current point based on that. */ +/* */ +/* Displaying a character: */ +/* Compute the bounding box of the character. It will contain signed values */ +/* relative to . I.e. if it returns x0,y0,x1,y1, */ +/* then the character should be displayed in the rectangle from */ +/* to = 32 && *text < 128) { + stbtt_aligned_quad q; + stbtt_GetBakedQuad(cdata, 512,512, *text-32, &x,&y,&q,1);/* 1=opengl & d3d10+,0=d3d9 */ + glTexCoord2f(q.s0,q.t0); glVertex2f(q.x0,q.y0); + glTexCoord2f(q.s1,q.t0); glVertex2f(q.x1,q.y0); + glTexCoord2f(q.s1,q.t1); glVertex2f(q.x1,q.y1); + glTexCoord2f(q.s0,q.t1); glVertex2f(q.x0,q.y1); + } + ++text; + } + glEnd(); +} +#endif +/* */ +/* */ +/* //////////////////////////////////////////////////////////////////////////// */ +/* */ +/* Complete program (this compiles): get a single bitmap, print as ASCII art */ +/* */ +#if 0 +#include +#define STB_TRUETYPE_IMPLEMENTATION /* force following include to generate implementation */ +#include "stb_truetype.h" + +char ttf_buffer[1<<25]; + +int main(int argc, char **argv) +{ + stbtt_fontinfo font; + unsigned char *bitmap; + int w,h,i,j,c = (argc > 1 ? atoi(argv[1]) : 'a'), s = (argc > 2 ? atoi(argv[2]) : 20); + + fread(ttf_buffer, 1, 1<<25, fopen(argc > 3 ? argv[3] : "c:/windows/fonts/arialbd.ttf", "rb")); + + stbtt_InitFont(&font, ttf_buffer, stbtt_GetFontOffsetForIndex(ttf_buffer,0)); + bitmap = stbtt_GetCodepointBitmap(&font, 0,stbtt_ScaleForPixelHeight(&font, s), c, &w, &h, 0,0); + + for (j=0; j < h; ++j) { + for (i=0; i < w; ++i) + putchar(" .:ioVM@"[bitmap[j*w+i]>>5]); + putchar('\n'); + } + return 0; +} +#endif +/* */ +/* Output: */ +/* */ +/* .ii. */ +/* @@@@@@. */ +/* V@Mio@@o */ +/* :i. V@V */ +/* :oM@@M */ +/* :@@@MM@M */ +/* @@o o@M */ +/* :@@. M@M */ +/* @@@o@@@@ */ +/* :M@@V:@@. */ +/* */ +/* //////////////////////////////////////////////////////////////////////////// */ +/* */ +/* Complete program: print "Hello World!" banner, with bugs */ +/* */ +#if 0 +char buffer[24<<20]; +unsigned char screen[20][79]; + +int main(int arg, char **argv) +{ + stbtt_fontinfo font; + int i,j,ascent,baseline,ch=0; + float scale, xpos=2; /* leave a little padding in case the character extends left */ + char *text = "Heljo World!"; /* intentionally misspelled to show 'lj' brokenness */ + + fread(buffer, 1, 1000000, fopen("c:/windows/fonts/arialbd.ttf", "rb")); + stbtt_InitFont(&font, buffer, 0); + + scale = stbtt_ScaleForPixelHeight(&font, 15); + stbtt_GetFontVMetrics(&font, &ascent,0,0); + baseline = (int) (ascent*scale); + + while (text[ch]) { + int advance,lsb,x0,y0,x1,y1; + float x_shift = xpos - (float) floor(xpos); + stbtt_GetCodepointHMetrics(&font, text[ch], &advance, &lsb); + stbtt_GetCodepointBitmapBoxSubpixel(&font, text[ch], scale,scale,x_shift,0, &x0,&y0,&x1,&y1); + stbtt_MakeCodepointBitmapSubpixel(&font, &screen[baseline + y0][(int) xpos + x0], x1-x0,y1-y0, 79, scale,scale,x_shift,0, text[ch]); + /* note that this stomps the old data, so where character boxes overlap (e.g. 'lj') it's wrong */ + /* because this API is really for baking character bitmaps into textures. if you want to render */ + /* a sequence of characters, you really need to render each bitmap to a temp buffer, then */ + /* "alpha blend" that into the working buffer */ + xpos += (advance * scale); + if (text[ch+1]) + xpos += scale*stbtt_GetCodepointKernAdvance(&font, text[ch],text[ch+1]); + ++ch; + } + + for (j=0; j < 20; ++j) { + for (i=0; i < 78; ++i) + putchar(" .:ioVM@"[screen[j][i]>>5]); + putchar('\n'); + } + + return 0; +} +#endif + + +/* //////////////////////////////////////////////////////////////////////////// */ +/* //////////////////////////////////////////////////////////////////////////// */ +/* // */ +/* // INTEGRATION WITH YOUR CODEBASE */ +/* // */ +/* // The following sections allow you to supply alternate definitions */ +/* // of C library functions used by stb_truetype, e.g. if you don't */ +/* // link with the C runtime library. */ + +#ifdef STB_TRUETYPE_IMPLEMENTATION + /* #define your own (u)stbtt_int8/16/32 before including to override this */ + #ifndef stbtt_uint8 + typedef unsigned char stbtt_uint8; + typedef signed char stbtt_int8; + typedef unsigned short stbtt_uint16; + typedef signed short stbtt_int16; + typedef unsigned int stbtt_uint32; + typedef signed int stbtt_int32; + #endif + + typedef char stbtt__check_size32[sizeof(stbtt_int32)==4 ? 1 : -1]; + typedef char stbtt__check_size16[sizeof(stbtt_int16)==2 ? 1 : -1]; + + /* e.g. #define your own STBTT_ifloor/STBTT_iceil() to avoid math.h */ + #ifndef STBTT_ifloor + #include + #define STBTT_ifloor(x) ((int) floor(x)) + #define STBTT_iceil(x) ((int) ceil(x)) + #endif + + #ifndef STBTT_sqrt + #include + #define STBTT_sqrt(x) sqrt(x) + #define STBTT_pow(x,y) pow(x,y) + #endif + + #ifndef STBTT_fmod + #include + #define STBTT_fmod(x,y) fmod(x,y) + #endif + + #ifndef STBTT_cos + #include + #define STBTT_cos(x) cos(x) + #define STBTT_acos(x) acos(x) + #endif + + #ifndef STBTT_fabs + #include + #define STBTT_fabs(x) fabs(x) + #endif + + /* #define your own functions "STBTT_malloc" / "STBTT_free" to avoid malloc.h */ + #ifndef STBTT_malloc + #include + #define STBTT_malloc(x,u) ((void)(u),malloc(x)) + #define STBTT_free(x,u) ((void)(u),free(x)) + #endif + + #ifndef STBTT_assert + #include + #define STBTT_assert(x) assert(x) + #endif + + #ifndef STBTT_strlen + #include + #define STBTT_strlen(x) strlen(x) + #endif + + #ifndef STBTT_memcpy + #include + #define STBTT_memcpy memcpy + #define STBTT_memset memset + #endif +#endif + +/* ///////////////////////////////////////////////////////////////////////////// */ +/* ///////////////////////////////////////////////////////////////////////////// */ +/* // */ +/* // INTERFACE */ +/* // */ +/* // */ + +#ifndef __STB_INCLUDE_STB_TRUETYPE_H__ +#define __STB_INCLUDE_STB_TRUETYPE_H__ + +#ifdef STBTT_STATIC +#define STBTT_DEF static +#else +#define STBTT_DEF extern +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/* private structure */ +typedef struct +{ + unsigned char *data; + int cursor; + int size; +} stbtt__buf; + +/* //////////////////////////////////////////////////////////////////////////// */ +/* */ +/* TEXTURE BAKING API */ +/* */ +/* If you use this API, you only have to call two functions ever. */ +/* */ + +typedef struct +{ + unsigned short x0,y0,x1,y1; /* coordinates of bbox in bitmap */ + float xoff,yoff,xadvance; +} stbtt_bakedchar; + +STBTT_DEF int stbtt_BakeFontBitmap(const unsigned char *data, int offset, /* font location (use offset=0 for plain .ttf) */ + float pixel_height, /* height of font in pixels */ + unsigned char *pixels, int pw, int ph, /* bitmap to be filled in */ + int first_char, int num_chars, /* characters to bake */ + stbtt_bakedchar *chardata); /* you allocate this, it's num_chars long */ +/* if return is positive, the first unused row of the bitmap */ +/* if return is negative, returns the negative of the number of characters that fit */ +/* if return is 0, no characters fit and no rows were used */ +/* This uses a very crappy packing. */ + +typedef struct +{ + float x0,y0,s0,t0; /* top-left */ + float x1,y1,s1,t1; /* bottom-right */ +} stbtt_aligned_quad; + +STBTT_DEF void stbtt_GetBakedQuad(const stbtt_bakedchar *chardata, int pw, int ph, /* same data as above */ + int char_index, /* character to display */ + float *xpos, float *ypos, /* pointers to current position in screen pixel space */ + stbtt_aligned_quad *q, /* output: quad to draw */ + int opengl_fillrule); /* true if opengl fill rule; false if DX9 or earlier */ +/* Call GetBakedQuad with char_index = 'character - first_char', and it */ +/* creates the quad you need to draw and advances the current position. */ +/* */ +/* The coordinate system used assumes y increases downwards. */ +/* */ +/* Characters will extend both above and below the current position; */ +/* see discussion of "BASELINE" above. */ +/* */ +/* It's inefficient; you might want to c&p it and optimize it. */ + +STBTT_DEF void stbtt_GetScaledFontVMetrics(const unsigned char *fontdata, int index, float size, float *ascent, float *descent, float *lineGap); +/* Query the font vertical metrics without having to create a font first. */ + + +/* //////////////////////////////////////////////////////////////////////////// */ +/* */ +/* NEW TEXTURE BAKING API */ +/* */ +/* This provides options for packing multiple fonts into one atlas, not */ +/* perfectly but better than nothing. */ + +typedef struct +{ + unsigned short x0,y0,x1,y1; /* coordinates of bbox in bitmap */ + float xoff,yoff,xadvance; + float xoff2,yoff2; +} stbtt_packedchar; + +typedef struct stbtt_pack_context stbtt_pack_context; +typedef struct stbtt_fontinfo stbtt_fontinfo; +#ifndef STB_RECT_PACK_VERSION +typedef struct stbrp_rect stbrp_rect; +#endif + +STBTT_DEF int stbtt_PackBegin(stbtt_pack_context *spc, unsigned char *pixels, int width, int height, int stride_in_bytes, int padding, void *alloc_context); +/* Initializes a packing context stored in the passed-in stbtt_pack_context. */ +/* Future calls using this context will pack characters into the bitmap passed */ +/* in here: a 1-channel bitmap that is width * height. stride_in_bytes is */ +/* the distance from one row to the next (or 0 to mean they are packed tightly */ +/* together). "padding" is the amount of padding to leave between each */ +/* character (normally you want '1' for bitmaps you'll use as textures with */ +/* bilinear filtering). */ +/* */ +/* Returns 0 on failure, 1 on success. */ + +STBTT_DEF void stbtt_PackEnd (stbtt_pack_context *spc); +/* Cleans up the packing context and frees all memory. */ + +#define STBTT_POINT_SIZE(x) (-(x)) + +STBTT_DEF int stbtt_PackFontRange(stbtt_pack_context *spc, const unsigned char *fontdata, int font_index, float font_size, + int first_unicode_char_in_range, int num_chars_in_range, stbtt_packedchar *chardata_for_range); +/* Creates character bitmaps from the font_index'th font found in fontdata (use */ +/* font_index=0 if you don't know what that is). It creates num_chars_in_range */ +/* bitmaps for characters with unicode values starting at first_unicode_char_in_range */ +/* and increasing. Data for how to render them is stored in chardata_for_range; */ +/* pass these to stbtt_GetPackedQuad to get back renderable quads. */ +/* */ +/* font_size is the full height of the character from ascender to descender, */ +/* as computed by stbtt_ScaleForPixelHeight. To use a point size as computed */ +/* by stbtt_ScaleForMappingEmToPixels, wrap the point size in STBTT_POINT_SIZE() */ +/* and pass that result as 'font_size': */ +/* ..., 20 , ... // font max minus min y is 20 pixels tall */ +/* ..., STBTT_POINT_SIZE(20), ... // 'M' is 20 pixels tall */ + +typedef struct +{ + float font_size; + int first_unicode_codepoint_in_range; /* if non-zero, then the chars are continuous, and this is the first codepoint */ + int *array_of_unicode_codepoints; /* if non-zero, then this is an array of unicode codepoints */ + int num_chars; + stbtt_packedchar *chardata_for_range; /* output */ + unsigned char h_oversample, v_oversample; /* don't set these, they're used internally */ +} stbtt_pack_range; + +STBTT_DEF int stbtt_PackFontRanges(stbtt_pack_context *spc, const unsigned char *fontdata, int font_index, stbtt_pack_range *ranges, int num_ranges); +/* Creates character bitmaps from multiple ranges of characters stored in */ +/* ranges. This will usually create a better-packed bitmap than multiple */ +/* calls to stbtt_PackFontRange. Note that you can call this multiple */ +/* times within a single PackBegin/PackEnd. */ + +STBTT_DEF void stbtt_PackSetOversampling(stbtt_pack_context *spc, unsigned int h_oversample, unsigned int v_oversample); +/* Oversampling a font increases the quality by allowing higher-quality subpixel */ +/* positioning, and is especially valuable at smaller text sizes. */ +/* */ +/* This function sets the amount of oversampling for all following calls to */ +/* stbtt_PackFontRange(s) or stbtt_PackFontRangesGatherRects for a given */ +/* pack context. The default (no oversampling) is achieved by h_oversample=1 */ +/* and v_oversample=1. The total number of pixels required is */ +/* h_oversample*v_oversample larger than the default; for example, 2x2 */ +/* oversampling requires 4x the storage of 1x1. For best results, render */ +/* oversampled textures with bilinear filtering. Look at the readme in */ +/* stb/tests/oversample for information about oversampled fonts */ +/* */ +/* To use with PackFontRangesGather etc., you must set it before calls */ +/* call to PackFontRangesGatherRects. */ + +STBTT_DEF void stbtt_PackSetSkipMissingCodepoints(stbtt_pack_context *spc, int skip); +/* If skip != 0, this tells stb_truetype to skip any codepoints for which */ +/* there is no corresponding glyph. If skip=0, which is the default, then */ +/* codepoints without a glyph recived the font's "missing character" glyph, */ +/* typically an empty box by convention. */ + +STBTT_DEF void stbtt_GetPackedQuad(const stbtt_packedchar *chardata, int pw, int ph, /* same data as above */ + int char_index, /* character to display */ + float *xpos, float *ypos, /* pointers to current position in screen pixel space */ + stbtt_aligned_quad *q, /* output: quad to draw */ + int align_to_integer); + +STBTT_DEF int stbtt_PackFontRangesGatherRects(stbtt_pack_context *spc, const stbtt_fontinfo *info, stbtt_pack_range *ranges, int num_ranges, stbrp_rect *rects); +STBTT_DEF void stbtt_PackFontRangesPackRects(stbtt_pack_context *spc, stbrp_rect *rects, int num_rects); +STBTT_DEF int stbtt_PackFontRangesRenderIntoRects(stbtt_pack_context *spc, const stbtt_fontinfo *info, stbtt_pack_range *ranges, int num_ranges, stbrp_rect *rects); +/* Calling these functions in sequence is roughly equivalent to calling */ +/* stbtt_PackFontRanges(). If you more control over the packing of multiple */ +/* fonts, or if you want to pack custom data into a font texture, take a look */ +/* at the source to of stbtt_PackFontRanges() and create a custom version */ +/* using these functions, e.g. call GatherRects multiple times, */ +/* building up a single array of rects, then call PackRects once, */ +/* then call RenderIntoRects repeatedly. This may result in a */ +/* better packing than calling PackFontRanges multiple times */ +/* (or it may not). */ + +/* this is an opaque structure that you shouldn't mess with which holds */ +/* all the context needed from PackBegin to PackEnd. */ +struct stbtt_pack_context { + void *user_allocator_context; + void *pack_info; + int width; + int height; + int stride_in_bytes; + int padding; + int skip_missing; + unsigned int h_oversample, v_oversample; + unsigned char *pixels; + void *nodes; +}; + +/* //////////////////////////////////////////////////////////////////////////// */ +/* */ +/* FONT LOADING */ +/* */ +/* */ + +STBTT_DEF int stbtt_GetNumberOfFonts(const unsigned char *data); +/* This function will determine the number of fonts in a font file. TrueType */ +/* collection (.ttc) files may contain multiple fonts, while TrueType font */ +/* (.ttf) files only contain one font. The number of fonts can be used for */ +/* indexing with the previous function where the index is between zero and one */ +/* less than the total fonts. If an error occurs, -1 is returned. */ + +STBTT_DEF int stbtt_GetFontOffsetForIndex(const unsigned char *data, int index); +/* Each .ttf/.ttc file may have more than one font. Each font has a sequential */ +/* index number starting from 0. Call this function to get the font offset for */ +/* a given index; it returns -1 if the index is out of range. A regular .ttf */ +/* file will only define one font and it always be at offset 0, so it will */ +/* return '0' for index 0, and -1 for all other indices. */ + +/* The following structure is defined publicly so you can declare one on */ +/* the stack or as a global or etc, but you should treat it as opaque. */ +struct stbtt_fontinfo +{ + void * userdata; + unsigned char * data; /* pointer to .ttf file */ + int fontstart; /* offset of start of font */ + + int numGlyphs; /* number of glyphs, needed for range checking */ + + int loca,head,glyf,hhea,hmtx,kern,gpos,svg; /* table locations as offset from start of .ttf */ + int index_map; /* a cmap mapping for our chosen character encoding */ + int indexToLocFormat; /* format needed to map from glyph index to glyph */ + + stbtt__buf cff; /* cff font data */ + stbtt__buf charstrings; /* the charstring index */ + stbtt__buf gsubrs; /* global charstring subroutines index */ + stbtt__buf subrs; /* private charstring subroutines index */ + stbtt__buf fontdicts; /* array of font dicts */ + stbtt__buf fdselect; /* map from glyph to fontdict */ +}; + +STBTT_DEF int stbtt_InitFont(stbtt_fontinfo *info, const unsigned char *data, int offset); +/* Given an offset into the file that defines a font, this function builds */ +/* the necessary cached info for the rest of the system. You must allocate */ +/* the stbtt_fontinfo yourself, and stbtt_InitFont will fill it out. You don't */ +/* need to do anything special to free it, because the contents are pure */ +/* value data with no additional data structures. Returns 0 on failure. */ + + +/* //////////////////////////////////////////////////////////////////////////// */ +/* */ +/* CHARACTER TO GLYPH-INDEX CONVERSIOn */ + +STBTT_DEF int stbtt_FindGlyphIndex(const stbtt_fontinfo *info, int unicode_codepoint); +/* If you're going to perform multiple operations on the same character */ +/* and you want a speed-up, call this function with the character you're */ +/* going to process, then use glyph-based functions instead of the */ +/* codepoint-based functions. */ +/* Returns 0 if the character codepoint is not defined in the font. */ + + +/* //////////////////////////////////////////////////////////////////////////// */ +/* */ +/* CHARACTER PROPERTIES */ +/* */ + +STBTT_DEF float stbtt_ScaleForPixelHeight(const stbtt_fontinfo *info, float pixels); +/* computes a scale factor to produce a font whose "height" is 'pixels' tall. */ +/* Height is measured as the distance from the highest ascender to the lowest */ +/* descender; in other words, it's equivalent to calling stbtt_GetFontVMetrics */ +/* and computing: */ +/* scale = pixels / (ascent - descent) */ +/* so if you prefer to measure height by the ascent only, use a similar calculation. */ + +STBTT_DEF float stbtt_ScaleForMappingEmToPixels(const stbtt_fontinfo *info, float pixels); +/* computes a scale factor to produce a font whose EM size is mapped to */ +/* 'pixels' tall. This is probably what traditional APIs compute, but */ +/* I'm not positive. */ + +STBTT_DEF void stbtt_GetFontVMetrics(const stbtt_fontinfo *info, int *ascent, int *descent, int *lineGap); +/* ascent is the coordinate above the baseline the font extends; descent */ +/* is the coordinate below the baseline the font extends (i.e. it is typically negative) */ +/* lineGap is the spacing between one row's descent and the next row's ascent... */ +/* so you should advance the vertical position by "*ascent - *descent + *lineGap" */ +/* these are expressed in unscaled coordinates, so you must multiply by */ +/* the scale factor for a given size */ + +STBTT_DEF int stbtt_GetFontVMetricsOS2(const stbtt_fontinfo *info, int *typoAscent, int *typoDescent, int *typoLineGap); +/* analogous to GetFontVMetrics, but returns the "typographic" values from the OS/2 */ +/* table (specific to MS/Windows TTF files). */ +/* */ +/* Returns 1 on success (table present), 0 on failure. */ + +STBTT_DEF void stbtt_GetFontBoundingBox(const stbtt_fontinfo *info, int *x0, int *y0, int *x1, int *y1); +/* the bounding box around all possible characters */ + +STBTT_DEF void stbtt_GetCodepointHMetrics(const stbtt_fontinfo *info, int codepoint, int *advanceWidth, int *leftSideBearing); +/* leftSideBearing is the offset from the current horizontal position to the left edge of the character */ +/* advanceWidth is the offset from the current horizontal position to the next horizontal position */ +/* these are expressed in unscaled coordinates */ + +STBTT_DEF int stbtt_GetCodepointKernAdvance(const stbtt_fontinfo *info, int ch1, int ch2); +/* an additional amount to add to the 'advance' value between ch1 and ch2 */ + +STBTT_DEF int stbtt_GetCodepointBox(const stbtt_fontinfo *info, int codepoint, int *x0, int *y0, int *x1, int *y1); +/* Gets the bounding box of the visible part of the glyph, in unscaled coordinates */ + +STBTT_DEF void stbtt_GetGlyphHMetrics(const stbtt_fontinfo *info, int glyph_index, int *advanceWidth, int *leftSideBearing); +STBTT_DEF int stbtt_GetGlyphKernAdvance(const stbtt_fontinfo *info, int glyph1, int glyph2); +STBTT_DEF int stbtt_GetGlyphBox(const stbtt_fontinfo *info, int glyph_index, int *x0, int *y0, int *x1, int *y1); +/* as above, but takes one or more glyph indices for greater efficiency */ + +typedef struct stbtt_kerningentry +{ + int glyph1; /* use stbtt_FindGlyphIndex */ + int glyph2; + int advance; +} stbtt_kerningentry; + +STBTT_DEF int stbtt_GetKerningTableLength(const stbtt_fontinfo *info); +STBTT_DEF int stbtt_GetKerningTable(const stbtt_fontinfo *info, stbtt_kerningentry* table, int table_length); +/* Retrieves a complete list of all of the kerning pairs provided by the font */ +/* stbtt_GetKerningTable never writes more than table_length entries and returns how many entries it did write. */ +/* The table will be sorted by (a.glyph1 == b.glyph1)?(a.glyph2 < b.glyph2):(a.glyph1 < b.glyph1) */ + +/* //////////////////////////////////////////////////////////////////////////// */ +/* */ +/* GLYPH SHAPES (you probably don't need these, but they have to go before */ +/* the bitmaps for C declaration-order reasons) */ +/* */ + +#ifndef STBTT_vmove /* you can predefine these to use different values (but why?) */ + enum { + STBTT_vmove=1, + STBTT_vline, + STBTT_vcurve, + STBTT_vcubic + }; +#endif + +#ifndef stbtt_vertex /* you can predefine this to use different values */ + /* (we share this with other code at RAD) */ + #define stbtt_vertex_type short /* can't use stbtt_int16 because that's not visible in the header file */ + typedef struct + { + stbtt_vertex_type x,y,cx,cy,cx1,cy1; + unsigned char type,padding; + } stbtt_vertex; +#endif + +STBTT_DEF int stbtt_IsGlyphEmpty(const stbtt_fontinfo *info, int glyph_index); +/* returns non-zero if nothing is drawn for this glyph */ + +STBTT_DEF int stbtt_GetCodepointShape(const stbtt_fontinfo *info, int unicode_codepoint, stbtt_vertex **vertices); +STBTT_DEF int stbtt_GetGlyphShape(const stbtt_fontinfo *info, int glyph_index, stbtt_vertex **vertices); +/* returns # of vertices and fills *vertices with the pointer to them */ +/* these are expressed in "unscaled" coordinates */ +/* */ +/* The shape is a series of contours. Each one starts with */ +/* a STBTT_moveto, then consists of a series of mixed */ +/* STBTT_lineto and STBTT_curveto segments. A lineto */ +/* draws a line from previous endpoint to its x,y; a curveto */ +/* draws a quadratic bezier from previous endpoint to */ +/* its x,y, using cx,cy as the bezier control point. */ + +STBTT_DEF void stbtt_FreeShape(const stbtt_fontinfo *info, stbtt_vertex *vertices); +/* frees the data allocated above */ + +STBTT_DEF unsigned char *stbtt_FindSVGDoc(const stbtt_fontinfo *info, int gl); +STBTT_DEF int stbtt_GetCodepointSVG(const stbtt_fontinfo *info, int unicode_codepoint, const char **svg); +STBTT_DEF int stbtt_GetGlyphSVG(const stbtt_fontinfo *info, int gl, const char **svg); +/* fills svg with the character's SVG data. */ +/* returns data size or 0 if SVG not found. */ + +/* //////////////////////////////////////////////////////////////////////////// */ +/* */ +/* BITMAP RENDERING */ +/* */ + +STBTT_DEF void stbtt_FreeBitmap(unsigned char *bitmap, void *userdata); +/* frees the bitmap allocated below */ + +STBTT_DEF unsigned char *stbtt_GetCodepointBitmap(const stbtt_fontinfo *info, float scale_x, float scale_y, int codepoint, int *width, int *height, int *xoff, int *yoff); +/* allocates a large-enough single-channel 8bpp bitmap and renders the */ +/* specified character/glyph at the specified scale into it, with */ +/* antialiasing. 0 is no coverage (transparent), 255 is fully covered (opaque). */ +/* *width & *height are filled out with the width & height of the bitmap, */ +/* which is stored left-to-right, top-to-bottom. */ +/* */ +/* xoff/yoff are the offset it pixel space from the glyph origin to the top-left of the bitmap */ + +STBTT_DEF unsigned char *stbtt_GetCodepointBitmapSubpixel(const stbtt_fontinfo *info, float scale_x, float scale_y, float shift_x, float shift_y, int codepoint, int *width, int *height, int *xoff, int *yoff); +/* the same as stbtt_GetCodepoitnBitmap, but you can specify a subpixel */ +/* shift for the character */ + +STBTT_DEF void stbtt_MakeCodepointBitmap(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, int codepoint); +/* the same as stbtt_GetCodepointBitmap, but you pass in storage for the bitmap */ +/* in the form of 'output', with row spacing of 'out_stride' bytes. the bitmap */ +/* is clipped to out_w/out_h bytes. Call stbtt_GetCodepointBitmapBox to get the */ +/* width and height and positioning info for it first. */ + +STBTT_DEF void stbtt_MakeCodepointBitmapSubpixel(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int codepoint); +/* same as stbtt_MakeCodepointBitmap, but you can specify a subpixel */ +/* shift for the character */ + +STBTT_DEF void stbtt_MakeCodepointBitmapSubpixelPrefilter(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int oversample_x, int oversample_y, float *sub_x, float *sub_y, int codepoint); +/* same as stbtt_MakeCodepointBitmapSubpixel, but prefiltering */ +/* is performed (see stbtt_PackSetOversampling) */ + +STBTT_DEF void stbtt_GetCodepointBitmapBox(const stbtt_fontinfo *font, int codepoint, float scale_x, float scale_y, int *ix0, int *iy0, int *ix1, int *iy1); +/* get the bbox of the bitmap centered around the glyph origin; so the */ +/* bitmap width is ix1-ix0, height is iy1-iy0, and location to place */ +/* the bitmap top left is (leftSideBearing*scale,iy0). */ +/* (Note that the bitmap uses y-increases-down, but the shape uses */ +/* y-increases-up, so CodepointBitmapBox and CodepointBox are inverted.) */ + +STBTT_DEF void stbtt_GetCodepointBitmapBoxSubpixel(const stbtt_fontinfo *font, int codepoint, float scale_x, float scale_y, float shift_x, float shift_y, int *ix0, int *iy0, int *ix1, int *iy1); +/* same as stbtt_GetCodepointBitmapBox, but you can specify a subpixel */ +/* shift for the character */ + +/* the following functions are equivalent to the above functions, but operate */ +/* on glyph indices instead of Unicode codepoints (for efficiency) */ +STBTT_DEF unsigned char *stbtt_GetGlyphBitmap(const stbtt_fontinfo *info, float scale_x, float scale_y, int glyph, int *width, int *height, int *xoff, int *yoff); +STBTT_DEF unsigned char *stbtt_GetGlyphBitmapSubpixel(const stbtt_fontinfo *info, float scale_x, float scale_y, float shift_x, float shift_y, int glyph, int *width, int *height, int *xoff, int *yoff); +STBTT_DEF void stbtt_MakeGlyphBitmap(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, int glyph); +STBTT_DEF void stbtt_MakeGlyphBitmapSubpixel(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int glyph); +STBTT_DEF void stbtt_MakeGlyphBitmapSubpixelPrefilter(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int oversample_x, int oversample_y, float *sub_x, float *sub_y, int glyph); +STBTT_DEF void stbtt_GetGlyphBitmapBox(const stbtt_fontinfo *font, int glyph, float scale_x, float scale_y, int *ix0, int *iy0, int *ix1, int *iy1); +STBTT_DEF void stbtt_GetGlyphBitmapBoxSubpixel(const stbtt_fontinfo *font, int glyph, float scale_x, float scale_y,float shift_x, float shift_y, int *ix0, int *iy0, int *ix1, int *iy1); + + +/* @TODO: don't expose this structure */ +typedef struct +{ + int w,h,stride; + unsigned char *pixels; +} stbtt__bitmap; + +/* rasterize a shape with quadratic beziers into a bitmap */ +STBTT_DEF void stbtt_Rasterize(stbtt__bitmap *result, /* 1-channel bitmap to draw into */ + float flatness_in_pixels, /* allowable error of curve in pixels */ + stbtt_vertex *vertices, /* array of vertices defining shape */ + int num_verts, /* number of vertices in above array */ + float scale_x, float scale_y, /* scale applied to input vertices */ + float shift_x, float shift_y, /* translation applied to input vertices */ + int x_off, int y_off, /* another translation applied to input */ + int invert, /* if non-zero, vertically flip shape */ + void *userdata); /* context for to STBTT_MALLOC */ + +/* //////////////////////////////////////////////////////////////////////////// */ +/* */ +/* Signed Distance Function (or Field) rendering */ + +STBTT_DEF void stbtt_FreeSDF(unsigned char *bitmap, void *userdata); +/* frees the SDF bitmap allocated below */ + +STBTT_DEF unsigned char * stbtt_GetGlyphSDF(const stbtt_fontinfo *info, float scale, int glyph, int padding, unsigned char onedge_value, float pixel_dist_scale, int *width, int *height, int *xoff, int *yoff); +STBTT_DEF unsigned char * stbtt_GetCodepointSDF(const stbtt_fontinfo *info, float scale, int codepoint, int padding, unsigned char onedge_value, float pixel_dist_scale, int *width, int *height, int *xoff, int *yoff); +/* These functions compute a discretized SDF field for a single character, suitable for storing */ +/* in a single-channel texture, sampling with bilinear filtering, and testing against */ +/* larger than some threshold to produce scalable fonts. */ +/* info -- the font */ +/* scale -- controls the size of the resulting SDF bitmap, same as it would be creating a regular bitmap */ +/* glyph/codepoint -- the character to generate the SDF for */ +/* padding -- extra "pixels" around the character which are filled with the distance to the character (not 0), */ +/* which allows effects like bit outlines */ +/* onedge_value -- value 0-255 to test the SDF against to reconstruct the character (i.e. the isocontour of the character) */ +/* pixel_dist_scale -- what value the SDF should increase by when moving one SDF "pixel" away from the edge (on the 0..255 scale) */ +/* if positive, > onedge_value is inside; if negative, < onedge_value is inside */ +/* width,height -- output height & width of the SDF bitmap (including padding) */ +/* xoff,yoff -- output origin of the character */ +/* return value -- a 2D array of bytes 0..255, width*height in size */ +/* */ +/* pixel_dist_scale & onedge_value are a scale & bias that allows you to make */ +/* optimal use of the limited 0..255 for your application, trading off precision */ +/* and special effects. SDF values outside the range 0..255 are clamped to 0..255. */ +/* */ +/* Example: */ +/* scale = stbtt_ScaleForPixelHeight(22) */ +/* padding = 5 */ +/* onedge_value = 180 */ +/* pixel_dist_scale = 180/5.0 = 36.0 */ +/* */ +/* This will create an SDF bitmap in which the character is about 22 pixels */ +/* high but the whole bitmap is about 22+5+5=32 pixels high. To produce a filled */ +/* shape, sample the SDF at each pixel and fill the pixel if the SDF value */ +/* is greater than or equal to 180/255. (You'll actually want to antialias, */ +/* which is beyond the scope of this example.) Additionally, you can compute */ +/* offset outlines (e.g. to stroke the character border inside & outside, */ +/* or only outside). For example, to fill outside the character up to 3 SDF */ +/* pixels, you would compare against (180-36.0*3)/255 = 72/255. The above */ +/* choice of variables maps a range from 5 pixels outside the shape to */ +/* 2 pixels inside the shape to 0..255; this is intended primarily for apply */ +/* outside effects only (the interior range is needed to allow proper */ +/* antialiasing of the font at *smaller* sizes) */ +/* */ +/* The function computes the SDF analytically at each SDF pixel, not by e.g. */ +/* building a higher-res bitmap and approximating it. In theory the quality */ +/* should be as high as possible for an SDF of this size & representation, but */ +/* unclear if this is true in practice (perhaps building a higher-res bitmap */ +/* and computing from that can allow drop-out prevention). */ +/* */ +/* The algorithm has not been optimized at all, so expect it to be slow */ +/* if computing lots of characters or very large sizes. */ + + + +/* //////////////////////////////////////////////////////////////////////////// */ +/* */ +/* Finding the right font... */ +/* */ +/* You should really just solve this offline, keep your own tables */ +/* of what font is what, and don't try to get it out of the .ttf file. */ +/* That's because getting it out of the .ttf file is really hard, because */ +/* the names in the file can appear in many possible encodings, in many */ +/* possible languages, and e.g. if you need a case-insensitive comparison, */ +/* the details of that depend on the encoding & language in a complex way */ +/* (actually underspecified in truetype, but also gigantic). */ +/* */ +/* But you can use the provided functions in two possible ways: */ +/* stbtt_FindMatchingFont() will use *case-sensitive* comparisons on */ +/* unicode-encoded names to try to find the font you want; */ +/* you can run this before calling stbtt_InitFont() */ +/* */ +/* stbtt_GetFontNameString() lets you get any of the various strings */ +/* from the file yourself and do your own comparisons on them. */ +/* You have to have called stbtt_InitFont() first. */ + + +STBTT_DEF int stbtt_FindMatchingFont(const unsigned char *fontdata, const char *name, int flags); +/* returns the offset (not index) of the font that matches, or -1 if none */ +/* if you use STBTT_MACSTYLE_DONTCARE, use a font name like "Arial Bold". */ +/* if you use any other flag, use a font name like "Arial"; this checks */ +/* the 'macStyle' header field; i don't know if fonts set this consistently */ +#define STBTT_MACSTYLE_DONTCARE 0 +#define STBTT_MACSTYLE_BOLD 1 +#define STBTT_MACSTYLE_ITALIC 2 +#define STBTT_MACSTYLE_UNDERSCORE 4 +#define STBTT_MACSTYLE_NONE 8 /* <= not same as 0, this makes us check the bitfield is 0 */ + +STBTT_DEF int stbtt_CompareUTF8toUTF16_bigendian(const char *s1, int len1, const char *s2, int len2); +/* returns 1/0 whether the first string interpreted as utf8 is identical to */ +/* the second string interpreted as big-endian utf16... useful for strings from next func */ + +STBTT_DEF const char *stbtt_GetFontNameString(const stbtt_fontinfo *font, int *length, int platformID, int encodingID, int languageID, int nameID); +/* returns the string (which may be big-endian double byte, e.g. for unicode) */ +/* and puts the length in bytes in *length. */ +/* */ +/* some of the values for the IDs are below; for more see the truetype spec: */ +/* http://developer.apple.com/textfonts/TTRefMan/RM06/Chap6name.html */ +/* http://www.microsoft.com/typography/otspec/name.htm */ + +enum { /* platformID */ + STBTT_PLATFORM_ID_UNICODE =0, + STBTT_PLATFORM_ID_MAC =1, + STBTT_PLATFORM_ID_ISO =2, + STBTT_PLATFORM_ID_MICROSOFT =3 +}; + +enum { /* encodingID for STBTT_PLATFORM_ID_UNICODE */ + STBTT_UNICODE_EID_UNICODE_1_0 =0, + STBTT_UNICODE_EID_UNICODE_1_1 =1, + STBTT_UNICODE_EID_ISO_10646 =2, + STBTT_UNICODE_EID_UNICODE_2_0_BMP=3, + STBTT_UNICODE_EID_UNICODE_2_0_FULL=4 +}; + +enum { /* encodingID for STBTT_PLATFORM_ID_MICROSOFT */ + STBTT_MS_EID_SYMBOL =0, + STBTT_MS_EID_UNICODE_BMP =1, + STBTT_MS_EID_SHIFTJIS =2, + STBTT_MS_EID_UNICODE_FULL =10 +}; + +enum { /* encodingID for STBTT_PLATFORM_ID_MAC; same as Script Manager codes */ + STBTT_MAC_EID_ROMAN =0, STBTT_MAC_EID_ARABIC =4, + STBTT_MAC_EID_JAPANESE =1, STBTT_MAC_EID_HEBREW =5, + STBTT_MAC_EID_CHINESE_TRAD =2, STBTT_MAC_EID_GREEK =6, + STBTT_MAC_EID_KOREAN =3, STBTT_MAC_EID_RUSSIAN =7 +}; + +enum { /* languageID for STBTT_PLATFORM_ID_MICROSOFT; same as LCID... */ + /* problematic because there are e.g. 16 english LCIDs and 16 arabic LCIDs */ + STBTT_MS_LANG_ENGLISH =0x0409, STBTT_MS_LANG_ITALIAN =0x0410, + STBTT_MS_LANG_CHINESE =0x0804, STBTT_MS_LANG_JAPANESE =0x0411, + STBTT_MS_LANG_DUTCH =0x0413, STBTT_MS_LANG_KOREAN =0x0412, + STBTT_MS_LANG_FRENCH =0x040c, STBTT_MS_LANG_RUSSIAN =0x0419, + STBTT_MS_LANG_GERMAN =0x0407, STBTT_MS_LANG_SPANISH =0x0409, + STBTT_MS_LANG_HEBREW =0x040d, STBTT_MS_LANG_SWEDISH =0x041D +}; + +enum { /* languageID for STBTT_PLATFORM_ID_MAC */ + STBTT_MAC_LANG_ENGLISH =0 , STBTT_MAC_LANG_JAPANESE =11, + STBTT_MAC_LANG_ARABIC =12, STBTT_MAC_LANG_KOREAN =23, + STBTT_MAC_LANG_DUTCH =4 , STBTT_MAC_LANG_RUSSIAN =32, + STBTT_MAC_LANG_FRENCH =1 , STBTT_MAC_LANG_SPANISH =6 , + STBTT_MAC_LANG_GERMAN =2 , STBTT_MAC_LANG_SWEDISH =5 , + STBTT_MAC_LANG_HEBREW =10, STBTT_MAC_LANG_CHINESE_SIMPLIFIED =33, + STBTT_MAC_LANG_ITALIAN =3 , STBTT_MAC_LANG_CHINESE_TRAD =19 +}; + +#ifdef __cplusplus +} +#endif + +#endif /* __STB_INCLUDE_STB_TRUETYPE_H__ */ + +/* ///////////////////////////////////////////////////////////////////////////// */ +/* ///////////////////////////////////////////////////////////////////////////// */ +/* // */ +/* // IMPLEMENTATION */ +/* // */ +/* // */ + +#ifdef STB_TRUETYPE_IMPLEMENTATION + +#ifndef STBTT_MAX_OVERSAMPLE +#define STBTT_MAX_OVERSAMPLE 8 +#endif + +#if STBTT_MAX_OVERSAMPLE > 255 +#error "STBTT_MAX_OVERSAMPLE cannot be > 255" +#endif + +typedef int stbtt__test_oversample_pow2[(STBTT_MAX_OVERSAMPLE & (STBTT_MAX_OVERSAMPLE-1)) == 0 ? 1 : -1]; + +#ifndef STBTT_RASTERIZER_VERSION +#define STBTT_RASTERIZER_VERSION 2 +#endif + +#ifdef _MSC_VER +#define STBTT__NOTUSED(v) (void)(v) +#else +#define STBTT__NOTUSED(v) (void)sizeof(v) +#endif + +/* //////////////////////////////////////////////////////////////////////// */ +/* */ +/* stbtt__buf helpers to parse data from file */ +/* */ + +static stbtt_uint8 stbtt__buf_get8(stbtt__buf *b) +{ + if (b->cursor >= b->size) + return 0; + return b->data[b->cursor++]; +} + +static stbtt_uint8 stbtt__buf_peek8(stbtt__buf *b) +{ + if (b->cursor >= b->size) + return 0; + return b->data[b->cursor]; +} + +static void stbtt__buf_seek(stbtt__buf *b, int o) +{ + STBTT_assert(!(o > b->size || o < 0)); + b->cursor = (o > b->size || o < 0) ? b->size : o; +} + +static void stbtt__buf_skip(stbtt__buf *b, int o) +{ + stbtt__buf_seek(b, b->cursor + o); +} + +static stbtt_uint32 stbtt__buf_get(stbtt__buf *b, int n) +{ + stbtt_uint32 v = 0; + int i; + STBTT_assert(n >= 1 && n <= 4); + for (i = 0; i < n; i++) + v = (v << 8) | stbtt__buf_get8(b); + return v; +} + +static stbtt__buf stbtt__new_buf(const void *p, size_t size) +{ + stbtt__buf r; + STBTT_assert(size < 0x40000000); + r.data = (stbtt_uint8*) p; + r.size = (int) size; + r.cursor = 0; + return r; +} + +#define stbtt__buf_get16(b) stbtt__buf_get((b), 2) +#define stbtt__buf_get32(b) stbtt__buf_get((b), 4) + +static stbtt__buf stbtt__buf_range(const stbtt__buf *b, int o, int s) +{ + stbtt__buf r = stbtt__new_buf(NULL, 0); + if (o < 0 || s < 0 || o > b->size || s > b->size - o) return r; + r.data = b->data + o; + r.size = s; + return r; +} + +static stbtt__buf stbtt__cff_get_index(stbtt__buf *b) +{ + int count, start, offsize; + start = b->cursor; + count = stbtt__buf_get16(b); + if (count) { + offsize = stbtt__buf_get8(b); + STBTT_assert(offsize >= 1 && offsize <= 4); + stbtt__buf_skip(b, offsize * count); + stbtt__buf_skip(b, stbtt__buf_get(b, offsize) - 1); + } + return stbtt__buf_range(b, start, b->cursor - start); +} + +static stbtt_uint32 stbtt__cff_int(stbtt__buf *b) +{ + int b0 = stbtt__buf_get8(b); + if (b0 >= 32 && b0 <= 246) return b0 - 139; + else if (b0 >= 247 && b0 <= 250) return (b0 - 247)*256 + stbtt__buf_get8(b) + 108; + else if (b0 >= 251 && b0 <= 254) return -(b0 - 251)*256 - stbtt__buf_get8(b) - 108; + else if (b0 == 28) return stbtt__buf_get16(b); + else if (b0 == 29) return stbtt__buf_get32(b); + STBTT_assert(0); + return 0; +} + +static void stbtt__cff_skip_operand(stbtt__buf *b) { + int v, b0 = stbtt__buf_peek8(b); + STBTT_assert(b0 >= 28); + if (b0 == 30) { + stbtt__buf_skip(b, 1); + while (b->cursor < b->size) { + v = stbtt__buf_get8(b); + if ((v & 0xF) == 0xF || (v >> 4) == 0xF) + break; + } + } else { + stbtt__cff_int(b); + } +} + +static stbtt__buf stbtt__dict_get(stbtt__buf *b, int key) +{ + stbtt__buf_seek(b, 0); + while (b->cursor < b->size) { + int start = b->cursor, end, op; + while (stbtt__buf_peek8(b) >= 28) + stbtt__cff_skip_operand(b); + end = b->cursor; + op = stbtt__buf_get8(b); + if (op == 12) op = stbtt__buf_get8(b) | 0x100; + if (op == key) return stbtt__buf_range(b, start, end-start); + } + return stbtt__buf_range(b, 0, 0); +} + +static void stbtt__dict_get_ints(stbtt__buf *b, int key, int outcount, stbtt_uint32 *out) +{ + int i; + stbtt__buf operands = stbtt__dict_get(b, key); + for (i = 0; i < outcount && operands.cursor < operands.size; i++) + out[i] = stbtt__cff_int(&operands); +} + +static int stbtt__cff_index_count(stbtt__buf *b) +{ + stbtt__buf_seek(b, 0); + return stbtt__buf_get16(b); +} + +static stbtt__buf stbtt__cff_index_get(stbtt__buf b, int i) +{ + int count, offsize, start, end; + stbtt__buf_seek(&b, 0); + count = stbtt__buf_get16(&b); + offsize = stbtt__buf_get8(&b); + STBTT_assert(i >= 0 && i < count); + STBTT_assert(offsize >= 1 && offsize <= 4); + stbtt__buf_skip(&b, i*offsize); + start = stbtt__buf_get(&b, offsize); + end = stbtt__buf_get(&b, offsize); + return stbtt__buf_range(&b, 2+(count+1)*offsize+start, end - start); +} + +/* //////////////////////////////////////////////////////////////////////// */ +/* */ +/* accessors to parse data from file */ +/* */ + +/* on platforms that don't allow misaligned reads, if we want to allow */ +/* truetype fonts that aren't padded to alignment, define ALLOW_UNALIGNED_TRUETYPE */ + +#define ttBYTE(p) (* (stbtt_uint8 *) (p)) +#define ttCHAR(p) (* (stbtt_int8 *) (p)) +#define ttFixed(p) ttLONG(p) + +static stbtt_uint16 ttUSHORT(stbtt_uint8 *p) { return p[0]*256 + p[1]; } +static stbtt_int16 ttSHORT(stbtt_uint8 *p) { return p[0]*256 + p[1]; } +static stbtt_uint32 ttULONG(stbtt_uint8 *p) { return (p[0]<<24) + (p[1]<<16) + (p[2]<<8) + p[3]; } +static stbtt_int32 ttLONG(stbtt_uint8 *p) { return (p[0]<<24) + (p[1]<<16) + (p[2]<<8) + p[3]; } + +#define stbtt_tag4(p,c0,c1,c2,c3) ((p)[0] == (c0) && (p)[1] == (c1) && (p)[2] == (c2) && (p)[3] == (c3)) +#define stbtt_tag(p,str) stbtt_tag4(p,str[0],str[1],str[2],str[3]) + +static int stbtt__isfont(stbtt_uint8 *font) +{ + /* check the version number */ + if (stbtt_tag4(font, '1',0,0,0)) return 1; /* TrueType 1 */ + if (stbtt_tag(font, "typ1")) return 1; /* TrueType with type 1 font -- we don't support this! */ + if (stbtt_tag(font, "OTTO")) return 1; /* OpenType with CFF */ + if (stbtt_tag4(font, 0,1,0,0)) return 1; /* OpenType 1.0 */ + if (stbtt_tag(font, "true")) return 1; /* Apple specification for TrueType fonts */ + return 0; +} + +/* @OPTIMIZE: binary search */ +static stbtt_uint32 stbtt__find_table(stbtt_uint8 *data, stbtt_uint32 fontstart, const char *tag) +{ + stbtt_int32 num_tables = ttUSHORT(data+fontstart+4); + stbtt_uint32 tabledir = fontstart + 12; + stbtt_int32 i; + for (i=0; i < num_tables; ++i) { + stbtt_uint32 loc = tabledir + 16*i; + if (stbtt_tag(data+loc+0, tag)) + return ttULONG(data+loc+8); + } + return 0; +} + +static int stbtt_GetFontOffsetForIndex_internal(unsigned char *font_collection, int index) +{ + /* if it's just a font, there's only one valid index */ + if (stbtt__isfont(font_collection)) + return index == 0 ? 0 : -1; + + /* check if it's a TTC */ + if (stbtt_tag(font_collection, "ttcf")) { + /* version 1? */ + if (ttULONG(font_collection+4) == 0x00010000 || ttULONG(font_collection+4) == 0x00020000) { + stbtt_int32 n = ttLONG(font_collection+8); + if (index >= n) + return -1; + return ttULONG(font_collection+12+index*4); + } + } + return -1; +} + +static int stbtt_GetNumberOfFonts_internal(unsigned char *font_collection) +{ + /* if it's just a font, there's only one valid font */ + if (stbtt__isfont(font_collection)) + return 1; + + /* check if it's a TTC */ + if (stbtt_tag(font_collection, "ttcf")) { + /* version 1? */ + if (ttULONG(font_collection+4) == 0x00010000 || ttULONG(font_collection+4) == 0x00020000) { + return ttLONG(font_collection+8); + } + } + return 0; +} + +static stbtt__buf stbtt__get_subrs(stbtt__buf cff, stbtt__buf fontdict) +{ + stbtt_uint32 subrsoff = 0, private_loc[2] = { 0, 0 }; + stbtt__buf pdict; + stbtt__dict_get_ints(&fontdict, 18, 2, private_loc); + if (!private_loc[1] || !private_loc[0]) return stbtt__new_buf(NULL, 0); + pdict = stbtt__buf_range(&cff, private_loc[1], private_loc[0]); + stbtt__dict_get_ints(&pdict, 19, 1, &subrsoff); + if (!subrsoff) return stbtt__new_buf(NULL, 0); + stbtt__buf_seek(&cff, private_loc[1]+subrsoff); + return stbtt__cff_get_index(&cff); +} + +/* since most people won't use this, find this table the first time it's needed */ +static int stbtt__get_svg(stbtt_fontinfo *info) +{ + stbtt_uint32 t; + if (info->svg < 0) { + t = stbtt__find_table(info->data, info->fontstart, "SVG "); + if (t) { + stbtt_uint32 offset = ttULONG(info->data + t + 2); + info->svg = t + offset; + } else { + info->svg = 0; + } + } + return info->svg; +} + +static int stbtt_InitFont_internal(stbtt_fontinfo *info, unsigned char *data, int fontstart) +{ + stbtt_uint32 cmap, t; + stbtt_int32 i,numTables; + + info->data = data; + info->fontstart = fontstart; + info->cff = stbtt__new_buf(NULL, 0); + + cmap = stbtt__find_table(data, fontstart, "cmap"); /* required */ + info->loca = stbtt__find_table(data, fontstart, "loca"); /* required */ + info->head = stbtt__find_table(data, fontstart, "head"); /* required */ + info->glyf = stbtt__find_table(data, fontstart, "glyf"); /* required */ + info->hhea = stbtt__find_table(data, fontstart, "hhea"); /* required */ + info->hmtx = stbtt__find_table(data, fontstart, "hmtx"); /* required */ + info->kern = stbtt__find_table(data, fontstart, "kern"); /* not required */ + info->gpos = stbtt__find_table(data, fontstart, "GPOS"); /* not required */ + + if (!cmap || !info->head || !info->hhea || !info->hmtx) + return 0; + if (info->glyf) { + /* required for truetype */ + if (!info->loca) return 0; + } else { + /* initialization for CFF / Type2 fonts (OTF) */ + stbtt__buf b, topdict, topdictidx; + stbtt_uint32 cstype = 2, charstrings = 0, fdarrayoff = 0, fdselectoff = 0; + stbtt_uint32 cff; + + cff = stbtt__find_table(data, fontstart, "CFF "); + if (!cff) return 0; + + info->fontdicts = stbtt__new_buf(NULL, 0); + info->fdselect = stbtt__new_buf(NULL, 0); + + /* @TODO this should use size from table (not 512MB) */ + info->cff = stbtt__new_buf(data+cff, 512*1024*1024); + b = info->cff; + + /* read the header */ + stbtt__buf_skip(&b, 2); + stbtt__buf_seek(&b, stbtt__buf_get8(&b)); /* hdrsize */ + + /* @TODO the name INDEX could list multiple fonts, */ + /* but we just use the first one. */ + stbtt__cff_get_index(&b); /* name INDEX */ + topdictidx = stbtt__cff_get_index(&b); + topdict = stbtt__cff_index_get(topdictidx, 0); + stbtt__cff_get_index(&b); /* string INDEX */ + info->gsubrs = stbtt__cff_get_index(&b); + + stbtt__dict_get_ints(&topdict, 17, 1, &charstrings); + stbtt__dict_get_ints(&topdict, 0x100 | 6, 1, &cstype); + stbtt__dict_get_ints(&topdict, 0x100 | 36, 1, &fdarrayoff); + stbtt__dict_get_ints(&topdict, 0x100 | 37, 1, &fdselectoff); + info->subrs = stbtt__get_subrs(b, topdict); + + /* we only support Type 2 charstrings */ + if (cstype != 2) return 0; + if (charstrings == 0) return 0; + + if (fdarrayoff) { + /* looks like a CID font */ + if (!fdselectoff) return 0; + stbtt__buf_seek(&b, fdarrayoff); + info->fontdicts = stbtt__cff_get_index(&b); + info->fdselect = stbtt__buf_range(&b, fdselectoff, b.size-fdselectoff); + } + + stbtt__buf_seek(&b, charstrings); + info->charstrings = stbtt__cff_get_index(&b); + } + + t = stbtt__find_table(data, fontstart, "maxp"); + if (t) + info->numGlyphs = ttUSHORT(data+t+4); + else + info->numGlyphs = 0xffff; + + info->svg = -1; + + /* find a cmap encoding table we understand *now* to avoid searching */ + /* later. (todo: could make this installable) */ + /* the same regardless of glyph. */ + numTables = ttUSHORT(data + cmap + 2); + info->index_map = 0; + for (i=0; i < numTables; ++i) { + stbtt_uint32 encoding_record = cmap + 4 + 8 * i; + /* find an encoding we understand: */ + switch(ttUSHORT(data+encoding_record)) { + case STBTT_PLATFORM_ID_MICROSOFT: + switch (ttUSHORT(data+encoding_record+2)) { + case STBTT_MS_EID_UNICODE_BMP: + case STBTT_MS_EID_UNICODE_FULL: + /* MS/Unicode */ + info->index_map = cmap + ttULONG(data+encoding_record+4); + break; + } + break; + case STBTT_PLATFORM_ID_UNICODE: + /* Mac/iOS has these */ + /* all the encodingIDs are unicode, so we don't bother to check it */ + info->index_map = cmap + ttULONG(data+encoding_record+4); + break; + } + } + if (info->index_map == 0) + return 0; + + info->indexToLocFormat = ttUSHORT(data+info->head + 50); + return 1; +} + +STBTT_DEF int stbtt_FindGlyphIndex(const stbtt_fontinfo *info, int unicode_codepoint) +{ + stbtt_uint8 *data = info->data; + stbtt_uint32 index_map = info->index_map; + + stbtt_uint16 format = ttUSHORT(data + index_map + 0); + if (format == 0) { /* apple byte encoding */ + stbtt_int32 bytes = ttUSHORT(data + index_map + 2); + if (unicode_codepoint < bytes-6) + return ttBYTE(data + index_map + 6 + unicode_codepoint); + return 0; + } else if (format == 6) { + stbtt_uint32 first = ttUSHORT(data + index_map + 6); + stbtt_uint32 count = ttUSHORT(data + index_map + 8); + if ((stbtt_uint32) unicode_codepoint >= first && (stbtt_uint32) unicode_codepoint < first+count) + return ttUSHORT(data + index_map + 10 + (unicode_codepoint - first)*2); + return 0; + } else if (format == 2) { + STBTT_assert(0); /* @TODO: high-byte mapping for japanese/chinese/korean */ + return 0; + } else if (format == 4) { /* standard mapping for windows fonts: binary search collection of ranges */ + stbtt_uint16 segcount = ttUSHORT(data+index_map+6) >> 1; + stbtt_uint16 searchRange = ttUSHORT(data+index_map+8) >> 1; + stbtt_uint16 entrySelector = ttUSHORT(data+index_map+10); + stbtt_uint16 rangeShift = ttUSHORT(data+index_map+12) >> 1; + + /* do a binary search of the segments */ + stbtt_uint32 endCount = index_map + 14; + stbtt_uint32 search = endCount; + + if (unicode_codepoint > 0xffff) + return 0; + + /* they lie from endCount .. endCount + segCount */ + /* but searchRange is the nearest power of two, so... */ + if (unicode_codepoint >= ttUSHORT(data + search + rangeShift*2)) + search += rangeShift*2; + + /* now decrement to bias correctly to find smallest */ + search -= 2; + while (entrySelector) { + stbtt_uint16 end; + searchRange >>= 1; + end = ttUSHORT(data + search + searchRange*2); + if (unicode_codepoint > end) + search += searchRange*2; + --entrySelector; + } + search += 2; + + { + stbtt_uint16 offset, start, last; + stbtt_uint16 item = (stbtt_uint16) ((search - endCount) >> 1); + + start = ttUSHORT(data + index_map + 14 + segcount*2 + 2 + 2*item); + last = ttUSHORT(data + endCount + 2*item); + if (unicode_codepoint < start || unicode_codepoint > last) + return 0; + + offset = ttUSHORT(data + index_map + 14 + segcount*6 + 2 + 2*item); + if (offset == 0) + return (stbtt_uint16) (unicode_codepoint + ttSHORT(data + index_map + 14 + segcount*4 + 2 + 2*item)); + + return ttUSHORT(data + offset + (unicode_codepoint-start)*2 + index_map + 14 + segcount*6 + 2 + 2*item); + } + } else if (format == 12 || format == 13) { + stbtt_uint32 ngroups = ttULONG(data+index_map+12); + stbtt_int32 low,high; + low = 0; high = (stbtt_int32)ngroups; + /* Binary search the right group. */ + while (low < high) { + stbtt_int32 mid = low + ((high-low) >> 1); /* rounds down, so low <= mid < high */ + stbtt_uint32 start_char = ttULONG(data+index_map+16+mid*12); + stbtt_uint32 end_char = ttULONG(data+index_map+16+mid*12+4); + if ((stbtt_uint32) unicode_codepoint < start_char) + high = mid; + else if ((stbtt_uint32) unicode_codepoint > end_char) + low = mid+1; + else { + stbtt_uint32 start_glyph = ttULONG(data+index_map+16+mid*12+8); + if (format == 12) + return start_glyph + unicode_codepoint-start_char; + else /* format == 13 */ + return start_glyph; + } + } + return 0; /* not found */ + } + /* @TODO */ + STBTT_assert(0); + return 0; +} + +STBTT_DEF int stbtt_GetCodepointShape(const stbtt_fontinfo *info, int unicode_codepoint, stbtt_vertex **vertices) +{ + return stbtt_GetGlyphShape(info, stbtt_FindGlyphIndex(info, unicode_codepoint), vertices); +} + +static void stbtt_setvertex(stbtt_vertex *v, stbtt_uint8 type, stbtt_int32 x, stbtt_int32 y, stbtt_int32 cx, stbtt_int32 cy) +{ + v->type = type; + v->x = (stbtt_int16) x; + v->y = (stbtt_int16) y; + v->cx = (stbtt_int16) cx; + v->cy = (stbtt_int16) cy; +} + +static int stbtt__GetGlyfOffset(const stbtt_fontinfo *info, int glyph_index) +{ + int g1,g2; + + STBTT_assert(!info->cff.size); + + if (glyph_index >= info->numGlyphs) return -1; /* glyph index out of range */ + if (info->indexToLocFormat >= 2) return -1; /* unknown index->glyph map format */ + + if (info->indexToLocFormat == 0) { + g1 = info->glyf + ttUSHORT(info->data + info->loca + glyph_index * 2) * 2; + g2 = info->glyf + ttUSHORT(info->data + info->loca + glyph_index * 2 + 2) * 2; + } else { + g1 = info->glyf + ttULONG (info->data + info->loca + glyph_index * 4); + g2 = info->glyf + ttULONG (info->data + info->loca + glyph_index * 4 + 4); + } + + return g1==g2 ? -1 : g1; /* if length is 0, return -1 */ +} + +static int stbtt__GetGlyphInfoT2(const stbtt_fontinfo *info, int glyph_index, int *x0, int *y0, int *x1, int *y1); + +STBTT_DEF int stbtt_GetGlyphBox(const stbtt_fontinfo *info, int glyph_index, int *x0, int *y0, int *x1, int *y1) +{ + if (info->cff.size) { + stbtt__GetGlyphInfoT2(info, glyph_index, x0, y0, x1, y1); + } else { + int g = stbtt__GetGlyfOffset(info, glyph_index); + if (g < 0) return 0; + + if (x0) *x0 = ttSHORT(info->data + g + 2); + if (y0) *y0 = ttSHORT(info->data + g + 4); + if (x1) *x1 = ttSHORT(info->data + g + 6); + if (y1) *y1 = ttSHORT(info->data + g + 8); + } + return 1; +} + +STBTT_DEF int stbtt_GetCodepointBox(const stbtt_fontinfo *info, int codepoint, int *x0, int *y0, int *x1, int *y1) +{ + return stbtt_GetGlyphBox(info, stbtt_FindGlyphIndex(info,codepoint), x0,y0,x1,y1); +} + +STBTT_DEF int stbtt_IsGlyphEmpty(const stbtt_fontinfo *info, int glyph_index) +{ + stbtt_int16 numberOfContours; + int g; + if (info->cff.size) + return stbtt__GetGlyphInfoT2(info, glyph_index, NULL, NULL, NULL, NULL) == 0; + g = stbtt__GetGlyfOffset(info, glyph_index); + if (g < 0) return 1; + numberOfContours = ttSHORT(info->data + g); + return numberOfContours == 0; +} + +static int stbtt__close_shape(stbtt_vertex *vertices, int num_vertices, int was_off, int start_off, + stbtt_int32 sx, stbtt_int32 sy, stbtt_int32 scx, stbtt_int32 scy, stbtt_int32 cx, stbtt_int32 cy) +{ + if (start_off) { + if (was_off) + stbtt_setvertex(&vertices[num_vertices++], STBTT_vcurve, (cx+scx)>>1, (cy+scy)>>1, cx,cy); + stbtt_setvertex(&vertices[num_vertices++], STBTT_vcurve, sx,sy,scx,scy); + } else { + if (was_off) + stbtt_setvertex(&vertices[num_vertices++], STBTT_vcurve,sx,sy,cx,cy); + else + stbtt_setvertex(&vertices[num_vertices++], STBTT_vline,sx,sy,0,0); + } + return num_vertices; +} + +static int stbtt__GetGlyphShapeTT(const stbtt_fontinfo *info, int glyph_index, stbtt_vertex **pvertices) +{ + stbtt_int16 numberOfContours; + stbtt_uint8 *endPtsOfContours; + stbtt_uint8 *data = info->data; + stbtt_vertex *vertices=0; + int num_vertices=0; + int g = stbtt__GetGlyfOffset(info, glyph_index); + + *pvertices = NULL; + + if (g < 0) return 0; + + numberOfContours = ttSHORT(data + g); + + if (numberOfContours > 0) { + stbtt_uint8 flags=0,flagcount; + stbtt_int32 ins, i,j=0,m,n, next_move, was_off=0, off, start_off=0; + stbtt_int32 x,y,cx,cy,sx,sy, scx,scy; + stbtt_uint8 *points; + endPtsOfContours = (data + g + 10); + ins = ttUSHORT(data + g + 10 + numberOfContours * 2); + points = data + g + 10 + numberOfContours * 2 + 2 + ins; + + n = 1+ttUSHORT(endPtsOfContours + numberOfContours*2-2); + + m = n + 2*numberOfContours; /* a loose bound on how many vertices we might need */ + vertices = (stbtt_vertex *) STBTT_malloc(m * sizeof(vertices[0]), info->userdata); + if (vertices == 0) + return 0; + + next_move = 0; + flagcount=0; + + /* in first pass, we load uninterpreted data into the allocated array */ + /* above, shifted to the end of the array so we won't overwrite it when */ + /* we create our final data starting from the front */ + + off = m - n; /* starting offset for uninterpreted data, regardless of how m ends up being calculated */ + + /* first load flags */ + + for (i=0; i < n; ++i) { + if (flagcount == 0) { + flags = *points++; + if (flags & 8) + flagcount = *points++; + } else + --flagcount; + vertices[off+i].type = flags; + } + + /* now load x coordinates */ + x=0; + for (i=0; i < n; ++i) { + flags = vertices[off+i].type; + if (flags & 2) { + stbtt_int16 dx = *points++; + x += (flags & 16) ? dx : -dx; /* ??? */ + } else { + if (!(flags & 16)) { + x = x + (stbtt_int16) (points[0]*256 + points[1]); + points += 2; + } + } + vertices[off+i].x = (stbtt_int16) x; + } + + /* now load y coordinates */ + y=0; + for (i=0; i < n; ++i) { + flags = vertices[off+i].type; + if (flags & 4) { + stbtt_int16 dy = *points++; + y += (flags & 32) ? dy : -dy; /* ??? */ + } else { + if (!(flags & 32)) { + y = y + (stbtt_int16) (points[0]*256 + points[1]); + points += 2; + } + } + vertices[off+i].y = (stbtt_int16) y; + } + + /* now convert them to our format */ + num_vertices=0; + sx = sy = cx = cy = scx = scy = 0; + for (i=0; i < n; ++i) { + flags = vertices[off+i].type; + x = (stbtt_int16) vertices[off+i].x; + y = (stbtt_int16) vertices[off+i].y; + + if (next_move == i) { + if (i != 0) + num_vertices = stbtt__close_shape(vertices, num_vertices, was_off, start_off, sx,sy,scx,scy,cx,cy); + + /* now start the new one */ + start_off = !(flags & 1); + if (start_off) { + /* if we start off with an off-curve point, then when we need to find a point on the curve */ + /* where we can start, and we need to save some state for when we wraparound. */ + scx = x; + scy = y; + if (!(vertices[off+i+1].type & 1)) { + /* next point is also a curve point, so interpolate an on-point curve */ + sx = (x + (stbtt_int32) vertices[off+i+1].x) >> 1; + sy = (y + (stbtt_int32) vertices[off+i+1].y) >> 1; + } else { + /* otherwise just use the next point as our start point */ + sx = (stbtt_int32) vertices[off+i+1].x; + sy = (stbtt_int32) vertices[off+i+1].y; + ++i; /* we're using point i+1 as the starting point, so skip it */ + } + } else { + sx = x; + sy = y; + } + stbtt_setvertex(&vertices[num_vertices++], STBTT_vmove,sx,sy,0,0); + was_off = 0; + next_move = 1 + ttUSHORT(endPtsOfContours+j*2); + ++j; + } else { + if (!(flags & 1)) { /* if it's a curve */ + if (was_off) /* two off-curve control points in a row means interpolate an on-curve midpoint */ + stbtt_setvertex(&vertices[num_vertices++], STBTT_vcurve, (cx+x)>>1, (cy+y)>>1, cx, cy); + cx = x; + cy = y; + was_off = 1; + } else { + if (was_off) + stbtt_setvertex(&vertices[num_vertices++], STBTT_vcurve, x,y, cx, cy); + else + stbtt_setvertex(&vertices[num_vertices++], STBTT_vline, x,y,0,0); + was_off = 0; + } + } + } + num_vertices = stbtt__close_shape(vertices, num_vertices, was_off, start_off, sx,sy,scx,scy,cx,cy); + } else if (numberOfContours < 0) { + /* Compound shapes. */ + int more = 1; + stbtt_uint8 *comp = data + g + 10; + num_vertices = 0; + vertices = 0; + while (more) { + stbtt_uint16 flags, gidx; + int comp_num_verts = 0, i; + stbtt_vertex *comp_verts = 0, *tmp = 0; + float mtx[6] = {1,0,0,1,0,0}, m, n; + + flags = ttSHORT(comp); comp+=2; + gidx = ttSHORT(comp); comp+=2; + + if (flags & 2) { /* XY values */ + if (flags & 1) { /* shorts */ + mtx[4] = ttSHORT(comp); comp+=2; + mtx[5] = ttSHORT(comp); comp+=2; + } else { + mtx[4] = ttCHAR(comp); comp+=1; + mtx[5] = ttCHAR(comp); comp+=1; + } + } + else { + /* @TODO handle matching point */ + STBTT_assert(0); + } + if (flags & (1<<3)) { /* WE_HAVE_A_SCALE */ + mtx[0] = mtx[3] = ttSHORT(comp)/16384.0f; comp+=2; + mtx[1] = mtx[2] = 0; + } else if (flags & (1<<6)) { /* WE_HAVE_AN_X_AND_YSCALE */ + mtx[0] = ttSHORT(comp)/16384.0f; comp+=2; + mtx[1] = mtx[2] = 0; + mtx[3] = ttSHORT(comp)/16384.0f; comp+=2; + } else if (flags & (1<<7)) { /* WE_HAVE_A_TWO_BY_TWO */ + mtx[0] = ttSHORT(comp)/16384.0f; comp+=2; + mtx[1] = ttSHORT(comp)/16384.0f; comp+=2; + mtx[2] = ttSHORT(comp)/16384.0f; comp+=2; + mtx[3] = ttSHORT(comp)/16384.0f; comp+=2; + } + + /* Find transformation scales. */ + m = (float) STBTT_sqrt(mtx[0]*mtx[0] + mtx[1]*mtx[1]); + n = (float) STBTT_sqrt(mtx[2]*mtx[2] + mtx[3]*mtx[3]); + + /* Get indexed glyph. */ + comp_num_verts = stbtt_GetGlyphShape(info, gidx, &comp_verts); + if (comp_num_verts > 0) { + /* Transform vertices. */ + for (i = 0; i < comp_num_verts; ++i) { + stbtt_vertex* v = &comp_verts[i]; + stbtt_vertex_type x,y; + x=v->x; y=v->y; + v->x = (stbtt_vertex_type)(m * (mtx[0]*x + mtx[2]*y + mtx[4])); + v->y = (stbtt_vertex_type)(n * (mtx[1]*x + mtx[3]*y + mtx[5])); + x=v->cx; y=v->cy; + v->cx = (stbtt_vertex_type)(m * (mtx[0]*x + mtx[2]*y + mtx[4])); + v->cy = (stbtt_vertex_type)(n * (mtx[1]*x + mtx[3]*y + mtx[5])); + } + /* Append vertices. */ + tmp = (stbtt_vertex*)STBTT_malloc((num_vertices+comp_num_verts)*sizeof(stbtt_vertex), info->userdata); + if (!tmp) { + if (vertices) STBTT_free(vertices, info->userdata); + if (comp_verts) STBTT_free(comp_verts, info->userdata); + return 0; + } + if (num_vertices > 0 && vertices) STBTT_memcpy(tmp, vertices, num_vertices*sizeof(stbtt_vertex)); + STBTT_memcpy(tmp+num_vertices, comp_verts, comp_num_verts*sizeof(stbtt_vertex)); + if (vertices) STBTT_free(vertices, info->userdata); + vertices = tmp; + STBTT_free(comp_verts, info->userdata); + num_vertices += comp_num_verts; + } + /* More components ? */ + more = flags & (1<<5); + } + } else { + /* numberOfCounters == 0, do nothing */ + } + + *pvertices = vertices; + return num_vertices; +} + +typedef struct +{ + int bounds; + int started; + float first_x, first_y; + float x, y; + stbtt_int32 min_x, max_x, min_y, max_y; + + stbtt_vertex *pvertices; + int num_vertices; +} stbtt__csctx; + +#define STBTT__CSCTX_INIT(bounds) {bounds,0, 0,0, 0,0, 0,0,0,0, NULL, 0} + +static void stbtt__track_vertex(stbtt__csctx *c, stbtt_int32 x, stbtt_int32 y) +{ + if (x > c->max_x || !c->started) c->max_x = x; + if (y > c->max_y || !c->started) c->max_y = y; + if (x < c->min_x || !c->started) c->min_x = x; + if (y < c->min_y || !c->started) c->min_y = y; + c->started = 1; +} + +static void stbtt__csctx_v(stbtt__csctx *c, stbtt_uint8 type, stbtt_int32 x, stbtt_int32 y, stbtt_int32 cx, stbtt_int32 cy, stbtt_int32 cx1, stbtt_int32 cy1) +{ + if (c->bounds) { + stbtt__track_vertex(c, x, y); + if (type == STBTT_vcubic) { + stbtt__track_vertex(c, cx, cy); + stbtt__track_vertex(c, cx1, cy1); + } + } else { + stbtt_setvertex(&c->pvertices[c->num_vertices], type, x, y, cx, cy); + c->pvertices[c->num_vertices].cx1 = (stbtt_int16) cx1; + c->pvertices[c->num_vertices].cy1 = (stbtt_int16) cy1; + } + c->num_vertices++; +} + +static void stbtt__csctx_close_shape(stbtt__csctx *ctx) +{ + if (ctx->first_x != ctx->x || ctx->first_y != ctx->y) + stbtt__csctx_v(ctx, STBTT_vline, (int)ctx->first_x, (int)ctx->first_y, 0, 0, 0, 0); +} + +static void stbtt__csctx_rmove_to(stbtt__csctx *ctx, float dx, float dy) +{ + stbtt__csctx_close_shape(ctx); + ctx->first_x = ctx->x = ctx->x + dx; + ctx->first_y = ctx->y = ctx->y + dy; + stbtt__csctx_v(ctx, STBTT_vmove, (int)ctx->x, (int)ctx->y, 0, 0, 0, 0); +} + +static void stbtt__csctx_rline_to(stbtt__csctx *ctx, float dx, float dy) +{ + ctx->x += dx; + ctx->y += dy; + stbtt__csctx_v(ctx, STBTT_vline, (int)ctx->x, (int)ctx->y, 0, 0, 0, 0); +} + +static void stbtt__csctx_rccurve_to(stbtt__csctx *ctx, float dx1, float dy1, float dx2, float dy2, float dx3, float dy3) +{ + float cx1 = ctx->x + dx1; + float cy1 = ctx->y + dy1; + float cx2 = cx1 + dx2; + float cy2 = cy1 + dy2; + ctx->x = cx2 + dx3; + ctx->y = cy2 + dy3; + stbtt__csctx_v(ctx, STBTT_vcubic, (int)ctx->x, (int)ctx->y, (int)cx1, (int)cy1, (int)cx2, (int)cy2); +} + +static stbtt__buf stbtt__get_subr(stbtt__buf idx, int n) +{ + int count = stbtt__cff_index_count(&idx); + int bias = 107; + if (count >= 33900) + bias = 32768; + else if (count >= 1240) + bias = 1131; + n += bias; + if (n < 0 || n >= count) + return stbtt__new_buf(NULL, 0); + return stbtt__cff_index_get(idx, n); +} + +static stbtt__buf stbtt__cid_get_glyph_subrs(const stbtt_fontinfo *info, int glyph_index) +{ + stbtt__buf fdselect = info->fdselect; + int nranges, start, end, v, fmt, fdselector = -1, i; + + stbtt__buf_seek(&fdselect, 0); + fmt = stbtt__buf_get8(&fdselect); + if (fmt == 0) { + /* untested */ + stbtt__buf_skip(&fdselect, glyph_index); + fdselector = stbtt__buf_get8(&fdselect); + } else if (fmt == 3) { + nranges = stbtt__buf_get16(&fdselect); + start = stbtt__buf_get16(&fdselect); + for (i = 0; i < nranges; i++) { + v = stbtt__buf_get8(&fdselect); + end = stbtt__buf_get16(&fdselect); + if (glyph_index >= start && glyph_index < end) { + fdselector = v; + break; + } + start = end; + } + } + if (fdselector == -1) stbtt__new_buf(NULL, 0); + return stbtt__get_subrs(info->cff, stbtt__cff_index_get(info->fontdicts, fdselector)); +} + +static int stbtt__run_charstring(const stbtt_fontinfo *info, int glyph_index, stbtt__csctx *c) +{ + int in_header = 1, maskbits = 0, subr_stack_height = 0, sp = 0, v, i, b0; + int has_subrs = 0, clear_stack; + float s[48]; + stbtt__buf subr_stack[10], subrs = info->subrs, b; + float f; + +#define STBTT__CSERR(s) (0) + + /* this currently ignores the initial width value, which isn't needed if we have hmtx */ + b = stbtt__cff_index_get(info->charstrings, glyph_index); + while (b.cursor < b.size) { + i = 0; + clear_stack = 1; + b0 = stbtt__buf_get8(&b); + switch (b0) { + /* @TODO implement hinting */ + case 0x13: /* hintmask */ + case 0x14: /* cntrmask */ + if (in_header) + maskbits += (sp / 2); /* implicit "vstem" */ + in_header = 0; + stbtt__buf_skip(&b, (maskbits + 7) / 8); + break; + + case 0x01: /* hstem */ + case 0x03: /* vstem */ + case 0x12: /* hstemhm */ + case 0x17: /* vstemhm */ + maskbits += (sp / 2); + break; + + case 0x15: /* rmoveto */ + in_header = 0; + if (sp < 2) return STBTT__CSERR("rmoveto stack"); + stbtt__csctx_rmove_to(c, s[sp-2], s[sp-1]); + break; + case 0x04: /* vmoveto */ + in_header = 0; + if (sp < 1) return STBTT__CSERR("vmoveto stack"); + stbtt__csctx_rmove_to(c, 0, s[sp-1]); + break; + case 0x16: /* hmoveto */ + in_header = 0; + if (sp < 1) return STBTT__CSERR("hmoveto stack"); + stbtt__csctx_rmove_to(c, s[sp-1], 0); + break; + + case 0x05: /* rlineto */ + if (sp < 2) return STBTT__CSERR("rlineto stack"); + for (; i + 1 < sp; i += 2) + stbtt__csctx_rline_to(c, s[i], s[i+1]); + break; + + /* hlineto/vlineto and vhcurveto/hvcurveto alternate horizontal and vertical */ + /* starting from a different place. */ + + case 0x07: /* vlineto */ + if (sp < 1) return STBTT__CSERR("vlineto stack"); + goto vlineto; + case 0x06: /* hlineto */ + if (sp < 1) return STBTT__CSERR("hlineto stack"); + for (;;) { + if (i >= sp) break; + stbtt__csctx_rline_to(c, s[i], 0); + i++; + vlineto: + if (i >= sp) break; + stbtt__csctx_rline_to(c, 0, s[i]); + i++; + } + break; + + case 0x1F: /* hvcurveto */ + if (sp < 4) return STBTT__CSERR("hvcurveto stack"); + goto hvcurveto; + case 0x1E: /* vhcurveto */ + if (sp < 4) return STBTT__CSERR("vhcurveto stack"); + for (;;) { + if (i + 3 >= sp) break; + stbtt__csctx_rccurve_to(c, 0, s[i], s[i+1], s[i+2], s[i+3], (sp - i == 5) ? s[i + 4] : 0.0f); + i += 4; + hvcurveto: + if (i + 3 >= sp) break; + stbtt__csctx_rccurve_to(c, s[i], 0, s[i+1], s[i+2], (sp - i == 5) ? s[i+4] : 0.0f, s[i+3]); + i += 4; + } + break; + + case 0x08: /* rrcurveto */ + if (sp < 6) return STBTT__CSERR("rcurveline stack"); + for (; i + 5 < sp; i += 6) + stbtt__csctx_rccurve_to(c, s[i], s[i+1], s[i+2], s[i+3], s[i+4], s[i+5]); + break; + + case 0x18: /* rcurveline */ + if (sp < 8) return STBTT__CSERR("rcurveline stack"); + for (; i + 5 < sp - 2; i += 6) + stbtt__csctx_rccurve_to(c, s[i], s[i+1], s[i+2], s[i+3], s[i+4], s[i+5]); + if (i + 1 >= sp) return STBTT__CSERR("rcurveline stack"); + stbtt__csctx_rline_to(c, s[i], s[i+1]); + break; + + case 0x19: /* rlinecurve */ + if (sp < 8) return STBTT__CSERR("rlinecurve stack"); + for (; i + 1 < sp - 6; i += 2) + stbtt__csctx_rline_to(c, s[i], s[i+1]); + if (i + 5 >= sp) return STBTT__CSERR("rlinecurve stack"); + stbtt__csctx_rccurve_to(c, s[i], s[i+1], s[i+2], s[i+3], s[i+4], s[i+5]); + break; + + case 0x1A: /* vvcurveto */ + case 0x1B: /* hhcurveto */ + if (sp < 4) return STBTT__CSERR("(vv|hh)curveto stack"); + f = 0.0; + if (sp & 1) { f = s[i]; i++; } + for (; i + 3 < sp; i += 4) { + if (b0 == 0x1B) + stbtt__csctx_rccurve_to(c, s[i], f, s[i+1], s[i+2], s[i+3], 0.0); + else + stbtt__csctx_rccurve_to(c, f, s[i], s[i+1], s[i+2], 0.0, s[i+3]); + f = 0.0; + } + break; + + case 0x0A: /* callsubr */ + if (!has_subrs) { + if (info->fdselect.size) + subrs = stbtt__cid_get_glyph_subrs(info, glyph_index); + has_subrs = 1; + } + /* FALLTHROUGH */ + case 0x1D: /* callgsubr */ + if (sp < 1) return STBTT__CSERR("call(g|)subr stack"); + v = (int) s[--sp]; + if (subr_stack_height >= 10) return STBTT__CSERR("recursion limit"); + subr_stack[subr_stack_height++] = b; + b = stbtt__get_subr(b0 == 0x0A ? subrs : info->gsubrs, v); + if (b.size == 0) return STBTT__CSERR("subr not found"); + b.cursor = 0; + clear_stack = 0; + break; + + case 0x0B: /* return */ + if (subr_stack_height <= 0) return STBTT__CSERR("return outside subr"); + b = subr_stack[--subr_stack_height]; + clear_stack = 0; + break; + + case 0x0E: /* endchar */ + stbtt__csctx_close_shape(c); + return 1; + + case 0x0C: { /* two-byte escape */ + float dx1, dx2, dx3, dx4, dx5, dx6, dy1, dy2, dy3, dy4, dy5, dy6; + float dx, dy; + int b1 = stbtt__buf_get8(&b); + switch (b1) { + /* @TODO These "flex" implementations ignore the flex-depth and resolution, */ + /* and always draw beziers. */ + case 0x22: /* hflex */ + if (sp < 7) return STBTT__CSERR("hflex stack"); + dx1 = s[0]; + dx2 = s[1]; + dy2 = s[2]; + dx3 = s[3]; + dx4 = s[4]; + dx5 = s[5]; + dx6 = s[6]; + stbtt__csctx_rccurve_to(c, dx1, 0, dx2, dy2, dx3, 0); + stbtt__csctx_rccurve_to(c, dx4, 0, dx5, -dy2, dx6, 0); + break; + + case 0x23: /* flex */ + if (sp < 13) return STBTT__CSERR("flex stack"); + dx1 = s[0]; + dy1 = s[1]; + dx2 = s[2]; + dy2 = s[3]; + dx3 = s[4]; + dy3 = s[5]; + dx4 = s[6]; + dy4 = s[7]; + dx5 = s[8]; + dy5 = s[9]; + dx6 = s[10]; + dy6 = s[11]; + /* fd is s[12] */ + stbtt__csctx_rccurve_to(c, dx1, dy1, dx2, dy2, dx3, dy3); + stbtt__csctx_rccurve_to(c, dx4, dy4, dx5, dy5, dx6, dy6); + break; + + case 0x24: /* hflex1 */ + if (sp < 9) return STBTT__CSERR("hflex1 stack"); + dx1 = s[0]; + dy1 = s[1]; + dx2 = s[2]; + dy2 = s[3]; + dx3 = s[4]; + dx4 = s[5]; + dx5 = s[6]; + dy5 = s[7]; + dx6 = s[8]; + stbtt__csctx_rccurve_to(c, dx1, dy1, dx2, dy2, dx3, 0); + stbtt__csctx_rccurve_to(c, dx4, 0, dx5, dy5, dx6, -(dy1+dy2+dy5)); + break; + + case 0x25: /* flex1 */ + if (sp < 11) return STBTT__CSERR("flex1 stack"); + dx1 = s[0]; + dy1 = s[1]; + dx2 = s[2]; + dy2 = s[3]; + dx3 = s[4]; + dy3 = s[5]; + dx4 = s[6]; + dy4 = s[7]; + dx5 = s[8]; + dy5 = s[9]; + dx6 = dy6 = s[10]; + dx = dx1+dx2+dx3+dx4+dx5; + dy = dy1+dy2+dy3+dy4+dy5; + if (STBTT_fabs(dx) > STBTT_fabs(dy)) + dy6 = -dy; + else + dx6 = -dx; + stbtt__csctx_rccurve_to(c, dx1, dy1, dx2, dy2, dx3, dy3); + stbtt__csctx_rccurve_to(c, dx4, dy4, dx5, dy5, dx6, dy6); + break; + + default: + return STBTT__CSERR("unimplemented"); + } + } break; + + default: + if (b0 != 255 && b0 != 28 && b0 < 32) + return STBTT__CSERR("reserved operator"); + + /* push immediate */ + if (b0 == 255) { + f = (float)(stbtt_int32)stbtt__buf_get32(&b) / 0x10000; + } else { + stbtt__buf_skip(&b, -1); + f = (float)(stbtt_int16)stbtt__cff_int(&b); + } + if (sp >= 48) return STBTT__CSERR("push stack overflow"); + s[sp++] = f; + clear_stack = 0; + break; + } + if (clear_stack) sp = 0; + } + return STBTT__CSERR("no endchar"); + +#undef STBTT__CSERR +} + +static int stbtt__GetGlyphShapeT2(const stbtt_fontinfo *info, int glyph_index, stbtt_vertex **pvertices) +{ + /* runs the charstring twice, once to count and once to output (to avoid realloc) */ + stbtt__csctx count_ctx = STBTT__CSCTX_INIT(1); + stbtt__csctx output_ctx = STBTT__CSCTX_INIT(0); + if (stbtt__run_charstring(info, glyph_index, &count_ctx)) { + *pvertices = (stbtt_vertex*)STBTT_malloc(count_ctx.num_vertices*sizeof(stbtt_vertex), info->userdata); + output_ctx.pvertices = *pvertices; + if (stbtt__run_charstring(info, glyph_index, &output_ctx)) { + STBTT_assert(output_ctx.num_vertices == count_ctx.num_vertices); + return output_ctx.num_vertices; + } + } + *pvertices = NULL; + return 0; +} + +static int stbtt__GetGlyphInfoT2(const stbtt_fontinfo *info, int glyph_index, int *x0, int *y0, int *x1, int *y1) +{ + stbtt__csctx c = STBTT__CSCTX_INIT(1); + int r = stbtt__run_charstring(info, glyph_index, &c); + if (x0) *x0 = r ? c.min_x : 0; + if (y0) *y0 = r ? c.min_y : 0; + if (x1) *x1 = r ? c.max_x : 0; + if (y1) *y1 = r ? c.max_y : 0; + return r ? c.num_vertices : 0; +} + +STBTT_DEF int stbtt_GetGlyphShape(const stbtt_fontinfo *info, int glyph_index, stbtt_vertex **pvertices) +{ + if (!info->cff.size) + return stbtt__GetGlyphShapeTT(info, glyph_index, pvertices); + else + return stbtt__GetGlyphShapeT2(info, glyph_index, pvertices); +} + +STBTT_DEF void stbtt_GetGlyphHMetrics(const stbtt_fontinfo *info, int glyph_index, int *advanceWidth, int *leftSideBearing) +{ + stbtt_uint16 numOfLongHorMetrics = ttUSHORT(info->data+info->hhea + 34); + if (glyph_index < numOfLongHorMetrics) { + if (advanceWidth) *advanceWidth = ttSHORT(info->data + info->hmtx + 4*glyph_index); + if (leftSideBearing) *leftSideBearing = ttSHORT(info->data + info->hmtx + 4*glyph_index + 2); + } else { + if (advanceWidth) *advanceWidth = ttSHORT(info->data + info->hmtx + 4*(numOfLongHorMetrics-1)); + if (leftSideBearing) *leftSideBearing = ttSHORT(info->data + info->hmtx + 4*numOfLongHorMetrics + 2*(glyph_index - numOfLongHorMetrics)); + } +} + +STBTT_DEF int stbtt_GetKerningTableLength(const stbtt_fontinfo *info) +{ + stbtt_uint8 *data = info->data + info->kern; + + /* we only look at the first table. it must be 'horizontal' and format 0. */ + if (!info->kern) + return 0; + if (ttUSHORT(data+2) < 1) /* number of tables, need at least 1 */ + return 0; + if (ttUSHORT(data+8) != 1) /* horizontal flag must be set in format */ + return 0; + + return ttUSHORT(data+10); +} + +STBTT_DEF int stbtt_GetKerningTable(const stbtt_fontinfo *info, stbtt_kerningentry* table, int table_length) +{ + stbtt_uint8 *data = info->data + info->kern; + int k, length; + + /* we only look at the first table. it must be 'horizontal' and format 0. */ + if (!info->kern) + return 0; + if (ttUSHORT(data+2) < 1) /* number of tables, need at least 1 */ + return 0; + if (ttUSHORT(data+8) != 1) /* horizontal flag must be set in format */ + return 0; + + length = ttUSHORT(data+10); + if (table_length < length) + length = table_length; + + for (k = 0; k < length; k++) + { + table[k].glyph1 = ttUSHORT(data+18+(k*6)); + table[k].glyph2 = ttUSHORT(data+20+(k*6)); + table[k].advance = ttSHORT(data+22+(k*6)); + } + + return length; +} + +static int stbtt__GetGlyphKernInfoAdvance(const stbtt_fontinfo *info, int glyph1, int glyph2) +{ + stbtt_uint8 *data = info->data + info->kern; + stbtt_uint32 needle, straw; + int l, r, m; + + /* we only look at the first table. it must be 'horizontal' and format 0. */ + if (!info->kern) + return 0; + if (ttUSHORT(data+2) < 1) /* number of tables, need at least 1 */ + return 0; + if (ttUSHORT(data+8) != 1) /* horizontal flag must be set in format */ + return 0; + + l = 0; + r = ttUSHORT(data+10) - 1; + needle = glyph1 << 16 | glyph2; + while (l <= r) { + m = (l + r) >> 1; + straw = ttULONG(data+18+(m*6)); /* note: unaligned read */ + if (needle < straw) + r = m - 1; + else if (needle > straw) + l = m + 1; + else + return ttSHORT(data+22+(m*6)); + } + return 0; +} + +static stbtt_int32 stbtt__GetCoverageIndex(stbtt_uint8 *coverageTable, int glyph) +{ + stbtt_uint16 coverageFormat = ttUSHORT(coverageTable); + switch (coverageFormat) { + case 1: { + stbtt_uint16 glyphCount = ttUSHORT(coverageTable + 2); + + /* Binary search. */ + stbtt_int32 l=0, r=glyphCount-1, m; + int straw, needle=glyph; + while (l <= r) { + stbtt_uint8 *glyphArray = coverageTable + 4; + stbtt_uint16 glyphID; + m = (l + r) >> 1; + glyphID = ttUSHORT(glyphArray + 2 * m); + straw = glyphID; + if (needle < straw) + r = m - 1; + else if (needle > straw) + l = m + 1; + else { + return m; + } + } + break; + } + + case 2: { + stbtt_uint16 rangeCount = ttUSHORT(coverageTable + 2); + stbtt_uint8 *rangeArray = coverageTable + 4; + + /* Binary search. */ + stbtt_int32 l=0, r=rangeCount-1, m; + int strawStart, strawEnd, needle=glyph; + while (l <= r) { + stbtt_uint8 *rangeRecord; + m = (l + r) >> 1; + rangeRecord = rangeArray + 6 * m; + strawStart = ttUSHORT(rangeRecord); + strawEnd = ttUSHORT(rangeRecord + 2); + if (needle < strawStart) + r = m - 1; + else if (needle > strawEnd) + l = m + 1; + else { + stbtt_uint16 startCoverageIndex = ttUSHORT(rangeRecord + 4); + return startCoverageIndex + glyph - strawStart; + } + } + break; + } + + default: return -1; /* unsupported */ + } + + return -1; +} + +static stbtt_int32 stbtt__GetGlyphClass(stbtt_uint8 *classDefTable, int glyph) +{ + stbtt_uint16 classDefFormat = ttUSHORT(classDefTable); + switch (classDefFormat) + { + case 1: { + stbtt_uint16 startGlyphID = ttUSHORT(classDefTable + 2); + stbtt_uint16 glyphCount = ttUSHORT(classDefTable + 4); + stbtt_uint8 *classDef1ValueArray = classDefTable + 6; + + if (glyph >= startGlyphID && glyph < startGlyphID + glyphCount) + return (stbtt_int32)ttUSHORT(classDef1ValueArray + 2 * (glyph - startGlyphID)); + break; + } + + case 2: { + stbtt_uint16 classRangeCount = ttUSHORT(classDefTable + 2); + stbtt_uint8 *classRangeRecords = classDefTable + 4; + + /* Binary search. */ + stbtt_int32 l=0, r=classRangeCount-1, m; + int strawStart, strawEnd, needle=glyph; + while (l <= r) { + stbtt_uint8 *classRangeRecord; + m = (l + r) >> 1; + classRangeRecord = classRangeRecords + 6 * m; + strawStart = ttUSHORT(classRangeRecord); + strawEnd = ttUSHORT(classRangeRecord + 2); + if (needle < strawStart) + r = m - 1; + else if (needle > strawEnd) + l = m + 1; + else + return (stbtt_int32)ttUSHORT(classRangeRecord + 4); + } + break; + } + + default: + return -1; /* Unsupported definition type, return an error. */ + } + + /* "All glyphs not assigned to a class fall into class 0". (OpenType spec) */ + return 0; +} + +/* Define to STBTT_assert(x) if you want to break on unimplemented formats. */ +#define STBTT_GPOS_TODO_assert(x) + +static stbtt_int32 stbtt__GetGlyphGPOSInfoAdvance(const stbtt_fontinfo *info, int glyph1, int glyph2) +{ + stbtt_uint16 lookupListOffset; + stbtt_uint8 *lookupList; + stbtt_uint16 lookupCount; + stbtt_uint8 *data; + stbtt_int32 i, sti; + + if (!info->gpos) return 0; + + data = info->data + info->gpos; + + if (ttUSHORT(data+0) != 1) return 0; /* Major version 1 */ + if (ttUSHORT(data+2) != 0) return 0; /* Minor version 0 */ + + lookupListOffset = ttUSHORT(data+8); + lookupList = data + lookupListOffset; + lookupCount = ttUSHORT(lookupList); + + for (i=0; i= pairSetCount) return 0; + + needle=glyph2; + r=pairValueCount-1; + l=0; + + /* Binary search. */ + while (l <= r) { + stbtt_uint16 secondGlyph; + stbtt_uint8 *pairValue; + m = (l + r) >> 1; + pairValue = pairValueArray + (2 + valueRecordPairSizeInBytes) * m; + secondGlyph = ttUSHORT(pairValue); + straw = secondGlyph; + if (needle < straw) + r = m - 1; + else if (needle > straw) + l = m + 1; + else { + stbtt_int16 xAdvance = ttSHORT(pairValue + 2); + return xAdvance; + } + } + } else + return 0; + break; + } + + case 2: { + stbtt_uint16 valueFormat1 = ttUSHORT(table + 4); + stbtt_uint16 valueFormat2 = ttUSHORT(table + 6); + if (valueFormat1 == 4 && valueFormat2 == 0) { /* Support more formats? */ + stbtt_uint16 classDef1Offset = ttUSHORT(table + 8); + stbtt_uint16 classDef2Offset = ttUSHORT(table + 10); + int glyph1class = stbtt__GetGlyphClass(table + classDef1Offset, glyph1); + int glyph2class = stbtt__GetGlyphClass(table + classDef2Offset, glyph2); + + stbtt_uint16 class1Count = ttUSHORT(table + 12); + stbtt_uint16 class2Count = ttUSHORT(table + 14); + stbtt_uint8 *class1Records, *class2Records; + stbtt_int16 xAdvance; + + if (glyph1class < 0 || glyph1class >= class1Count) return 0; /* malformed */ + if (glyph2class < 0 || glyph2class >= class2Count) return 0; /* malformed */ + + class1Records = table + 16; + class2Records = class1Records + 2 * (glyph1class * class2Count); + xAdvance = ttSHORT(class2Records + 2 * glyph2class); + return xAdvance; + } else + return 0; + break; + } + + default: + return 0; /* Unsupported position format */ + } + } + } + + return 0; +} + +STBTT_DEF int stbtt_GetGlyphKernAdvance(const stbtt_fontinfo *info, int g1, int g2) +{ + int xAdvance = 0; + + if (info->gpos) + xAdvance += stbtt__GetGlyphGPOSInfoAdvance(info, g1, g2); + else if (info->kern) + xAdvance += stbtt__GetGlyphKernInfoAdvance(info, g1, g2); + + return xAdvance; +} + +STBTT_DEF int stbtt_GetCodepointKernAdvance(const stbtt_fontinfo *info, int ch1, int ch2) +{ + if (!info->kern && !info->gpos) /* if no kerning table, don't waste time looking up both codepoint->glyphs */ + return 0; + return stbtt_GetGlyphKernAdvance(info, stbtt_FindGlyphIndex(info,ch1), stbtt_FindGlyphIndex(info,ch2)); +} + +STBTT_DEF void stbtt_GetCodepointHMetrics(const stbtt_fontinfo *info, int codepoint, int *advanceWidth, int *leftSideBearing) +{ + stbtt_GetGlyphHMetrics(info, stbtt_FindGlyphIndex(info,codepoint), advanceWidth, leftSideBearing); +} + +STBTT_DEF void stbtt_GetFontVMetrics(const stbtt_fontinfo *info, int *ascent, int *descent, int *lineGap) +{ + if (ascent ) *ascent = ttSHORT(info->data+info->hhea + 4); + if (descent) *descent = ttSHORT(info->data+info->hhea + 6); + if (lineGap) *lineGap = ttSHORT(info->data+info->hhea + 8); +} + +STBTT_DEF int stbtt_GetFontVMetricsOS2(const stbtt_fontinfo *info, int *typoAscent, int *typoDescent, int *typoLineGap) +{ + int tab = stbtt__find_table(info->data, info->fontstart, "OS/2"); + if (!tab) + return 0; + if (typoAscent ) *typoAscent = ttSHORT(info->data+tab + 68); + if (typoDescent) *typoDescent = ttSHORT(info->data+tab + 70); + if (typoLineGap) *typoLineGap = ttSHORT(info->data+tab + 72); + return 1; +} + +STBTT_DEF void stbtt_GetFontBoundingBox(const stbtt_fontinfo *info, int *x0, int *y0, int *x1, int *y1) +{ + *x0 = ttSHORT(info->data + info->head + 36); + *y0 = ttSHORT(info->data + info->head + 38); + *x1 = ttSHORT(info->data + info->head + 40); + *y1 = ttSHORT(info->data + info->head + 42); +} + +STBTT_DEF float stbtt_ScaleForPixelHeight(const stbtt_fontinfo *info, float height) +{ + int fheight = ttSHORT(info->data + info->hhea + 4) - ttSHORT(info->data + info->hhea + 6); + return (float) height / fheight; +} + +STBTT_DEF float stbtt_ScaleForMappingEmToPixels(const stbtt_fontinfo *info, float pixels) +{ + int unitsPerEm = ttUSHORT(info->data + info->head + 18); + return pixels / unitsPerEm; +} + +STBTT_DEF void stbtt_FreeShape(const stbtt_fontinfo *info, stbtt_vertex *v) +{ + STBTT_free(v, info->userdata); +} + +STBTT_DEF stbtt_uint8 *stbtt_FindSVGDoc(const stbtt_fontinfo *info, int gl) +{ + int i; + stbtt_uint8 *data = info->data; + stbtt_uint8 *svg_doc_list = data + stbtt__get_svg((stbtt_fontinfo *) info); + + int numEntries = ttUSHORT(svg_doc_list); + stbtt_uint8 *svg_docs = svg_doc_list + 2; + + for(i=0; i= ttUSHORT(svg_doc)) && (gl <= ttUSHORT(svg_doc + 2))) + return svg_doc; + } + return 0; +} + +STBTT_DEF int stbtt_GetGlyphSVG(const stbtt_fontinfo *info, int gl, const char **svg) +{ + stbtt_uint8 *data = info->data; + stbtt_uint8 *svg_doc; + + if (info->svg == 0) + return 0; + + svg_doc = stbtt_FindSVGDoc(info, gl); + if (svg_doc != NULL) { + *svg = (char *) data + info->svg + ttULONG(svg_doc + 4); + return ttULONG(svg_doc + 8); + } else { + return 0; + } +} + +STBTT_DEF int stbtt_GetCodepointSVG(const stbtt_fontinfo *info, int unicode_codepoint, const char **svg) +{ + return stbtt_GetGlyphSVG(info, stbtt_FindGlyphIndex(info, unicode_codepoint), svg); +} + +/* //////////////////////////////////////////////////////////////////////////// */ +/* */ +/* antialiasing software rasterizer */ +/* */ + +STBTT_DEF void stbtt_GetGlyphBitmapBoxSubpixel(const stbtt_fontinfo *font, int glyph, float scale_x, float scale_y,float shift_x, float shift_y, int *ix0, int *iy0, int *ix1, int *iy1) +{ + int x0=0,y0=0,x1,y1; /* =0 suppresses compiler warning */ + if (!stbtt_GetGlyphBox(font, glyph, &x0,&y0,&x1,&y1)) { + /* e.g. space character */ + if (ix0) *ix0 = 0; + if (iy0) *iy0 = 0; + if (ix1) *ix1 = 0; + if (iy1) *iy1 = 0; + } else { + /* move to integral bboxes (treating pixels as little squares, what pixels get touched)? */ + if (ix0) *ix0 = STBTT_ifloor( x0 * scale_x + shift_x); + if (iy0) *iy0 = STBTT_ifloor(-y1 * scale_y + shift_y); + if (ix1) *ix1 = STBTT_iceil ( x1 * scale_x + shift_x); + if (iy1) *iy1 = STBTT_iceil (-y0 * scale_y + shift_y); + } +} + +STBTT_DEF void stbtt_GetGlyphBitmapBox(const stbtt_fontinfo *font, int glyph, float scale_x, float scale_y, int *ix0, int *iy0, int *ix1, int *iy1) +{ + stbtt_GetGlyphBitmapBoxSubpixel(font, glyph, scale_x, scale_y,0.0f,0.0f, ix0, iy0, ix1, iy1); +} + +STBTT_DEF void stbtt_GetCodepointBitmapBoxSubpixel(const stbtt_fontinfo *font, int codepoint, float scale_x, float scale_y, float shift_x, float shift_y, int *ix0, int *iy0, int *ix1, int *iy1) +{ + stbtt_GetGlyphBitmapBoxSubpixel(font, stbtt_FindGlyphIndex(font,codepoint), scale_x, scale_y,shift_x,shift_y, ix0,iy0,ix1,iy1); +} + +STBTT_DEF void stbtt_GetCodepointBitmapBox(const stbtt_fontinfo *font, int codepoint, float scale_x, float scale_y, int *ix0, int *iy0, int *ix1, int *iy1) +{ + stbtt_GetCodepointBitmapBoxSubpixel(font, codepoint, scale_x, scale_y,0.0f,0.0f, ix0,iy0,ix1,iy1); +} + +/* //////////////////////////////////////////////////////////////////////////// */ +/* */ +/* Rasterizer */ + +typedef struct stbtt__hheap_chunk +{ + struct stbtt__hheap_chunk *next; +} stbtt__hheap_chunk; + +typedef struct stbtt__hheap +{ + struct stbtt__hheap_chunk *head; + void *first_free; + int num_remaining_in_head_chunk; +} stbtt__hheap; + +static void *stbtt__hheap_alloc(stbtt__hheap *hh, size_t size, void *userdata) +{ + if (hh->first_free) { + void *p = hh->first_free; + hh->first_free = * (void **) p; + return p; + } else { + if (hh->num_remaining_in_head_chunk == 0) { + int count = (size < 32 ? 2000 : size < 128 ? 800 : 100); + stbtt__hheap_chunk *c = (stbtt__hheap_chunk *) STBTT_malloc(sizeof(stbtt__hheap_chunk) + size * count, userdata); + if (c == NULL) + return NULL; + c->next = hh->head; + hh->head = c; + hh->num_remaining_in_head_chunk = count; + } + --hh->num_remaining_in_head_chunk; + return (char *) (hh->head) + sizeof(stbtt__hheap_chunk) + size * hh->num_remaining_in_head_chunk; + } +} + +static void stbtt__hheap_free(stbtt__hheap *hh, void *p) +{ + *(void **) p = hh->first_free; + hh->first_free = p; +} + +static void stbtt__hheap_cleanup(stbtt__hheap *hh, void *userdata) +{ + stbtt__hheap_chunk *c = hh->head; + while (c) { + stbtt__hheap_chunk *n = c->next; + STBTT_free(c, userdata); + c = n; + } +} + +typedef struct stbtt__edge { + float x0,y0, x1,y1; + int invert; +} stbtt__edge; + + +typedef struct stbtt__active_edge +{ + struct stbtt__active_edge *next; + #if STBTT_RASTERIZER_VERSION==1 + int x,dx; + float ey; + int direction; + #elif STBTT_RASTERIZER_VERSION==2 + float fx,fdx,fdy; + float direction; + float sy; + float ey; + #else + #error "Unrecognized value of STBTT_RASTERIZER_VERSION" + #endif +} stbtt__active_edge; + +#if STBTT_RASTERIZER_VERSION == 1 +#define STBTT_FIXSHIFT 10 +#define STBTT_FIX (1 << STBTT_FIXSHIFT) +#define STBTT_FIXMASK (STBTT_FIX-1) + +static stbtt__active_edge *stbtt__new_active(stbtt__hheap *hh, stbtt__edge *e, int off_x, float start_point, void *userdata) +{ + stbtt__active_edge *z = (stbtt__active_edge *) stbtt__hheap_alloc(hh, sizeof(*z), userdata); + float dxdy = (e->x1 - e->x0) / (e->y1 - e->y0); + STBTT_assert(z != NULL); + if (!z) return z; + + /* round dx down to avoid overshooting */ + if (dxdy < 0) + z->dx = -STBTT_ifloor(STBTT_FIX * -dxdy); + else + z->dx = STBTT_ifloor(STBTT_FIX * dxdy); + + z->x = STBTT_ifloor(STBTT_FIX * e->x0 + z->dx * (start_point - e->y0)); /* use z->dx so when we offset later it's by the same amount */ + z->x -= off_x * STBTT_FIX; + + z->ey = e->y1; + z->next = 0; + z->direction = e->invert ? 1 : -1; + return z; +} +#elif STBTT_RASTERIZER_VERSION == 2 +static stbtt__active_edge *stbtt__new_active(stbtt__hheap *hh, stbtt__edge *e, int off_x, float start_point, void *userdata) +{ + stbtt__active_edge *z = (stbtt__active_edge *) stbtt__hheap_alloc(hh, sizeof(*z), userdata); + float dxdy = (e->x1 - e->x0) / (e->y1 - e->y0); + STBTT_assert(z != NULL); + /* STBTT_assert(e->y0 <= start_point); */ + if (!z) return z; + z->fdx = dxdy; + z->fdy = dxdy != 0.0f ? (1.0f/dxdy) : 0.0f; + z->fx = e->x0 + dxdy * (start_point - e->y0); + z->fx -= off_x; + z->direction = e->invert ? 1.0f : -1.0f; + z->sy = e->y0; + z->ey = e->y1; + z->next = 0; + return z; +} +#else +#error "Unrecognized value of STBTT_RASTERIZER_VERSION" +#endif + +#if STBTT_RASTERIZER_VERSION == 1 +/* note: this routine clips fills that extend off the edges... ideally this */ +/* wouldn't happen, but it could happen if the truetype glyph bounding boxes */ +/* are wrong, or if the user supplies a too-small bitmap */ +static void stbtt__fill_active_edges(unsigned char *scanline, int len, stbtt__active_edge *e, int max_weight) +{ + /* non-zero winding fill */ + int x0=0, w=0; + + while (e) { + if (w == 0) { + /* if we're currently at zero, we need to record the edge start point */ + x0 = e->x; w += e->direction; + } else { + int x1 = e->x; w += e->direction; + /* if we went to zero, we need to draw */ + if (w == 0) { + int i = x0 >> STBTT_FIXSHIFT; + int j = x1 >> STBTT_FIXSHIFT; + + if (i < len && j >= 0) { + if (i == j) { + /* x0,x1 are the same pixel, so compute combined coverage */ + scanline[i] = scanline[i] + (stbtt_uint8) ((x1 - x0) * max_weight >> STBTT_FIXSHIFT); + } else { + if (i >= 0) /* add antialiasing for x0 */ + scanline[i] = scanline[i] + (stbtt_uint8) (((STBTT_FIX - (x0 & STBTT_FIXMASK)) * max_weight) >> STBTT_FIXSHIFT); + else + i = -1; /* clip */ + + if (j < len) /* add antialiasing for x1 */ + scanline[j] = scanline[j] + (stbtt_uint8) (((x1 & STBTT_FIXMASK) * max_weight) >> STBTT_FIXSHIFT); + else + j = len; /* clip */ + + for (++i; i < j; ++i) /* fill pixels between x0 and x1 */ + scanline[i] = scanline[i] + (stbtt_uint8) max_weight; + } + } + } + } + + e = e->next; + } +} + +static void stbtt__rasterize_sorted_edges(stbtt__bitmap *result, stbtt__edge *e, int n, int vsubsample, int off_x, int off_y, void *userdata) +{ + stbtt__hheap hh = { 0, 0, 0 }; + stbtt__active_edge *active = NULL; + int y,j=0; + int max_weight = (255 / vsubsample); /* weight per vertical scanline */ + int s; /* vertical subsample index */ + unsigned char scanline_data[512], *scanline; + + if (result->w > 512) + scanline = (unsigned char *) STBTT_malloc(result->w, userdata); + else + scanline = scanline_data; + + y = off_y * vsubsample; + e[n].y0 = (off_y + result->h) * (float) vsubsample + 1; + + while (j < result->h) { + STBTT_memset(scanline, 0, result->w); + for (s=0; s < vsubsample; ++s) { + /* find center of pixel for this scanline */ + float scan_y = y + 0.5f; + stbtt__active_edge **step = &active; + + /* update all active edges; */ + /* remove all active edges that terminate before the center of this scanline */ + while (*step) { + stbtt__active_edge * z = *step; + if (z->ey <= scan_y) { + *step = z->next; /* delete from list */ + STBTT_assert(z->direction); + z->direction = 0; + stbtt__hheap_free(&hh, z); + } else { + z->x += z->dx; /* advance to position for current scanline */ + step = &((*step)->next); /* advance through list */ + } + } + + /* resort the list if needed */ + for(;;) { + int changed=0; + step = &active; + while (*step && (*step)->next) { + if ((*step)->x > (*step)->next->x) { + stbtt__active_edge *t = *step; + stbtt__active_edge *q = t->next; + + t->next = q->next; + q->next = t; + *step = q; + changed = 1; + } + step = &(*step)->next; + } + if (!changed) break; + } + + /* insert all edges that start before the center of this scanline -- omit ones that also end on this scanline */ + while (e->y0 <= scan_y) { + if (e->y1 > scan_y) { + stbtt__active_edge *z = stbtt__new_active(&hh, e, off_x, scan_y, userdata); + if (z != NULL) { + /* find insertion point */ + if (active == NULL) + active = z; + else if (z->x < active->x) { + /* insert at front */ + z->next = active; + active = z; + } else { + /* find thing to insert AFTER */ + stbtt__active_edge *p = active; + while (p->next && p->next->x < z->x) + p = p->next; + /* at this point, p->next->x is NOT < z->x */ + z->next = p->next; + p->next = z; + } + } + } + ++e; + } + + /* now process all active edges in XOR fashion */ + if (active) + stbtt__fill_active_edges(scanline, result->w, active, max_weight); + + ++y; + } + STBTT_memcpy(result->pixels + j * result->stride, scanline, result->w); + ++j; + } + + stbtt__hheap_cleanup(&hh, userdata); + + if (scanline != scanline_data) + STBTT_free(scanline, userdata); +} + +#elif STBTT_RASTERIZER_VERSION == 2 + +/* the edge passed in here does not cross the vertical line at x or the vertical line at x+1 */ +/* (i.e. it has already been clipped to those) */ +static void stbtt__handle_clipped_edge(float *scanline, int x, stbtt__active_edge *e, float x0, float y0, float x1, float y1) +{ + if (y0 == y1) return; + STBTT_assert(y0 < y1); + STBTT_assert(e->sy <= e->ey); + if (y0 > e->ey) return; + if (y1 < e->sy) return; + if (y0 < e->sy) { + x0 += (x1-x0) * (e->sy - y0) / (y1-y0); + y0 = e->sy; + } + if (y1 > e->ey) { + x1 += (x1-x0) * (e->ey - y1) / (y1-y0); + y1 = e->ey; + } + + if (x0 == x) + STBTT_assert(x1 <= x+1); + else if (x0 == x+1) + STBTT_assert(x1 >= x); + else if (x0 <= x) + STBTT_assert(x1 <= x); + else if (x0 >= x+1) + STBTT_assert(x1 >= x+1); + else + STBTT_assert(x1 >= x && x1 <= x+1); + + if (x0 <= x && x1 <= x) + scanline[x] += e->direction * (y1-y0); + else if (x0 >= x+1 && x1 >= x+1) + ; + else { + STBTT_assert(x0 >= x && x0 <= x+1 && x1 >= x && x1 <= x+1); + scanline[x] += e->direction * (y1-y0) * (1-((x0-x)+(x1-x))/2); /* coverage = 1 - average x position */ + } +} + +static float stbtt__sized_trapezoid_area(float height, float top_width, float bottom_width) +{ + STBTT_assert(top_width >= 0); + STBTT_assert(bottom_width >= 0); + return (top_width + bottom_width) / 2.0f * height; +} + +static float stbtt__position_trapezoid_area(float height, float tx0, float tx1, float bx0, float bx1) +{ + return stbtt__sized_trapezoid_area(height, tx1 - tx0, bx1 - bx0); +} + +static float stbtt__sized_triangle_area(float height, float width) +{ + return height * width / 2; +} + +static void stbtt__fill_active_edges_new(float *scanline, float *scanline_fill, int len, stbtt__active_edge *e, float y_top) +{ + float y_bottom = y_top+1; + + while (e) { + /* brute force every pixel */ + + /* compute intersection points with top & bottom */ + STBTT_assert(e->ey >= y_top); + + if (e->fdx == 0) { + float x0 = e->fx; + if (x0 < len) { + if (x0 >= 0) { + stbtt__handle_clipped_edge(scanline,(int) x0,e, x0,y_top, x0,y_bottom); + stbtt__handle_clipped_edge(scanline_fill-1,(int) x0+1,e, x0,y_top, x0,y_bottom); + } else { + stbtt__handle_clipped_edge(scanline_fill-1,0,e, x0,y_top, x0,y_bottom); + } + } + } else { + float x0 = e->fx; + float dx = e->fdx; + float xb = x0 + dx; + float x_top, x_bottom; + float sy0,sy1; + float dy = e->fdy; + STBTT_assert(e->sy <= y_bottom && e->ey >= y_top); + + /* compute endpoints of line segment clipped to this scanline (if the */ + /* line segment starts on this scanline. x0 is the intersection of the */ + /* line with y_top, but that may be off the line segment. */ + if (e->sy > y_top) { + x_top = x0 + dx * (e->sy - y_top); + sy0 = e->sy; + } else { + x_top = x0; + sy0 = y_top; + } + if (e->ey < y_bottom) { + x_bottom = x0 + dx * (e->ey - y_top); + sy1 = e->ey; + } else { + x_bottom = xb; + sy1 = y_bottom; + } + + if (x_top >= 0 && x_bottom >= 0 && x_top < len && x_bottom < len) { + /* from here on, we don't have to range check x values */ + + if ((int) x_top == (int) x_bottom) { + float height; + /* simple case, only spans one pixel */ + int x = (int) x_top; + height = (sy1 - sy0) * e->direction; + STBTT_assert(x >= 0 && x < len); + scanline[x] += stbtt__position_trapezoid_area(height, x_top, x+1.0f, x_bottom, x+1.0f); + scanline_fill[x] += height; /* everything right of this pixel is filled */ + } else { + int x,x1,x2; + float y_crossing, y_final, step, sign, area; + /* covers 2+ pixels */ + if (x_top > x_bottom) { + /* flip scanline vertically; signed area is the same */ + float t; + sy0 = y_bottom - (sy0 - y_top); + sy1 = y_bottom - (sy1 - y_top); + t = sy0, sy0 = sy1, sy1 = t; + t = x_bottom, x_bottom = x_top, x_top = t; + dx = -dx; + dy = -dy; + t = x0, x0 = xb, xb = t; + } + STBTT_assert(dy >= 0); + STBTT_assert(dx >= 0); + + x1 = (int) x_top; + x2 = (int) x_bottom; + /* compute intersection with y axis at x1+1 */ + y_crossing = y_top + dy * (x1+1 - x0); + + /* compute intersection with y axis at x2 */ + y_final = y_top + dy * (x2 - x0); + + /* x1 x_top x2 x_bottom */ + /* y_top +------|-----+------------+------------+--------|---+------------+ */ + /* | | | | | | */ + /* | | | | | | */ + /* sy0 | Txxxxx|............|............|............|............| */ + /* y_crossing | *xxxxx.......|............|............|............| */ + /* | | xxxxx..|............|............|............| */ + /* | | /- xx*xxxx........|............|............| */ + /* | | dy < | xxxxxx..|............|............| */ + /* y_final | | \- | xx*xxx.........|............| */ + /* sy1 | | | | xxxxxB...|............| */ + /* | | | | | | */ + /* | | | | | | */ + /* y_bottom +------------+------------+------------+------------+------------+ */ + /* */ + /* goal is to measure the area covered by '.' in each pixel */ + + /* if x2 is right at the right edge of x1, y_crossing can blow up, github #1057 */ + /* @TODO: maybe test against sy1 rather than y_bottom? */ + if (y_crossing > y_bottom) + y_crossing = y_bottom; + + sign = e->direction; + + /* area of the rectangle covered from sy0..y_crossing */ + area = sign * (y_crossing-sy0); + + /* area of the triangle (x_top,sy0), (x1+1,sy0), (x1+1,y_crossing) */ + scanline[x1] += stbtt__sized_triangle_area(area, x1+1 - x_top); + + /* check if final y_crossing is blown up; no test case for this */ + if (y_final > y_bottom) { + y_final = y_bottom; + dy = (y_final - y_crossing ) / (x2 - (x1+1)); /* if denom=0, y_final = y_crossing, so y_final <= y_bottom */ + } + + /* in second pixel, area covered by line segment found in first pixel */ + /* is always a rectangle 1 wide * the height of that line segment; this */ + /* is exactly what the variable 'area' stores. it also gets a contribution */ + /* from the line segment within it. the THIRD pixel will get the first */ + /* pixel's rectangle contribution, the second pixel's rectangle contribution, */ + /* and its own contribution. the 'own contribution' is the same in every pixel except */ + /* the leftmost and rightmost, a trapezoid that slides down in each pixel. */ + /* the second pixel's contribution to the third pixel will be the */ + /* rectangle 1 wide times the height change in the second pixel, which is dy. */ + + step = sign * dy * 1; /* dy is dy/dx, change in y for every 1 change in x, */ + /* which multiplied by 1-pixel-width is how much pixel area changes for each step in x */ + /* so the area advances by 'step' every time */ + + for (x = x1+1; x < x2; ++x) { + scanline[x] += area + step/2; /* area of trapezoid is 1*step/2 */ + area += step; + } + STBTT_assert(STBTT_fabs(area) <= 1.01f); /* accumulated error from area += step unless we round step down */ + STBTT_assert(sy1 > y_final-0.01f); + + /* area covered in the last pixel is the rectangle from all the pixels to the left, */ + /* plus the trapezoid filled by the line segment in this pixel all the way to the right edge */ + scanline[x2] += area + sign * stbtt__position_trapezoid_area(sy1-y_final, (float) x2, x2+1.0f, x_bottom, x2+1.0f); + + /* the rest of the line is filled based on the total height of the line segment in this pixel */ + scanline_fill[x2] += sign * (sy1-sy0); + } + } else { + /* if edge goes outside of box we're drawing, we require */ + /* clipping logic. since this does not match the intended use */ + /* of this library, we use a different, very slow brute */ + /* force implementation */ + /* note though that this does happen some of the time because */ + /* x_top and x_bottom can be extrapolated at the top & bottom of */ + /* the shape and actually lie outside the bounding box */ + int x; + for (x=0; x < len; ++x) { + /* cases: */ + /* */ + /* there can be up to two intersections with the pixel. any intersection */ + /* with left or right edges can be handled by splitting into two (or three) */ + /* regions. intersections with top & bottom do not necessitate case-wise logic. */ + /* */ + /* the old way of doing this found the intersections with the left & right edges, */ + /* then used some simple logic to produce up to three segments in sorted order */ + /* from top-to-bottom. however, this had a problem: if an x edge was epsilon */ + /* across the x border, then the corresponding y position might not be distinct */ + /* from the other y segment, and it might ignored as an empty segment. to avoid */ + /* that, we need to explicitly produce segments based on x positions. */ + + /* rename variables to clearly-defined pairs */ + float y0 = y_top; + float x1 = (float) (x); + float x2 = (float) (x+1); + float x3 = xb; + float y3 = y_bottom; + + /* x = e->x + e->dx * (y-y_top) */ + /* (y-y_top) = (x - e->x) / e->dx */ + /* y = (x - e->x) / e->dx + y_top */ + float y1 = (x - x0) / dx + y_top; + float y2 = (x+1 - x0) / dx + y_top; + + if (x0 < x1 && x3 > x2) { /* three segments descending down-right */ + stbtt__handle_clipped_edge(scanline,x,e, x0,y0, x1,y1); + stbtt__handle_clipped_edge(scanline,x,e, x1,y1, x2,y2); + stbtt__handle_clipped_edge(scanline,x,e, x2,y2, x3,y3); + } else if (x3 < x1 && x0 > x2) { /* three segments descending down-left */ + stbtt__handle_clipped_edge(scanline,x,e, x0,y0, x2,y2); + stbtt__handle_clipped_edge(scanline,x,e, x2,y2, x1,y1); + stbtt__handle_clipped_edge(scanline,x,e, x1,y1, x3,y3); + } else if (x0 < x1 && x3 > x1) { /* two segments across x, down-right */ + stbtt__handle_clipped_edge(scanline,x,e, x0,y0, x1,y1); + stbtt__handle_clipped_edge(scanline,x,e, x1,y1, x3,y3); + } else if (x3 < x1 && x0 > x1) { /* two segments across x, down-left */ + stbtt__handle_clipped_edge(scanline,x,e, x0,y0, x1,y1); + stbtt__handle_clipped_edge(scanline,x,e, x1,y1, x3,y3); + } else if (x0 < x2 && x3 > x2) { /* two segments across x+1, down-right */ + stbtt__handle_clipped_edge(scanline,x,e, x0,y0, x2,y2); + stbtt__handle_clipped_edge(scanline,x,e, x2,y2, x3,y3); + } else if (x3 < x2 && x0 > x2) { /* two segments across x+1, down-left */ + stbtt__handle_clipped_edge(scanline,x,e, x0,y0, x2,y2); + stbtt__handle_clipped_edge(scanline,x,e, x2,y2, x3,y3); + } else { /* one segment */ + stbtt__handle_clipped_edge(scanline,x,e, x0,y0, x3,y3); + } + } + } + } + e = e->next; + } +} + +/* directly AA rasterize edges w/o supersampling */ +static void stbtt__rasterize_sorted_edges(stbtt__bitmap *result, stbtt__edge *e, int n, int vsubsample, int off_x, int off_y, void *userdata) +{ + stbtt__hheap hh = { 0, 0, 0 }; + stbtt__active_edge *active = NULL; + int y,j=0, i; + float scanline_data[129], *scanline, *scanline2; + + STBTT__NOTUSED(vsubsample); + + if (result->w > 64) + scanline = (float *) STBTT_malloc((result->w*2+1) * sizeof(float), userdata); + else + scanline = scanline_data; + + scanline2 = scanline + result->w; + + y = off_y; + e[n].y0 = (float) (off_y + result->h) + 1; + + while (j < result->h) { + /* find center of pixel for this scanline */ + float scan_y_top = y + 0.0f; + float scan_y_bottom = y + 1.0f; + stbtt__active_edge **step = &active; + + STBTT_memset(scanline , 0, result->w*sizeof(scanline[0])); + STBTT_memset(scanline2, 0, (result->w+1)*sizeof(scanline[0])); + + /* update all active edges; */ + /* remove all active edges that terminate before the top of this scanline */ + while (*step) { + stbtt__active_edge * z = *step; + if (z->ey <= scan_y_top) { + *step = z->next; /* delete from list */ + STBTT_assert(z->direction); + z->direction = 0; + stbtt__hheap_free(&hh, z); + } else { + step = &((*step)->next); /* advance through list */ + } + } + + /* insert all edges that start before the bottom of this scanline */ + while (e->y0 <= scan_y_bottom) { + if (e->y0 != e->y1) { + stbtt__active_edge *z = stbtt__new_active(&hh, e, off_x, scan_y_top, userdata); + if (z != NULL) { + if (j == 0 && off_y != 0) { + if (z->ey < scan_y_top) { + /* this can happen due to subpixel positioning and some kind of fp rounding error i think */ + z->ey = scan_y_top; + } + } + STBTT_assert(z->ey >= scan_y_top); /* if we get really unlucky a tiny bit of an edge can be out of bounds */ + /* insert at front */ + z->next = active; + active = z; + } + } + ++e; + } + + /* now process all active edges */ + if (active) + stbtt__fill_active_edges_new(scanline, scanline2+1, result->w, active, scan_y_top); + + { + float sum = 0; + for (i=0; i < result->w; ++i) { + float k; + int m; + sum += scanline2[i]; + k = scanline[i] + sum; + k = (float) STBTT_fabs(k)*255 + 0.5f; + m = (int) k; + if (m > 255) m = 255; + result->pixels[j*result->stride + i] = (unsigned char) m; + } + } + /* advance all the edges */ + step = &active; + while (*step) { + stbtt__active_edge *z = *step; + z->fx += z->fdx; /* advance to position for current scanline */ + step = &((*step)->next); /* advance through list */ + } + + ++y; + ++j; + } + + stbtt__hheap_cleanup(&hh, userdata); + + if (scanline != scanline_data) + STBTT_free(scanline, userdata); +} +#else +#error "Unrecognized value of STBTT_RASTERIZER_VERSION" +#endif + +#define STBTT__COMPARE(a,b) ((a)->y0 < (b)->y0) + +static void stbtt__sort_edges_ins_sort(stbtt__edge *p, int n) +{ + int i,j; + for (i=1; i < n; ++i) { + stbtt__edge t = p[i], *a = &t; + j = i; + while (j > 0) { + stbtt__edge *b = &p[j-1]; + int c = STBTT__COMPARE(a,b); + if (!c) break; + p[j] = p[j-1]; + --j; + } + if (i != j) + p[j] = t; + } +} + +static void stbtt__sort_edges_quicksort(stbtt__edge *p, int n) +{ + /* threshold for transitioning to insertion sort */ + while (n > 12) { + stbtt__edge t; + int c01,c12,c,m,i,j; + + /* compute median of three */ + m = n >> 1; + c01 = STBTT__COMPARE(&p[0],&p[m]); + c12 = STBTT__COMPARE(&p[m],&p[n-1]); + /* if 0 >= mid >= end, or 0 < mid < end, then use mid */ + if (c01 != c12) { + /* otherwise, we'll need to swap something else to middle */ + int z; + c = STBTT__COMPARE(&p[0],&p[n-1]); + /* 0>mid && midn => n; 0 0 */ + /* 0n: 0>n => 0; 0 n */ + z = (c == c12) ? 0 : n-1; + t = p[z]; + p[z] = p[m]; + p[m] = t; + } + /* now p[m] is the median-of-three */ + /* swap it to the beginning so it won't move around */ + t = p[0]; + p[0] = p[m]; + p[m] = t; + + /* partition loop */ + i=1; + j=n-1; + for(;;) { + /* handling of equality is crucial here */ + /* for sentinels & efficiency with duplicates */ + for (;;++i) { + if (!STBTT__COMPARE(&p[i], &p[0])) break; + } + for (;;--j) { + if (!STBTT__COMPARE(&p[0], &p[j])) break; + } + /* make sure we haven't crossed */ + if (i >= j) break; + t = p[i]; + p[i] = p[j]; + p[j] = t; + + ++i; + --j; + } + /* recurse on smaller side, iterate on larger */ + if (j < (n-i)) { + stbtt__sort_edges_quicksort(p,j); + p = p+i; + n = n-i; + } else { + stbtt__sort_edges_quicksort(p+i, n-i); + n = j; + } + } +} + +static void stbtt__sort_edges(stbtt__edge *p, int n) +{ + stbtt__sort_edges_quicksort(p, n); + stbtt__sort_edges_ins_sort(p, n); +} + +typedef struct +{ + float x,y; +} stbtt__point; + +static void stbtt__rasterize(stbtt__bitmap *result, stbtt__point *pts, int *wcount, int windings, float scale_x, float scale_y, float shift_x, float shift_y, int off_x, int off_y, int invert, void *userdata) +{ + float y_scale_inv = invert ? -scale_y : scale_y; + stbtt__edge *e; + int n,i,j,k,m; +#if STBTT_RASTERIZER_VERSION == 1 + int vsubsample = result->h < 8 ? 15 : 5; +#elif STBTT_RASTERIZER_VERSION == 2 + int vsubsample = 1; +#else + #error "Unrecognized value of STBTT_RASTERIZER_VERSION" +#endif + /* vsubsample should divide 255 evenly; otherwise we won't reach full opacity */ + + /* now we have to blow out the windings into explicit edge lists */ + n = 0; + for (i=0; i < windings; ++i) + n += wcount[i]; + + e = (stbtt__edge *) STBTT_malloc(sizeof(*e) * (n+1), userdata); /* add an extra one as a sentinel */ + if (e == 0) return; + n = 0; + + m=0; + for (i=0; i < windings; ++i) { + stbtt__point *p = pts + m; + m += wcount[i]; + j = wcount[i]-1; + for (k=0; k < wcount[i]; j=k++) { + int a=k,b=j; + /* skip the edge if horizontal */ + if (p[j].y == p[k].y) + continue; + /* add edge from j to k to the list */ + e[n].invert = 0; + if (invert ? p[j].y > p[k].y : p[j].y < p[k].y) { + e[n].invert = 1; + a=j,b=k; + } + e[n].x0 = p[a].x * scale_x + shift_x; + e[n].y0 = (p[a].y * y_scale_inv + shift_y) * vsubsample; + e[n].x1 = p[b].x * scale_x + shift_x; + e[n].y1 = (p[b].y * y_scale_inv + shift_y) * vsubsample; + ++n; + } + } + + /* now sort the edges by their highest point (should snap to integer, and then by x) */ + /* STBTT_sort(e, n, sizeof(e[0]), stbtt__edge_compare); */ + stbtt__sort_edges(e, n); + + /* now, traverse the scanlines and find the intersections on each scanline, use xor winding rule */ + stbtt__rasterize_sorted_edges(result, e, n, vsubsample, off_x, off_y, userdata); + + STBTT_free(e, userdata); +} + +static void stbtt__add_point(stbtt__point *points, int n, float x, float y) +{ + if (!points) return; /* during first pass, it's unallocated */ + points[n].x = x; + points[n].y = y; +} + +/* tessellate until threshold p is happy... @TODO warped to compensate for non-linear stretching */ +static int stbtt__tesselate_curve(stbtt__point *points, int *num_points, float x0, float y0, float x1, float y1, float x2, float y2, float objspace_flatness_squared, int n) +{ + /* midpoint */ + float mx = (x0 + 2*x1 + x2)/4; + float my = (y0 + 2*y1 + y2)/4; + /* versus directly drawn line */ + float dx = (x0+x2)/2 - mx; + float dy = (y0+y2)/2 - my; + if (n > 16) /* 65536 segments on one curve better be enough! */ + return 1; + if (dx*dx+dy*dy > objspace_flatness_squared) { /* half-pixel error allowed... need to be smaller if AA */ + stbtt__tesselate_curve(points, num_points, x0,y0, (x0+x1)/2.0f,(y0+y1)/2.0f, mx,my, objspace_flatness_squared,n+1); + stbtt__tesselate_curve(points, num_points, mx,my, (x1+x2)/2.0f,(y1+y2)/2.0f, x2,y2, objspace_flatness_squared,n+1); + } else { + stbtt__add_point(points, *num_points,x2,y2); + *num_points = *num_points+1; + } + return 1; +} + +static void stbtt__tesselate_cubic(stbtt__point *points, int *num_points, float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3, float objspace_flatness_squared, int n) +{ + /* @TODO this "flatness" calculation is just made-up nonsense that seems to work well enough */ + float dx0 = x1-x0; + float dy0 = y1-y0; + float dx1 = x2-x1; + float dy1 = y2-y1; + float dx2 = x3-x2; + float dy2 = y3-y2; + float dx = x3-x0; + float dy = y3-y0; + float longlen = (float) (STBTT_sqrt(dx0*dx0+dy0*dy0)+STBTT_sqrt(dx1*dx1+dy1*dy1)+STBTT_sqrt(dx2*dx2+dy2*dy2)); + float shortlen = (float) STBTT_sqrt(dx*dx+dy*dy); + float flatness_squared = longlen*longlen-shortlen*shortlen; + + if (n > 16) /* 65536 segments on one curve better be enough! */ + return; + + if (flatness_squared > objspace_flatness_squared) { + float x01 = (x0+x1)/2; + float y01 = (y0+y1)/2; + float x12 = (x1+x2)/2; + float y12 = (y1+y2)/2; + float x23 = (x2+x3)/2; + float y23 = (y2+y3)/2; + + float xa = (x01+x12)/2; + float ya = (y01+y12)/2; + float xb = (x12+x23)/2; + float yb = (y12+y23)/2; + + float mx = (xa+xb)/2; + float my = (ya+yb)/2; + + stbtt__tesselate_cubic(points, num_points, x0,y0, x01,y01, xa,ya, mx,my, objspace_flatness_squared,n+1); + stbtt__tesselate_cubic(points, num_points, mx,my, xb,yb, x23,y23, x3,y3, objspace_flatness_squared,n+1); + } else { + stbtt__add_point(points, *num_points,x3,y3); + *num_points = *num_points+1; + } +} + +/* returns number of contours */ +static stbtt__point *stbtt_FlattenCurves(stbtt_vertex *vertices, int num_verts, float objspace_flatness, int **contour_lengths, int *num_contours, void *userdata) +{ + stbtt__point *points=0; + int num_points=0; + + float objspace_flatness_squared = objspace_flatness * objspace_flatness; + int i,n=0,start=0, pass; + + /* count how many "moves" there are to get the contour count */ + for (i=0; i < num_verts; ++i) + if (vertices[i].type == STBTT_vmove) + ++n; + + *num_contours = n; + if (n == 0) return 0; + + *contour_lengths = (int *) STBTT_malloc(sizeof(**contour_lengths) * n, userdata); + + if (*contour_lengths == 0) { + *num_contours = 0; + return 0; + } + + /* make two passes through the points so we don't need to realloc */ + for (pass=0; pass < 2; ++pass) { + float x=0,y=0; + if (pass == 1) { + points = (stbtt__point *) STBTT_malloc(num_points * sizeof(points[0]), userdata); + if (points == NULL) goto error; + } + num_points = 0; + n= -1; + for (i=0; i < num_verts; ++i) { + switch (vertices[i].type) { + case STBTT_vmove: + /* start the next contour */ + if (n >= 0) + (*contour_lengths)[n] = num_points - start; + ++n; + start = num_points; + + x = vertices[i].x, y = vertices[i].y; + stbtt__add_point(points, num_points++, x,y); + break; + case STBTT_vline: + x = vertices[i].x, y = vertices[i].y; + stbtt__add_point(points, num_points++, x, y); + break; + case STBTT_vcurve: + stbtt__tesselate_curve(points, &num_points, x,y, + vertices[i].cx, vertices[i].cy, + vertices[i].x, vertices[i].y, + objspace_flatness_squared, 0); + x = vertices[i].x, y = vertices[i].y; + break; + case STBTT_vcubic: + stbtt__tesselate_cubic(points, &num_points, x,y, + vertices[i].cx, vertices[i].cy, + vertices[i].cx1, vertices[i].cy1, + vertices[i].x, vertices[i].y, + objspace_flatness_squared, 0); + x = vertices[i].x, y = vertices[i].y; + break; + } + } + (*contour_lengths)[n] = num_points - start; + } + + return points; +error: + STBTT_free(points, userdata); + STBTT_free(*contour_lengths, userdata); + *contour_lengths = 0; + *num_contours = 0; + return NULL; +} + +STBTT_DEF void stbtt_Rasterize(stbtt__bitmap *result, float flatness_in_pixels, stbtt_vertex *vertices, int num_verts, float scale_x, float scale_y, float shift_x, float shift_y, int x_off, int y_off, int invert, void *userdata) +{ + float scale = scale_x > scale_y ? scale_y : scale_x; + int winding_count = 0; + int *winding_lengths = NULL; + stbtt__point *windings = stbtt_FlattenCurves(vertices, num_verts, flatness_in_pixels / scale, &winding_lengths, &winding_count, userdata); + if (windings) { + stbtt__rasterize(result, windings, winding_lengths, winding_count, scale_x, scale_y, shift_x, shift_y, x_off, y_off, invert, userdata); + STBTT_free(winding_lengths, userdata); + STBTT_free(windings, userdata); + } +} + +STBTT_DEF void stbtt_FreeBitmap(unsigned char *bitmap, void *userdata) +{ + STBTT_free(bitmap, userdata); +} + +STBTT_DEF unsigned char *stbtt_GetGlyphBitmapSubpixel(const stbtt_fontinfo *info, float scale_x, float scale_y, float shift_x, float shift_y, int glyph, int *width, int *height, int *xoff, int *yoff) +{ + int ix0,iy0,ix1,iy1; + stbtt__bitmap gbm; + stbtt_vertex *vertices; + int num_verts = stbtt_GetGlyphShape(info, glyph, &vertices); + + if (scale_x == 0) scale_x = scale_y; + if (scale_y == 0) { + if (scale_x == 0) { + STBTT_free(vertices, info->userdata); + return NULL; + } + scale_y = scale_x; + } + + stbtt_GetGlyphBitmapBoxSubpixel(info, glyph, scale_x, scale_y, shift_x, shift_y, &ix0,&iy0,&ix1,&iy1); + + /* now we get the size */ + gbm.w = (ix1 - ix0); + gbm.h = (iy1 - iy0); + gbm.pixels = NULL; /* in case we error */ + + if (width ) *width = gbm.w; + if (height) *height = gbm.h; + if (xoff ) *xoff = ix0; + if (yoff ) *yoff = iy0; + + if (gbm.w && gbm.h) { + gbm.pixels = (unsigned char *) STBTT_malloc(gbm.w * gbm.h, info->userdata); + if (gbm.pixels) { + gbm.stride = gbm.w; + + stbtt_Rasterize(&gbm, 0.35f, vertices, num_verts, scale_x, scale_y, shift_x, shift_y, ix0, iy0, 1, info->userdata); + } + } + STBTT_free(vertices, info->userdata); + return gbm.pixels; +} + +STBTT_DEF unsigned char *stbtt_GetGlyphBitmap(const stbtt_fontinfo *info, float scale_x, float scale_y, int glyph, int *width, int *height, int *xoff, int *yoff) +{ + return stbtt_GetGlyphBitmapSubpixel(info, scale_x, scale_y, 0.0f, 0.0f, glyph, width, height, xoff, yoff); +} + +STBTT_DEF void stbtt_MakeGlyphBitmapSubpixel(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int glyph) +{ + int ix0,iy0; + stbtt_vertex *vertices; + int num_verts = stbtt_GetGlyphShape(info, glyph, &vertices); + stbtt__bitmap gbm; + + stbtt_GetGlyphBitmapBoxSubpixel(info, glyph, scale_x, scale_y, shift_x, shift_y, &ix0,&iy0,0,0); + gbm.pixels = output; + gbm.w = out_w; + gbm.h = out_h; + gbm.stride = out_stride; + + if (gbm.w && gbm.h) + stbtt_Rasterize(&gbm, 0.35f, vertices, num_verts, scale_x, scale_y, shift_x, shift_y, ix0,iy0, 1, info->userdata); + + STBTT_free(vertices, info->userdata); +} + +STBTT_DEF void stbtt_MakeGlyphBitmap(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, int glyph) +{ + stbtt_MakeGlyphBitmapSubpixel(info, output, out_w, out_h, out_stride, scale_x, scale_y, 0.0f,0.0f, glyph); +} + +STBTT_DEF unsigned char *stbtt_GetCodepointBitmapSubpixel(const stbtt_fontinfo *info, float scale_x, float scale_y, float shift_x, float shift_y, int codepoint, int *width, int *height, int *xoff, int *yoff) +{ + return stbtt_GetGlyphBitmapSubpixel(info, scale_x, scale_y,shift_x,shift_y, stbtt_FindGlyphIndex(info,codepoint), width,height,xoff,yoff); +} + +STBTT_DEF void stbtt_MakeCodepointBitmapSubpixelPrefilter(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int oversample_x, int oversample_y, float *sub_x, float *sub_y, int codepoint) +{ + stbtt_MakeGlyphBitmapSubpixelPrefilter(info, output, out_w, out_h, out_stride, scale_x, scale_y, shift_x, shift_y, oversample_x, oversample_y, sub_x, sub_y, stbtt_FindGlyphIndex(info,codepoint)); +} + +STBTT_DEF void stbtt_MakeCodepointBitmapSubpixel(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int codepoint) +{ + stbtt_MakeGlyphBitmapSubpixel(info, output, out_w, out_h, out_stride, scale_x, scale_y, shift_x, shift_y, stbtt_FindGlyphIndex(info,codepoint)); +} + +STBTT_DEF unsigned char *stbtt_GetCodepointBitmap(const stbtt_fontinfo *info, float scale_x, float scale_y, int codepoint, int *width, int *height, int *xoff, int *yoff) +{ + return stbtt_GetCodepointBitmapSubpixel(info, scale_x, scale_y, 0.0f,0.0f, codepoint, width,height,xoff,yoff); +} + +STBTT_DEF void stbtt_MakeCodepointBitmap(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, int codepoint) +{ + stbtt_MakeCodepointBitmapSubpixel(info, output, out_w, out_h, out_stride, scale_x, scale_y, 0.0f,0.0f, codepoint); +} + +/* //////////////////////////////////////////////////////////////////////////// */ +/* */ +/* bitmap baking */ +/* */ +/* This is SUPER-CRAPPY packing to keep source code small */ + +static int stbtt_BakeFontBitmap_internal(unsigned char *data, int offset, /* font location (use offset=0 for plain .ttf) */ + float pixel_height, /* height of font in pixels */ + unsigned char *pixels, int pw, int ph, /* bitmap to be filled in */ + int first_char, int num_chars, /* characters to bake */ + stbtt_bakedchar *chardata) +{ + float scale; + int x,y,bottom_y, i; + stbtt_fontinfo f; + f.userdata = NULL; + if (!stbtt_InitFont(&f, data, offset)) + return -1; + STBTT_memset(pixels, 0, pw*ph); /* background of 0 around pixels */ + x=y=1; + bottom_y = 1; + + scale = stbtt_ScaleForPixelHeight(&f, pixel_height); + + for (i=0; i < num_chars; ++i) { + int advance, lsb, x0,y0,x1,y1,gw,gh; + int g = stbtt_FindGlyphIndex(&f, first_char + i); + stbtt_GetGlyphHMetrics(&f, g, &advance, &lsb); + stbtt_GetGlyphBitmapBox(&f, g, scale,scale, &x0,&y0,&x1,&y1); + gw = x1-x0; + gh = y1-y0; + if (x + gw + 1 >= pw) + y = bottom_y, x = 1; /* advance to next row */ + if (y + gh + 1 >= ph) /* check if it fits vertically AFTER potentially moving to next row */ + return -i; + STBTT_assert(x+gw < pw); + STBTT_assert(y+gh < ph); + stbtt_MakeGlyphBitmap(&f, pixels+x+y*pw, gw,gh,pw, scale,scale, g); + chardata[i].x0 = (stbtt_int16) x; + chardata[i].y0 = (stbtt_int16) y; + chardata[i].x1 = (stbtt_int16) (x + gw); + chardata[i].y1 = (stbtt_int16) (y + gh); + chardata[i].xadvance = scale * advance; + chardata[i].xoff = (float) x0; + chardata[i].yoff = (float) y0; + x = x + gw + 1; + if (y+gh+1 > bottom_y) + bottom_y = y+gh+1; + } + return bottom_y; +} + +STBTT_DEF void stbtt_GetBakedQuad(const stbtt_bakedchar *chardata, int pw, int ph, int char_index, float *xpos, float *ypos, stbtt_aligned_quad *q, int opengl_fillrule) +{ + float d3d_bias = opengl_fillrule ? 0 : -0.5f; + float ipw = 1.0f / pw, iph = 1.0f / ph; + const stbtt_bakedchar *b = chardata + char_index; + int round_x = STBTT_ifloor((*xpos + b->xoff) + 0.5f); + int round_y = STBTT_ifloor((*ypos + b->yoff) + 0.5f); + + q->x0 = round_x + d3d_bias; + q->y0 = round_y + d3d_bias; + q->x1 = round_x + b->x1 - b->x0 + d3d_bias; + q->y1 = round_y + b->y1 - b->y0 + d3d_bias; + + q->s0 = b->x0 * ipw; + q->t0 = b->y0 * iph; + q->s1 = b->x1 * ipw; + q->t1 = b->y1 * iph; + + *xpos += b->xadvance; +} + +/* //////////////////////////////////////////////////////////////////////////// */ +/* */ +/* rectangle packing replacement routines if you don't have stb_rect_pack.h */ +/* */ + +#ifndef STB_RECT_PACK_VERSION + +typedef int stbrp_coord; + +/* ////////////////////////////////////////////////////////////////////////////////// */ +/* // */ +/* // */ +/* COMPILER WARNING ?!?!? // */ +/* // */ +/* // */ +/* if you get a compile warning due to these symbols being defined more than // */ +/* once, move #include "stb_rect_pack.h" before #include "stb_truetype.h" // */ +/* // */ +/* ////////////////////////////////////////////////////////////////////////////////// */ + +typedef struct +{ + int width,height; + int x,y,bottom_y; +} stbrp_context; + +typedef struct +{ + unsigned char x; +} stbrp_node; + +struct stbrp_rect +{ + stbrp_coord x,y; + int id,w,h,was_packed; +}; + +static void stbrp_init_target(stbrp_context *con, int pw, int ph, stbrp_node *nodes, int num_nodes) +{ + con->width = pw; + con->height = ph; + con->x = 0; + con->y = 0; + con->bottom_y = 0; + STBTT__NOTUSED(nodes); + STBTT__NOTUSED(num_nodes); +} + +static void stbrp_pack_rects(stbrp_context *con, stbrp_rect *rects, int num_rects) +{ + int i; + for (i=0; i < num_rects; ++i) { + if (con->x + rects[i].w > con->width) { + con->x = 0; + con->y = con->bottom_y; + } + if (con->y + rects[i].h > con->height) + break; + rects[i].x = con->x; + rects[i].y = con->y; + rects[i].was_packed = 1; + con->x += rects[i].w; + if (con->y + rects[i].h > con->bottom_y) + con->bottom_y = con->y + rects[i].h; + } + for ( ; i < num_rects; ++i) + rects[i].was_packed = 0; +} +#endif + +/* //////////////////////////////////////////////////////////////////////////// */ +/* */ +/* bitmap baking */ +/* */ +/* This is SUPER-AWESOME (tm Ryan Gordon) packing using stb_rect_pack.h. If */ +/* stb_rect_pack.h isn't available, it uses the BakeFontBitmap strategy. */ + +STBTT_DEF int stbtt_PackBegin(stbtt_pack_context *spc, unsigned char *pixels, int pw, int ph, int stride_in_bytes, int padding, void *alloc_context) +{ + stbrp_context *context = (stbrp_context *) STBTT_malloc(sizeof(*context) ,alloc_context); + int num_nodes = pw - padding; + stbrp_node *nodes = (stbrp_node *) STBTT_malloc(sizeof(*nodes ) * num_nodes,alloc_context); + + if (context == NULL || nodes == NULL) { + if (context != NULL) STBTT_free(context, alloc_context); + if (nodes != NULL) STBTT_free(nodes , alloc_context); + return 0; + } + + spc->user_allocator_context = alloc_context; + spc->width = pw; + spc->height = ph; + spc->pixels = pixels; + spc->pack_info = context; + spc->nodes = nodes; + spc->padding = padding; + spc->stride_in_bytes = stride_in_bytes != 0 ? stride_in_bytes : pw; + spc->h_oversample = 1; + spc->v_oversample = 1; + spc->skip_missing = 0; + + stbrp_init_target(context, pw-padding, ph-padding, nodes, num_nodes); + + if (pixels) + STBTT_memset(pixels, 0, pw*ph); /* background of 0 around pixels */ + + return 1; +} + +STBTT_DEF void stbtt_PackEnd (stbtt_pack_context *spc) +{ + STBTT_free(spc->nodes , spc->user_allocator_context); + STBTT_free(spc->pack_info, spc->user_allocator_context); +} + +STBTT_DEF void stbtt_PackSetOversampling(stbtt_pack_context *spc, unsigned int h_oversample, unsigned int v_oversample) +{ + STBTT_assert(h_oversample <= STBTT_MAX_OVERSAMPLE); + STBTT_assert(v_oversample <= STBTT_MAX_OVERSAMPLE); + if (h_oversample <= STBTT_MAX_OVERSAMPLE) + spc->h_oversample = h_oversample; + if (v_oversample <= STBTT_MAX_OVERSAMPLE) + spc->v_oversample = v_oversample; +} + +STBTT_DEF void stbtt_PackSetSkipMissingCodepoints(stbtt_pack_context *spc, int skip) +{ + spc->skip_missing = skip; +} + +#define STBTT__OVER_MASK (STBTT_MAX_OVERSAMPLE-1) + +static void stbtt__h_prefilter(unsigned char *pixels, int w, int h, int stride_in_bytes, unsigned int kernel_width) +{ + unsigned char buffer[STBTT_MAX_OVERSAMPLE]; + int safe_w = w - kernel_width; + int j; + STBTT_memset(buffer, 0, STBTT_MAX_OVERSAMPLE); /* suppress bogus warning from VS2013 -analyze */ + for (j=0; j < h; ++j) { + int i; + unsigned int total; + STBTT_memset(buffer, 0, kernel_width); + + total = 0; + + /* make kernel_width a constant in common cases so compiler can optimize out the divide */ + switch (kernel_width) { + case 2: + for (i=0; i <= safe_w; ++i) { + total += pixels[i] - buffer[i & STBTT__OVER_MASK]; + buffer[(i+kernel_width) & STBTT__OVER_MASK] = pixels[i]; + pixels[i] = (unsigned char) (total / 2); + } + break; + case 3: + for (i=0; i <= safe_w; ++i) { + total += pixels[i] - buffer[i & STBTT__OVER_MASK]; + buffer[(i+kernel_width) & STBTT__OVER_MASK] = pixels[i]; + pixels[i] = (unsigned char) (total / 3); + } + break; + case 4: + for (i=0; i <= safe_w; ++i) { + total += pixels[i] - buffer[i & STBTT__OVER_MASK]; + buffer[(i+kernel_width) & STBTT__OVER_MASK] = pixels[i]; + pixels[i] = (unsigned char) (total / 4); + } + break; + case 5: + for (i=0; i <= safe_w; ++i) { + total += pixels[i] - buffer[i & STBTT__OVER_MASK]; + buffer[(i+kernel_width) & STBTT__OVER_MASK] = pixels[i]; + pixels[i] = (unsigned char) (total / 5); + } + break; + default: + for (i=0; i <= safe_w; ++i) { + total += pixels[i] - buffer[i & STBTT__OVER_MASK]; + buffer[(i+kernel_width) & STBTT__OVER_MASK] = pixels[i]; + pixels[i] = (unsigned char) (total / kernel_width); + } + break; + } + + for (; i < w; ++i) { + STBTT_assert(pixels[i] == 0); + total -= buffer[i & STBTT__OVER_MASK]; + pixels[i] = (unsigned char) (total / kernel_width); + } + + pixels += stride_in_bytes; + } +} + +static void stbtt__v_prefilter(unsigned char *pixels, int w, int h, int stride_in_bytes, unsigned int kernel_width) +{ + unsigned char buffer[STBTT_MAX_OVERSAMPLE]; + int safe_h = h - kernel_width; + int j; + STBTT_memset(buffer, 0, STBTT_MAX_OVERSAMPLE); /* suppress bogus warning from VS2013 -analyze */ + for (j=0; j < w; ++j) { + int i; + unsigned int total; + STBTT_memset(buffer, 0, kernel_width); + + total = 0; + + /* make kernel_width a constant in common cases so compiler can optimize out the divide */ + switch (kernel_width) { + case 2: + for (i=0; i <= safe_h; ++i) { + total += pixels[i*stride_in_bytes] - buffer[i & STBTT__OVER_MASK]; + buffer[(i+kernel_width) & STBTT__OVER_MASK] = pixels[i*stride_in_bytes]; + pixels[i*stride_in_bytes] = (unsigned char) (total / 2); + } + break; + case 3: + for (i=0; i <= safe_h; ++i) { + total += pixels[i*stride_in_bytes] - buffer[i & STBTT__OVER_MASK]; + buffer[(i+kernel_width) & STBTT__OVER_MASK] = pixels[i*stride_in_bytes]; + pixels[i*stride_in_bytes] = (unsigned char) (total / 3); + } + break; + case 4: + for (i=0; i <= safe_h; ++i) { + total += pixels[i*stride_in_bytes] - buffer[i & STBTT__OVER_MASK]; + buffer[(i+kernel_width) & STBTT__OVER_MASK] = pixels[i*stride_in_bytes]; + pixels[i*stride_in_bytes] = (unsigned char) (total / 4); + } + break; + case 5: + for (i=0; i <= safe_h; ++i) { + total += pixels[i*stride_in_bytes] - buffer[i & STBTT__OVER_MASK]; + buffer[(i+kernel_width) & STBTT__OVER_MASK] = pixels[i*stride_in_bytes]; + pixels[i*stride_in_bytes] = (unsigned char) (total / 5); + } + break; + default: + for (i=0; i <= safe_h; ++i) { + total += pixels[i*stride_in_bytes] - buffer[i & STBTT__OVER_MASK]; + buffer[(i+kernel_width) & STBTT__OVER_MASK] = pixels[i*stride_in_bytes]; + pixels[i*stride_in_bytes] = (unsigned char) (total / kernel_width); + } + break; + } + + for (; i < h; ++i) { + STBTT_assert(pixels[i*stride_in_bytes] == 0); + total -= buffer[i & STBTT__OVER_MASK]; + pixels[i*stride_in_bytes] = (unsigned char) (total / kernel_width); + } + + pixels += 1; + } +} + +static float stbtt__oversample_shift(int oversample) +{ + if (!oversample) + return 0.0f; + + /* The prefilter is a box filter of width "oversample", */ + /* which shifts phase by (oversample - 1)/2 pixels in */ + /* oversampled space. We want to shift in the opposite */ + /* direction to counter this. */ + return (float)-(oversample - 1) / (2.0f * (float)oversample); +} + +/* rects array must be big enough to accommodate all characters in the given ranges */ +STBTT_DEF int stbtt_PackFontRangesGatherRects(stbtt_pack_context *spc, const stbtt_fontinfo *info, stbtt_pack_range *ranges, int num_ranges, stbrp_rect *rects) +{ + int i,j,k; + int missing_glyph_added = 0; + + k=0; + for (i=0; i < num_ranges; ++i) { + float fh = ranges[i].font_size; + float scale = fh > 0 ? stbtt_ScaleForPixelHeight(info, fh) : stbtt_ScaleForMappingEmToPixels(info, -fh); + ranges[i].h_oversample = (unsigned char) spc->h_oversample; + ranges[i].v_oversample = (unsigned char) spc->v_oversample; + for (j=0; j < ranges[i].num_chars; ++j) { + int x0,y0,x1,y1; + int codepoint = ranges[i].array_of_unicode_codepoints == NULL ? ranges[i].first_unicode_codepoint_in_range + j : ranges[i].array_of_unicode_codepoints[j]; + int glyph = stbtt_FindGlyphIndex(info, codepoint); + if (glyph == 0 && (spc->skip_missing || missing_glyph_added)) { + rects[k].w = rects[k].h = 0; + } else { + stbtt_GetGlyphBitmapBoxSubpixel(info,glyph, + scale * spc->h_oversample, + scale * spc->v_oversample, + 0,0, + &x0,&y0,&x1,&y1); + rects[k].w = (stbrp_coord) (x1-x0 + spc->padding + spc->h_oversample-1); + rects[k].h = (stbrp_coord) (y1-y0 + spc->padding + spc->v_oversample-1); + if (glyph == 0) + missing_glyph_added = 1; + } + ++k; + } + } + + return k; +} + +STBTT_DEF void stbtt_MakeGlyphBitmapSubpixelPrefilter(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int prefilter_x, int prefilter_y, float *sub_x, float *sub_y, int glyph) +{ + stbtt_MakeGlyphBitmapSubpixel(info, + output, + out_w - (prefilter_x - 1), + out_h - (prefilter_y - 1), + out_stride, + scale_x, + scale_y, + shift_x, + shift_y, + glyph); + + if (prefilter_x > 1) + stbtt__h_prefilter(output, out_w, out_h, out_stride, prefilter_x); + + if (prefilter_y > 1) + stbtt__v_prefilter(output, out_w, out_h, out_stride, prefilter_y); + + *sub_x = stbtt__oversample_shift(prefilter_x); + *sub_y = stbtt__oversample_shift(prefilter_y); +} + +/* rects array must be big enough to accommodate all characters in the given ranges */ +STBTT_DEF int stbtt_PackFontRangesRenderIntoRects(stbtt_pack_context *spc, const stbtt_fontinfo *info, stbtt_pack_range *ranges, int num_ranges, stbrp_rect *rects) +{ + int i,j,k, missing_glyph = -1, return_value = 1; + + /* save current values */ + int old_h_over = spc->h_oversample; + int old_v_over = spc->v_oversample; + + k = 0; + for (i=0; i < num_ranges; ++i) { + float fh = ranges[i].font_size; + float scale = fh > 0 ? stbtt_ScaleForPixelHeight(info, fh) : stbtt_ScaleForMappingEmToPixels(info, -fh); + float recip_h,recip_v,sub_x,sub_y; + spc->h_oversample = ranges[i].h_oversample; + spc->v_oversample = ranges[i].v_oversample; + recip_h = 1.0f / spc->h_oversample; + recip_v = 1.0f / spc->v_oversample; + sub_x = stbtt__oversample_shift(spc->h_oversample); + sub_y = stbtt__oversample_shift(spc->v_oversample); + for (j=0; j < ranges[i].num_chars; ++j) { + stbrp_rect *r = &rects[k]; + if (r->was_packed && r->w != 0 && r->h != 0) { + stbtt_packedchar *bc = &ranges[i].chardata_for_range[j]; + int advance, lsb, x0,y0,x1,y1; + int codepoint = ranges[i].array_of_unicode_codepoints == NULL ? ranges[i].first_unicode_codepoint_in_range + j : ranges[i].array_of_unicode_codepoints[j]; + int glyph = stbtt_FindGlyphIndex(info, codepoint); + stbrp_coord pad = (stbrp_coord) spc->padding; + + /* pad on left and top */ + r->x += pad; + r->y += pad; + r->w -= pad; + r->h -= pad; + stbtt_GetGlyphHMetrics(info, glyph, &advance, &lsb); + stbtt_GetGlyphBitmapBox(info, glyph, + scale * spc->h_oversample, + scale * spc->v_oversample, + &x0,&y0,&x1,&y1); + stbtt_MakeGlyphBitmapSubpixel(info, + spc->pixels + r->x + r->y*spc->stride_in_bytes, + r->w - spc->h_oversample+1, + r->h - spc->v_oversample+1, + spc->stride_in_bytes, + scale * spc->h_oversample, + scale * spc->v_oversample, + 0,0, + glyph); + + if (spc->h_oversample > 1) + stbtt__h_prefilter(spc->pixels + r->x + r->y*spc->stride_in_bytes, + r->w, r->h, spc->stride_in_bytes, + spc->h_oversample); + + if (spc->v_oversample > 1) + stbtt__v_prefilter(spc->pixels + r->x + r->y*spc->stride_in_bytes, + r->w, r->h, spc->stride_in_bytes, + spc->v_oversample); + + bc->x0 = (stbtt_int16) r->x; + bc->y0 = (stbtt_int16) r->y; + bc->x1 = (stbtt_int16) (r->x + r->w); + bc->y1 = (stbtt_int16) (r->y + r->h); + bc->xadvance = scale * advance; + bc->xoff = (float) x0 * recip_h + sub_x; + bc->yoff = (float) y0 * recip_v + sub_y; + bc->xoff2 = (x0 + r->w) * recip_h + sub_x; + bc->yoff2 = (y0 + r->h) * recip_v + sub_y; + + if (glyph == 0) + missing_glyph = j; + } else if (spc->skip_missing) { + return_value = 0; + } else if (r->was_packed && r->w == 0 && r->h == 0 && missing_glyph >= 0) { + ranges[i].chardata_for_range[j] = ranges[i].chardata_for_range[missing_glyph]; + } else { + return_value = 0; /* if any fail, report failure */ + } + + ++k; + } + } + + /* restore original values */ + spc->h_oversample = old_h_over; + spc->v_oversample = old_v_over; + + return return_value; +} + +STBTT_DEF void stbtt_PackFontRangesPackRects(stbtt_pack_context *spc, stbrp_rect *rects, int num_rects) +{ + stbrp_pack_rects((stbrp_context *) spc->pack_info, rects, num_rects); +} + +STBTT_DEF int stbtt_PackFontRanges(stbtt_pack_context *spc, const unsigned char *fontdata, int font_index, stbtt_pack_range *ranges, int num_ranges) +{ + stbtt_fontinfo info; + int i,j,n, return_value = 1; + /* stbrp_context *context = (stbrp_context *) spc->pack_info; */ + stbrp_rect *rects; + + /* flag all characters as NOT packed */ + for (i=0; i < num_ranges; ++i) + for (j=0; j < ranges[i].num_chars; ++j) + ranges[i].chardata_for_range[j].x0 = + ranges[i].chardata_for_range[j].y0 = + ranges[i].chardata_for_range[j].x1 = + ranges[i].chardata_for_range[j].y1 = 0; + + n = 0; + for (i=0; i < num_ranges; ++i) + n += ranges[i].num_chars; + + rects = (stbrp_rect *) STBTT_malloc(sizeof(*rects) * n, spc->user_allocator_context); + if (rects == NULL) + return 0; + + info.userdata = spc->user_allocator_context; + stbtt_InitFont(&info, fontdata, stbtt_GetFontOffsetForIndex(fontdata,font_index)); + + n = stbtt_PackFontRangesGatherRects(spc, &info, ranges, num_ranges, rects); + + stbtt_PackFontRangesPackRects(spc, rects, n); + + return_value = stbtt_PackFontRangesRenderIntoRects(spc, &info, ranges, num_ranges, rects); + + STBTT_free(rects, spc->user_allocator_context); + return return_value; +} + +STBTT_DEF int stbtt_PackFontRange(stbtt_pack_context *spc, const unsigned char *fontdata, int font_index, float font_size, + int first_unicode_codepoint_in_range, int num_chars_in_range, stbtt_packedchar *chardata_for_range) +{ + stbtt_pack_range range; + range.first_unicode_codepoint_in_range = first_unicode_codepoint_in_range; + range.array_of_unicode_codepoints = NULL; + range.num_chars = num_chars_in_range; + range.chardata_for_range = chardata_for_range; + range.font_size = font_size; + return stbtt_PackFontRanges(spc, fontdata, font_index, &range, 1); +} + +STBTT_DEF void stbtt_GetScaledFontVMetrics(const unsigned char *fontdata, int index, float size, float *ascent, float *descent, float *lineGap) +{ + int i_ascent, i_descent, i_lineGap; + float scale; + stbtt_fontinfo info; + stbtt_InitFont(&info, fontdata, stbtt_GetFontOffsetForIndex(fontdata, index)); + scale = size > 0 ? stbtt_ScaleForPixelHeight(&info, size) : stbtt_ScaleForMappingEmToPixels(&info, -size); + stbtt_GetFontVMetrics(&info, &i_ascent, &i_descent, &i_lineGap); + *ascent = (float) i_ascent * scale; + *descent = (float) i_descent * scale; + *lineGap = (float) i_lineGap * scale; +} + +STBTT_DEF void stbtt_GetPackedQuad(const stbtt_packedchar *chardata, int pw, int ph, int char_index, float *xpos, float *ypos, stbtt_aligned_quad *q, int align_to_integer) +{ + float ipw = 1.0f / pw, iph = 1.0f / ph; + const stbtt_packedchar *b = chardata + char_index; + + if (align_to_integer) { + float x = (float) STBTT_ifloor((*xpos + b->xoff) + 0.5f); + float y = (float) STBTT_ifloor((*ypos + b->yoff) + 0.5f); + q->x0 = x; + q->y0 = y; + q->x1 = x + b->xoff2 - b->xoff; + q->y1 = y + b->yoff2 - b->yoff; + } else { + q->x0 = *xpos + b->xoff; + q->y0 = *ypos + b->yoff; + q->x1 = *xpos + b->xoff2; + q->y1 = *ypos + b->yoff2; + } + + q->s0 = b->x0 * ipw; + q->t0 = b->y0 * iph; + q->s1 = b->x1 * ipw; + q->t1 = b->y1 * iph; + + *xpos += b->xadvance; +} + +/* //////////////////////////////////////////////////////////////////////////// */ +/* */ +/* sdf computation */ +/* */ + +#define STBTT_min(a,b) ((a) < (b) ? (a) : (b)) +#define STBTT_max(a,b) ((a) < (b) ? (b) : (a)) + +static int stbtt__ray_intersect_bezier(float orig[2], float ray[2], float q0[2], float q1[2], float q2[2], float hits[2][2]) +{ + float q0perp = q0[1]*ray[0] - q0[0]*ray[1]; + float q1perp = q1[1]*ray[0] - q1[0]*ray[1]; + float q2perp = q2[1]*ray[0] - q2[0]*ray[1]; + float roperp = orig[1]*ray[0] - orig[0]*ray[1]; + + float a = q0perp - 2*q1perp + q2perp; + float b = q1perp - q0perp; + float c = q0perp - roperp; + + float s0 = 0., s1 = 0.; + int num_s = 0; + + if (a != 0.0) { + float discr = b*b - a*c; + if (discr > 0.0) { + float rcpna = -1 / a; + float d = (float) STBTT_sqrt(discr); + s0 = (b+d) * rcpna; + s1 = (b-d) * rcpna; + if (s0 >= 0.0 && s0 <= 1.0) + num_s = 1; + if (d > 0.0 && s1 >= 0.0 && s1 <= 1.0) { + if (num_s == 0) s0 = s1; + ++num_s; + } + } + } else { + /* 2*b*s + c = 0 */ + /* s = -c / (2*b) */ + s0 = c / (-2 * b); + if (s0 >= 0.0 && s0 <= 1.0) + num_s = 1; + } + + if (num_s == 0) + return 0; + else { + float rcp_len2 = 1 / (ray[0]*ray[0] + ray[1]*ray[1]); + float rayn_x = ray[0] * rcp_len2, rayn_y = ray[1] * rcp_len2; + + float q0d = q0[0]*rayn_x + q0[1]*rayn_y; + float q1d = q1[0]*rayn_x + q1[1]*rayn_y; + float q2d = q2[0]*rayn_x + q2[1]*rayn_y; + float rod = orig[0]*rayn_x + orig[1]*rayn_y; + + float q10d = q1d - q0d; + float q20d = q2d - q0d; + float q0rd = q0d - rod; + + hits[0][0] = q0rd + s0*(2.0f - 2.0f*s0)*q10d + s0*s0*q20d; + hits[0][1] = a*s0+b; + + if (num_s > 1) { + hits[1][0] = q0rd + s1*(2.0f - 2.0f*s1)*q10d + s1*s1*q20d; + hits[1][1] = a*s1+b; + return 2; + } else { + return 1; + } + } +} + +static int equal(float *a, float *b) +{ + return (a[0] == b[0] && a[1] == b[1]); +} + +static int stbtt__compute_crossings_x(float x, float y, int nverts, stbtt_vertex *verts) +{ + int i; + float orig[2], ray[2] = { 1, 0 }; + float y_frac; + int winding = 0; + + /* make sure y never passes through a vertex of the shape */ + y_frac = (float) STBTT_fmod(y, 1.0f); + if (y_frac < 0.01f) + y += 0.01f; + else if (y_frac > 0.99f) + y -= 0.01f; + + orig[0] = x; + orig[1] = y; + + /* test a ray from (-infinity,y) to (x,y) */ + for (i=0; i < nverts; ++i) { + if (verts[i].type == STBTT_vline) { + int x0 = (int) verts[i-1].x, y0 = (int) verts[i-1].y; + int x1 = (int) verts[i ].x, y1 = (int) verts[i ].y; + if (y > STBTT_min(y0,y1) && y < STBTT_max(y0,y1) && x > STBTT_min(x0,x1)) { + float x_inter = (y - y0) / (y1 - y0) * (x1-x0) + x0; + if (x_inter < x) + winding += (y0 < y1) ? 1 : -1; + } + } + if (verts[i].type == STBTT_vcurve) { + int x0 = (int) verts[i-1].x , y0 = (int) verts[i-1].y ; + int x1 = (int) verts[i ].cx, y1 = (int) verts[i ].cy; + int x2 = (int) verts[i ].x , y2 = (int) verts[i ].y ; + int ax = STBTT_min(x0,STBTT_min(x1,x2)), ay = STBTT_min(y0,STBTT_min(y1,y2)); + int by = STBTT_max(y0,STBTT_max(y1,y2)); + if (y > ay && y < by && x > ax) { + float q0[2],q1[2],q2[2]; + float hits[2][2]; + q0[0] = (float)x0; + q0[1] = (float)y0; + q1[0] = (float)x1; + q1[1] = (float)y1; + q2[0] = (float)x2; + q2[1] = (float)y2; + if (equal(q0,q1) || equal(q1,q2)) { + x0 = (int)verts[i-1].x; + y0 = (int)verts[i-1].y; + x1 = (int)verts[i ].x; + y1 = (int)verts[i ].y; + if (y > STBTT_min(y0,y1) && y < STBTT_max(y0,y1) && x > STBTT_min(x0,x1)) { + float x_inter = (y - y0) / (y1 - y0) * (x1-x0) + x0; + if (x_inter < x) + winding += (y0 < y1) ? 1 : -1; + } + } else { + int num_hits = stbtt__ray_intersect_bezier(orig, ray, q0, q1, q2, hits); + if (num_hits >= 1) + if (hits[0][0] < 0) + winding += (hits[0][1] < 0 ? -1 : 1); + if (num_hits >= 2) + if (hits[1][0] < 0) + winding += (hits[1][1] < 0 ? -1 : 1); + } + } + } + } + return winding; +} + +static float stbtt__cuberoot( float x ) +{ + if (x<0) + return -(float) STBTT_pow(-x,1.0f/3.0f); + else + return (float) STBTT_pow( x,1.0f/3.0f); +} + +/* x^3 + a*x^2 + b*x + c = 0 */ +static int stbtt__solve_cubic(float a, float b, float c, float* r) +{ + float s = -a / 3; + float p = b - a*a / 3; + float q = a * (2*a*a - 9*b) / 27 + c; + float p3 = p*p*p; + float d = q*q + 4*p3 / 27; + if (d >= 0) { + float z = (float) STBTT_sqrt(d); + float u = (-q + z) / 2; + float v = (-q - z) / 2; + u = stbtt__cuberoot(u); + v = stbtt__cuberoot(v); + r[0] = s + u + v; + return 1; + } else { + float u = (float) STBTT_sqrt(-p/3); + float v = (float) STBTT_acos(-STBTT_sqrt(-27/p3) * q / 2) / 3; /* p3 must be negative, since d is negative */ + float m = (float) STBTT_cos(v); + float n = (float) STBTT_cos(v-3.141592/2)*1.732050808f; + r[0] = s + u * 2 * m; + r[1] = s - u * (m + n); + r[2] = s - u * (m - n); + + /* STBTT_assert( STBTT_fabs(((r[0]+a)*r[0]+b)*r[0]+c) < 0.05f); // these asserts may not be safe at all scales, though they're in bezier t parameter units so maybe? */ + /* STBTT_assert( STBTT_fabs(((r[1]+a)*r[1]+b)*r[1]+c) < 0.05f); */ + /* STBTT_assert( STBTT_fabs(((r[2]+a)*r[2]+b)*r[2]+c) < 0.05f); */ + return 3; + } +} + +STBTT_DEF unsigned char * stbtt_GetGlyphSDF(const stbtt_fontinfo *info, float scale, int glyph, int padding, unsigned char onedge_value, float pixel_dist_scale, int *width, int *height, int *xoff, int *yoff) +{ + float scale_x = scale, scale_y = scale; + int ix0,iy0,ix1,iy1; + int w,h; + unsigned char *data; + + if (scale == 0) return NULL; + + stbtt_GetGlyphBitmapBoxSubpixel(info, glyph, scale, scale, 0.0f,0.0f, &ix0,&iy0,&ix1,&iy1); + + /* if empty, return NULL */ + if (ix0 == ix1 || iy0 == iy1) + return NULL; + + ix0 -= padding; + iy0 -= padding; + ix1 += padding; + iy1 += padding; + + w = (ix1 - ix0); + h = (iy1 - iy0); + + if (width ) *width = w; + if (height) *height = h; + if (xoff ) *xoff = ix0; + if (yoff ) *yoff = iy0; + + /* invert for y-downwards bitmaps */ + scale_y = -scale_y; + + { + int x,y,i,j; + float *precompute; + stbtt_vertex *verts; + int num_verts = stbtt_GetGlyphShape(info, glyph, &verts); + data = (unsigned char *) STBTT_malloc(w * h, info->userdata); + precompute = (float *) STBTT_malloc(num_verts * sizeof(float), info->userdata); + + for (i=0,j=num_verts-1; i < num_verts; j=i++) { + if (verts[i].type == STBTT_vline) { + float x0 = verts[i].x*scale_x, y0 = verts[i].y*scale_y; + float x1 = verts[j].x*scale_x, y1 = verts[j].y*scale_y; + float dist = (float) STBTT_sqrt((x1-x0)*(x1-x0) + (y1-y0)*(y1-y0)); + precompute[i] = (dist == 0) ? 0.0f : 1.0f / dist; + } else if (verts[i].type == STBTT_vcurve) { + float x2 = verts[j].x *scale_x, y2 = verts[j].y *scale_y; + float x1 = verts[i].cx*scale_x, y1 = verts[i].cy*scale_y; + float x0 = verts[i].x *scale_x, y0 = verts[i].y *scale_y; + float bx = x0 - 2*x1 + x2, by = y0 - 2*y1 + y2; + float len2 = bx*bx + by*by; + if (len2 != 0.0f) + precompute[i] = 1.0f / (bx*bx + by*by); + else + precompute[i] = 0.0f; + } else + precompute[i] = 0.0f; + } + + for (y=iy0; y < iy1; ++y) { + for (x=ix0; x < ix1; ++x) { + float val; + float min_dist = 999999.0f; + float sx = (float) x + 0.5f; + float sy = (float) y + 0.5f; + float x_gspace = (sx / scale_x); + float y_gspace = (sy / scale_y); + + int winding = stbtt__compute_crossings_x(x_gspace, y_gspace, num_verts, verts); /* @OPTIMIZE: this could just be a rasterization, but needs to be line vs. non-tesselated curves so a new path */ + + for (i=0; i < num_verts; ++i) { + float x0 = verts[i].x*scale_x, y0 = verts[i].y*scale_y; + + if (verts[i].type == STBTT_vline && precompute[i] != 0.0f) { + float x1 = verts[i-1].x*scale_x, y1 = verts[i-1].y*scale_y; + + float dist,dist2 = (x0-sx)*(x0-sx) + (y0-sy)*(y0-sy); + if (dist2 < min_dist*min_dist) + min_dist = (float) STBTT_sqrt(dist2); + + /* coarse culling against bbox */ + /* if (sx > STBTT_min(x0,x1)-min_dist && sx < STBTT_max(x0,x1)+min_dist && */ + /* sy > STBTT_min(y0,y1)-min_dist && sy < STBTT_max(y0,y1)+min_dist) */ + dist = (float) STBTT_fabs((x1-x0)*(y0-sy) - (y1-y0)*(x0-sx)) * precompute[i]; + STBTT_assert(i != 0); + if (dist < min_dist) { + /* check position along line */ + /* x' = x0 + t*(x1-x0), y' = y0 + t*(y1-y0) */ + /* minimize (x'-sx)*(x'-sx)+(y'-sy)*(y'-sy) */ + float dx = x1-x0, dy = y1-y0; + float px = x0-sx, py = y0-sy; + /* minimize (px+t*dx)^2 + (py+t*dy)^2 = px*px + 2*px*dx*t + t^2*dx*dx + py*py + 2*py*dy*t + t^2*dy*dy */ + /* derivative: 2*px*dx + 2*py*dy + (2*dx*dx+2*dy*dy)*t, set to 0 and solve */ + float t = -(px*dx + py*dy) / (dx*dx + dy*dy); + if (t >= 0.0f && t <= 1.0f) + min_dist = dist; + } + } else if (verts[i].type == STBTT_vcurve) { + float x2 = verts[i-1].x *scale_x, y2 = verts[i-1].y *scale_y; + float x1 = verts[i ].cx*scale_x, y1 = verts[i ].cy*scale_y; + float box_x0 = STBTT_min(STBTT_min(x0,x1),x2); + float box_y0 = STBTT_min(STBTT_min(y0,y1),y2); + float box_x1 = STBTT_max(STBTT_max(x0,x1),x2); + float box_y1 = STBTT_max(STBTT_max(y0,y1),y2); + /* coarse culling against bbox to avoid computing cubic unnecessarily */ + if (sx > box_x0-min_dist && sx < box_x1+min_dist && sy > box_y0-min_dist && sy < box_y1+min_dist) { + int num=0; + float ax = x1-x0, ay = y1-y0; + float bx = x0 - 2*x1 + x2, by = y0 - 2*y1 + y2; + float mx = x0 - sx, my = y0 - sy; + float res[3] = {0.f,0.f,0.f}; + float px,py,t,it,dist2; + float a_inv = precompute[i]; + if (a_inv == 0.0) { /* if a_inv is 0, it's 2nd degree so use quadratic formula */ + float a = 3*(ax*bx + ay*by); + float b = 2*(ax*ax + ay*ay) + (mx*bx+my*by); + float c = mx*ax+my*ay; + if (a == 0.0) { /* if a is 0, it's linear */ + if (b != 0.0) { + res[num++] = -c/b; + } + } else { + float discriminant = b*b - 4*a*c; + if (discriminant < 0) + num = 0; + else { + float root = (float) STBTT_sqrt(discriminant); + res[0] = (-b - root)/(2*a); + res[1] = (-b + root)/(2*a); + num = 2; /* don't bother distinguishing 1-solution case, as code below will still work */ + } + } + } else { + float b = 3*(ax*bx + ay*by) * a_inv; /* could precompute this as it doesn't depend on sample point */ + float c = (2*(ax*ax + ay*ay) + (mx*bx+my*by)) * a_inv; + float d = (mx*ax+my*ay) * a_inv; + num = stbtt__solve_cubic(b, c, d, res); + } + dist2 = (x0-sx)*(x0-sx) + (y0-sy)*(y0-sy); + if (dist2 < min_dist*min_dist) + min_dist = (float) STBTT_sqrt(dist2); + + if (num >= 1 && res[0] >= 0.0f && res[0] <= 1.0f) { + t = res[0], it = 1.0f - t; + px = it*it*x0 + 2*t*it*x1 + t*t*x2; + py = it*it*y0 + 2*t*it*y1 + t*t*y2; + dist2 = (px-sx)*(px-sx) + (py-sy)*(py-sy); + if (dist2 < min_dist * min_dist) + min_dist = (float) STBTT_sqrt(dist2); + } + if (num >= 2 && res[1] >= 0.0f && res[1] <= 1.0f) { + t = res[1], it = 1.0f - t; + px = it*it*x0 + 2*t*it*x1 + t*t*x2; + py = it*it*y0 + 2*t*it*y1 + t*t*y2; + dist2 = (px-sx)*(px-sx) + (py-sy)*(py-sy); + if (dist2 < min_dist * min_dist) + min_dist = (float) STBTT_sqrt(dist2); + } + if (num >= 3 && res[2] >= 0.0f && res[2] <= 1.0f) { + t = res[2], it = 1.0f - t; + px = it*it*x0 + 2*t*it*x1 + t*t*x2; + py = it*it*y0 + 2*t*it*y1 + t*t*y2; + dist2 = (px-sx)*(px-sx) + (py-sy)*(py-sy); + if (dist2 < min_dist * min_dist) + min_dist = (float) STBTT_sqrt(dist2); + } + } + } + } + if (winding == 0) + min_dist = -min_dist; /* if outside the shape, value is negative */ + val = onedge_value + pixel_dist_scale * min_dist; + if (val < 0) + val = 0; + else if (val > 255) + val = 255; + data[(y-iy0)*w+(x-ix0)] = (unsigned char) val; + } + } + STBTT_free(precompute, info->userdata); + STBTT_free(verts, info->userdata); + } + return data; +} + +STBTT_DEF unsigned char * stbtt_GetCodepointSDF(const stbtt_fontinfo *info, float scale, int codepoint, int padding, unsigned char onedge_value, float pixel_dist_scale, int *width, int *height, int *xoff, int *yoff) +{ + return stbtt_GetGlyphSDF(info, scale, stbtt_FindGlyphIndex(info, codepoint), padding, onedge_value, pixel_dist_scale, width, height, xoff, yoff); +} + +STBTT_DEF void stbtt_FreeSDF(unsigned char *bitmap, void *userdata) +{ + STBTT_free(bitmap, userdata); +} + +/* //////////////////////////////////////////////////////////////////////////// */ +/* */ +/* font name matching -- recommended not to use this */ +/* */ + +/* check if a utf8 string contains a prefix which is the utf16 string; if so return length of matching utf8 string */ +static stbtt_int32 stbtt__CompareUTF8toUTF16_bigendian_prefix(stbtt_uint8 *s1, stbtt_int32 len1, stbtt_uint8 *s2, stbtt_int32 len2) +{ + stbtt_int32 i=0; + + /* convert utf16 to utf8 and compare the results while converting */ + while (len2) { + stbtt_uint16 ch = s2[0]*256 + s2[1]; + if (ch < 0x80) { + if (i >= len1) return -1; + if (s1[i++] != ch) return -1; + } else if (ch < 0x800) { + if (i+1 >= len1) return -1; + if (s1[i++] != 0xc0 + (ch >> 6)) return -1; + if (s1[i++] != 0x80 + (ch & 0x3f)) return -1; + } else if (ch >= 0xd800 && ch < 0xdc00) { + stbtt_uint32 c; + stbtt_uint16 ch2 = s2[2]*256 + s2[3]; + if (i+3 >= len1) return -1; + c = ((ch - 0xd800) << 10) + (ch2 - 0xdc00) + 0x10000; + if (s1[i++] != 0xf0 + (c >> 18)) return -1; + if (s1[i++] != 0x80 + ((c >> 12) & 0x3f)) return -1; + if (s1[i++] != 0x80 + ((c >> 6) & 0x3f)) return -1; + if (s1[i++] != 0x80 + ((c ) & 0x3f)) return -1; + s2 += 2; /* plus another 2 below */ + len2 -= 2; + } else if (ch >= 0xdc00 && ch < 0xe000) { + return -1; + } else { + if (i+2 >= len1) return -1; + if (s1[i++] != 0xe0 + (ch >> 12)) return -1; + if (s1[i++] != 0x80 + ((ch >> 6) & 0x3f)) return -1; + if (s1[i++] != 0x80 + ((ch ) & 0x3f)) return -1; + } + s2 += 2; + len2 -= 2; + } + return i; +} + +static int stbtt_CompareUTF8toUTF16_bigendian_internal(char *s1, int len1, char *s2, int len2) +{ + return len1 == stbtt__CompareUTF8toUTF16_bigendian_prefix((stbtt_uint8*) s1, len1, (stbtt_uint8*) s2, len2); +} + +/* returns results in whatever encoding you request... but note that 2-byte encodings */ +/* will be BIG-ENDIAN... use stbtt_CompareUTF8toUTF16_bigendian() to compare */ +STBTT_DEF const char *stbtt_GetFontNameString(const stbtt_fontinfo *font, int *length, int platformID, int encodingID, int languageID, int nameID) +{ + stbtt_int32 i,count,stringOffset; + stbtt_uint8 *fc = font->data; + stbtt_uint32 offset = font->fontstart; + stbtt_uint32 nm = stbtt__find_table(fc, offset, "name"); + if (!nm) return NULL; + + count = ttUSHORT(fc+nm+2); + stringOffset = nm + ttUSHORT(fc+nm+4); + for (i=0; i < count; ++i) { + stbtt_uint32 loc = nm + 6 + 12 * i; + if (platformID == ttUSHORT(fc+loc+0) && encodingID == ttUSHORT(fc+loc+2) + && languageID == ttUSHORT(fc+loc+4) && nameID == ttUSHORT(fc+loc+6)) { + *length = ttUSHORT(fc+loc+8); + return (const char *) (fc+stringOffset+ttUSHORT(fc+loc+10)); + } + } + return NULL; +} + +static int stbtt__matchpair(stbtt_uint8 *fc, stbtt_uint32 nm, stbtt_uint8 *name, stbtt_int32 nlen, stbtt_int32 target_id, stbtt_int32 next_id) +{ + stbtt_int32 i; + stbtt_int32 count = ttUSHORT(fc+nm+2); + stbtt_int32 stringOffset = nm + ttUSHORT(fc+nm+4); + + for (i=0; i < count; ++i) { + stbtt_uint32 loc = nm + 6 + 12 * i; + stbtt_int32 id = ttUSHORT(fc+loc+6); + if (id == target_id) { + /* find the encoding */ + stbtt_int32 platform = ttUSHORT(fc+loc+0), encoding = ttUSHORT(fc+loc+2), language = ttUSHORT(fc+loc+4); + + /* is this a Unicode encoding? */ + if (platform == 0 || (platform == 3 && encoding == 1) || (platform == 3 && encoding == 10)) { + stbtt_int32 slen = ttUSHORT(fc+loc+8); + stbtt_int32 off = ttUSHORT(fc+loc+10); + + /* check if there's a prefix match */ + stbtt_int32 matchlen = stbtt__CompareUTF8toUTF16_bigendian_prefix(name, nlen, fc+stringOffset+off,slen); + if (matchlen >= 0) { + /* check for target_id+1 immediately following, with same encoding & language */ + if (i+1 < count && ttUSHORT(fc+loc+12+6) == next_id && ttUSHORT(fc+loc+12) == platform && ttUSHORT(fc+loc+12+2) == encoding && ttUSHORT(fc+loc+12+4) == language) { + slen = ttUSHORT(fc+loc+12+8); + off = ttUSHORT(fc+loc+12+10); + if (slen == 0) { + if (matchlen == nlen) + return 1; + } else if (matchlen < nlen && name[matchlen] == ' ') { + ++matchlen; + if (stbtt_CompareUTF8toUTF16_bigendian_internal((char*) (name+matchlen), nlen-matchlen, (char*)(fc+stringOffset+off),slen)) + return 1; + } + } else { + /* if nothing immediately following */ + if (matchlen == nlen) + return 1; + } + } + } + + /* @TODO handle other encodings */ + } + } + return 0; +} + +static int stbtt__matches(stbtt_uint8 *fc, stbtt_uint32 offset, stbtt_uint8 *name, stbtt_int32 flags) +{ + stbtt_int32 nlen = (stbtt_int32) STBTT_strlen((char *) name); + stbtt_uint32 nm,hd; + if (!stbtt__isfont(fc+offset)) return 0; + + /* check italics/bold/underline flags in macStyle... */ + if (flags) { + hd = stbtt__find_table(fc, offset, "head"); + if ((ttUSHORT(fc+hd+44) & 7) != (flags & 7)) return 0; + } + + nm = stbtt__find_table(fc, offset, "name"); + if (!nm) return 0; + + if (flags) { + /* if we checked the macStyle flags, then just check the family and ignore the subfamily */ + if (stbtt__matchpair(fc, nm, name, nlen, 16, -1)) return 1; + if (stbtt__matchpair(fc, nm, name, nlen, 1, -1)) return 1; + if (stbtt__matchpair(fc, nm, name, nlen, 3, -1)) return 1; + } else { + if (stbtt__matchpair(fc, nm, name, nlen, 16, 17)) return 1; + if (stbtt__matchpair(fc, nm, name, nlen, 1, 2)) return 1; + if (stbtt__matchpair(fc, nm, name, nlen, 3, -1)) return 1; + } + + return 0; +} + +static int stbtt_FindMatchingFont_internal(unsigned char *font_collection, char *name_utf8, stbtt_int32 flags) +{ + stbtt_int32 i; + for (i=0;;++i) { + stbtt_int32 off = stbtt_GetFontOffsetForIndex(font_collection, i); + if (off < 0) return off; + if (stbtt__matches((stbtt_uint8 *) font_collection, off, (stbtt_uint8*) name_utf8, flags)) + return off; + } +} + +#if defined(__GNUC__) || defined(__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wcast-qual" +#endif + +STBTT_DEF int stbtt_BakeFontBitmap(const unsigned char *data, int offset, + float pixel_height, unsigned char *pixels, int pw, int ph, + int first_char, int num_chars, stbtt_bakedchar *chardata) +{ + return stbtt_BakeFontBitmap_internal((unsigned char *) data, offset, pixel_height, pixels, pw, ph, first_char, num_chars, chardata); +} + +STBTT_DEF int stbtt_GetFontOffsetForIndex(const unsigned char *data, int index) +{ + return stbtt_GetFontOffsetForIndex_internal((unsigned char *) data, index); +} + +STBTT_DEF int stbtt_GetNumberOfFonts(const unsigned char *data) +{ + return stbtt_GetNumberOfFonts_internal((unsigned char *) data); +} + +STBTT_DEF int stbtt_InitFont(stbtt_fontinfo *info, const unsigned char *data, int offset) +{ + return stbtt_InitFont_internal(info, (unsigned char *) data, offset); +} + +STBTT_DEF int stbtt_FindMatchingFont(const unsigned char *fontdata, const char *name, int flags) +{ + return stbtt_FindMatchingFont_internal((unsigned char *) fontdata, (char *) name, flags); +} + +STBTT_DEF int stbtt_CompareUTF8toUTF16_bigendian(const char *s1, int len1, const char *s2, int len2) +{ + return stbtt_CompareUTF8toUTF16_bigendian_internal((char *) s1, len1, (char *) s2, len2); +} + +#if defined(__GNUC__) || defined(__clang__) +#pragma GCC diagnostic pop +#endif + +#endif /* STB_TRUETYPE_IMPLEMENTATION */ + + +/* FULL VERSION HISTORY */ +/* */ +/* 1.25 (2021-07-11) many fixes */ +/* 1.24 (2020-02-05) fix warning */ +/* 1.23 (2020-02-02) query SVG data for glyphs; query whole kerning table (but only kern not GPOS) */ +/* 1.22 (2019-08-11) minimize missing-glyph duplication; fix kerning if both 'GPOS' and 'kern' are defined */ +/* 1.21 (2019-02-25) fix warning */ +/* 1.20 (2019-02-07) PackFontRange skips missing codepoints; GetScaleFontVMetrics() */ +/* 1.19 (2018-02-11) OpenType GPOS kerning (horizontal only), STBTT_fmod */ +/* 1.18 (2018-01-29) add missing function */ +/* 1.17 (2017-07-23) make more arguments const; doc fix */ +/* 1.16 (2017-07-12) SDF support */ +/* 1.15 (2017-03-03) make more arguments const */ +/* 1.14 (2017-01-16) num-fonts-in-TTC function */ +/* 1.13 (2017-01-02) support OpenType fonts, certain Apple fonts */ +/* 1.12 (2016-10-25) suppress warnings about casting away const with -Wcast-qual */ +/* 1.11 (2016-04-02) fix unused-variable warning */ +/* 1.10 (2016-04-02) allow user-defined fabs() replacement */ +/* fix memory leak if fontsize=0.0 */ +/* fix warning from duplicate typedef */ +/* 1.09 (2016-01-16) warning fix; avoid crash on outofmem; use alloc userdata for PackFontRanges */ +/* 1.08 (2015-09-13) document stbtt_Rasterize(); fixes for vertical & horizontal edges */ +/* 1.07 (2015-08-01) allow PackFontRanges to accept arrays of sparse codepoints; */ +/* allow PackFontRanges to pack and render in separate phases; */ +/* fix stbtt_GetFontOFfsetForIndex (never worked for non-0 input?); */ +/* fixed an assert() bug in the new rasterizer */ +/* replace assert() with STBTT_assert() in new rasterizer */ +/* 1.06 (2015-07-14) performance improvements (~35% faster on x86 and x64 on test machine) */ +/* also more precise AA rasterizer, except if shapes overlap */ +/* remove need for STBTT_sort */ +/* 1.05 (2015-04-15) fix misplaced definitions for STBTT_STATIC */ +/* 1.04 (2015-04-15) typo in example */ +/* 1.03 (2015-04-12) STBTT_STATIC, fix memory leak in new packing, various fixes */ +/* 1.02 (2014-12-10) fix various warnings & compile issues w/ stb_rect_pack, C++ */ +/* 1.01 (2014-12-08) fix subpixel position when oversampling to exactly match */ +/* non-oversampled; STBTT_POINT_SIZE for packed case only */ +/* 1.00 (2014-12-06) add new PackBegin etc. API, w/ support for oversampling */ +/* 0.99 (2014-09-18) fix multiple bugs with subpixel rendering (ryg) */ +/* 0.9 (2014-08-07) support certain mac/iOS fonts without an MS platformID */ +/* 0.8b (2014-07-07) fix a warning */ +/* 0.8 (2014-05-25) fix a few more warnings */ +/* 0.7 (2013-09-25) bugfix: subpixel glyph bug fixed in 0.5 had come back */ +/* 0.6c (2012-07-24) improve documentation */ +/* 0.6b (2012-07-20) fix a few more warnings */ +/* 0.6 (2012-07-17) fix warnings; added stbtt_ScaleForMappingEmToPixels, */ +/* stbtt_GetFontBoundingBox, stbtt_IsGlyphEmpty */ +/* 0.5 (2011-12-09) bugfixes: */ +/* subpixel glyph renderer computed wrong bounding box */ +/* first vertex of shape can be off-curve (FreeSans) */ +/* 0.4b (2011-12-03) fixed an error in the font baking example */ +/* 0.4 (2011-12-01) kerning, subpixel rendering (tor) */ +/* bugfixes for: */ +/* codepoint-to-glyph conversion using table fmt=12 */ +/* codepoint-to-glyph conversion using table fmt=4 */ +/* stbtt_GetBakedQuad with non-square texture (Zer) */ +/* updated Hello World! sample to use kerning and subpixel */ +/* fixed some warnings */ +/* 0.3 (2009-06-24) cmap fmt=12, compound shapes (MM) */ +/* userdata, malloc-from-userdata, non-zero fill (stb) */ +/* 0.2 (2009-03-11) Fix unsigned/signed char warnings */ +/* 0.1 (2009-03-09) First public release */ +/* */ + +/* +------------------------------------------------------------------------------ +This software is available under 2 licenses -- choose whichever you prefer. +------------------------------------------------------------------------------ +ALTERNATIVE A - MIT License +Copyright (c) 2017 Sean Barrett +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +------------------------------------------------------------------------------ +ALTERNATIVE B - Public Domain (www.unlicense.org) +This is free and unencumbered software released into the public domain. +Anyone is free to copy, modify, publish, use, compile, sell, or distribute this +software, either in source code form or as a compiled binary, for any purpose, +commercial or non-commercial, and by any means. +In jurisdictions that recognize copyright laws, the author or authors of this +software dedicate any and all copyright interest in the software to the public +domain. We make this dedication for the benefit of the public at large and to +the detriment of our heirs and successors. We intend this dedication to be an +overt act of relinquishment in perpetuity of all present and future rights to +this software under copyright law. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +------------------------------------------------------------------------------ +*/ + + + + +#ifdef NK_INCLUDE_FONT_BAKING +/* ------------------------------------------------------------- + * + * RECT PACK + * + * --------------------------------------------------------------*/ + + + +/* + * ============================================================== + * + * TRUETYPE + * + * =============================================================== + */ +#define STBTT_MAX_OVERSAMPLE 8 + + +/* ------------------------------------------------------------- + * + * FONT BAKING + * + * --------------------------------------------------------------*/ +struct nk_font_bake_data { + struct stbtt_fontinfo info; + struct stbrp_rect *rects; + stbtt_pack_range *ranges; + nk_rune range_count; +}; + +struct nk_font_baker { + struct nk_allocator alloc; + struct stbtt_pack_context spc; + struct nk_font_bake_data *build; + stbtt_packedchar *packed_chars; + struct stbrp_rect *rects; + stbtt_pack_range *ranges; +}; + +NK_GLOBAL const nk_size nk_rect_align = NK_ALIGNOF(struct stbrp_rect); +NK_GLOBAL const nk_size nk_range_align = NK_ALIGNOF(stbtt_pack_range); +NK_GLOBAL const nk_size nk_char_align = NK_ALIGNOF(stbtt_packedchar); +NK_GLOBAL const nk_size nk_build_align = NK_ALIGNOF(struct nk_font_bake_data); +NK_GLOBAL const nk_size nk_baker_align = NK_ALIGNOF(struct nk_font_baker); + +NK_INTERN int +nk_range_count(const nk_rune *range) +{ + const nk_rune *iter = range; + NK_ASSERT(range); + if (!range) return 0; + while (*(iter++) != 0); + return (iter == range) ? 0 : (int)((iter - range)/2); +} +NK_INTERN int +nk_range_glyph_count(const nk_rune *range, int count) +{ + int i = 0; + int total_glyphs = 0; + for (i = 0; i < count; ++i) { + int diff; + nk_rune f = range[(i*2)+0]; + nk_rune t = range[(i*2)+1]; + NK_ASSERT(t >= f); + diff = (int)((t - f) + 1); + total_glyphs += diff; + } + return total_glyphs; +} +NK_API const nk_rune* +nk_font_default_glyph_ranges(void) +{ + NK_STORAGE const nk_rune ranges[] = {0x0020, 0x00FF, 0}; + return ranges; +} +NK_API const nk_rune* +nk_font_chinese_glyph_ranges(void) +{ + NK_STORAGE const nk_rune ranges[] = { + 0x0020, 0x00FF, + 0x3000, 0x30FF, + 0x31F0, 0x31FF, + 0xFF00, 0xFFEF, + 0x4E00, 0x9FAF, + 0 + }; + return ranges; +} +NK_API const nk_rune* +nk_font_cyrillic_glyph_ranges(void) +{ + NK_STORAGE const nk_rune ranges[] = { + 0x0020, 0x00FF, + 0x0400, 0x052F, + 0x2DE0, 0x2DFF, + 0xA640, 0xA69F, + 0 + }; + return ranges; +} +NK_API const nk_rune* +nk_font_korean_glyph_ranges(void) +{ + NK_STORAGE const nk_rune ranges[] = { + 0x0020, 0x00FF, + 0x3131, 0x3163, + 0xAC00, 0xD79D, + 0 + }; + return ranges; +} +NK_INTERN void +nk_font_baker_memory(nk_size *temp, int *glyph_count, + struct nk_font_config *config_list, int count) +{ + int range_count = 0; + int total_range_count = 0; + struct nk_font_config *iter, *i; + + NK_ASSERT(config_list); + NK_ASSERT(glyph_count); + if (!config_list) { + *temp = 0; + *glyph_count = 0; + return; + } + *glyph_count = 0; + for (iter = config_list; iter; iter = iter->next) { + i = iter; + do {if (!i->range) iter->range = nk_font_default_glyph_ranges(); + range_count = nk_range_count(i->range); + total_range_count += range_count; + *glyph_count += nk_range_glyph_count(i->range, range_count); + } while ((i = i->n) != iter); + } + *temp = (nk_size)*glyph_count * sizeof(struct stbrp_rect); + *temp += (nk_size)total_range_count * sizeof(stbtt_pack_range); + *temp += (nk_size)*glyph_count * sizeof(stbtt_packedchar); + *temp += (nk_size)count * sizeof(struct nk_font_bake_data); + *temp += sizeof(struct nk_font_baker); + *temp += nk_rect_align + nk_range_align + nk_char_align; + *temp += nk_build_align + nk_baker_align; +} +NK_INTERN struct nk_font_baker* +nk_font_baker(void *memory, int glyph_count, int count, struct nk_allocator *alloc) +{ + struct nk_font_baker *baker; + if (!memory) return 0; + /* setup baker inside a memory block */ + baker = (struct nk_font_baker*)NK_ALIGN_PTR(memory, nk_baker_align); + baker->build = (struct nk_font_bake_data*)NK_ALIGN_PTR((baker + 1), nk_build_align); + baker->packed_chars = (stbtt_packedchar*)NK_ALIGN_PTR((baker->build + count), nk_char_align); + baker->rects = (struct stbrp_rect*)NK_ALIGN_PTR((baker->packed_chars + glyph_count), nk_rect_align); + baker->ranges = (stbtt_pack_range*)NK_ALIGN_PTR((baker->rects + glyph_count), nk_range_align); + baker->alloc = *alloc; + return baker; +} +NK_INTERN int +nk_font_bake_pack(struct nk_font_baker *baker, + nk_size *image_memory, int *width, int *height, struct nk_recti *custom, + const struct nk_font_config *config_list, int count, + struct nk_allocator *alloc) +{ + NK_STORAGE const nk_size max_height = 1024 * 32; + const struct nk_font_config *config_iter, *it; + int total_glyph_count = 0; + int total_range_count = 0; + int range_count = 0; + int i = 0; + + NK_ASSERT(image_memory); + NK_ASSERT(width); + NK_ASSERT(height); + NK_ASSERT(config_list); + NK_ASSERT(count); + NK_ASSERT(alloc); + + if (!image_memory || !width || !height || !config_list || !count) return nk_false; + for (config_iter = config_list; config_iter; config_iter = config_iter->next) { + it = config_iter; + do {range_count = nk_range_count(it->range); + total_range_count += range_count; + total_glyph_count += nk_range_glyph_count(it->range, range_count); + } while ((it = it->n) != config_iter); + } + /* setup font baker from temporary memory */ + for (config_iter = config_list; config_iter; config_iter = config_iter->next) { + it = config_iter; + do { + struct stbtt_fontinfo *font_info = &baker->build[i++].info; + font_info->userdata = alloc; + + if (!stbtt_InitFont(font_info, (const unsigned char*)it->ttf_blob, stbtt_GetFontOffsetForIndex((const unsigned char*)it->ttf_blob, 0))) + return nk_false; + } while ((it = it->n) != config_iter); + } + *height = 0; + *width = (total_glyph_count > 1000) ? 1024 : 512; + stbtt_PackBegin(&baker->spc, 0, (int)*width, (int)max_height, 0, 1, alloc); + { + int input_i = 0; + int range_n = 0; + int rect_n = 0; + int char_n = 0; + + if (custom) { + /* pack custom user data first so it will be in the upper left corner*/ + struct stbrp_rect custom_space; + nk_zero(&custom_space, sizeof(custom_space)); + custom_space.w = (stbrp_coord)(custom->w); + custom_space.h = (stbrp_coord)(custom->h); + + stbtt_PackSetOversampling(&baker->spc, 1, 1); + stbrp_pack_rects((struct stbrp_context*)baker->spc.pack_info, &custom_space, 1); + *height = NK_MAX(*height, (int)(custom_space.y + custom_space.h)); + + custom->x = (short)custom_space.x; + custom->y = (short)custom_space.y; + custom->w = (short)custom_space.w; + custom->h = (short)custom_space.h; + } + + /* first font pass: pack all glyphs */ + for (input_i = 0, config_iter = config_list; input_i < count && config_iter; + config_iter = config_iter->next) { + it = config_iter; + do {int n = 0; + int glyph_count; + const nk_rune *in_range; + const struct nk_font_config *cfg = it; + struct nk_font_bake_data *tmp = &baker->build[input_i++]; + + /* count glyphs + ranges in current font */ + glyph_count = 0; range_count = 0; + for (in_range = cfg->range; in_range[0] && in_range[1]; in_range += 2) { + glyph_count += (int)(in_range[1] - in_range[0]) + 1; + range_count++; + } + + /* setup ranges */ + tmp->ranges = baker->ranges + range_n; + tmp->range_count = (nk_rune)range_count; + range_n += range_count; + for (i = 0; i < range_count; ++i) { + in_range = &cfg->range[i * 2]; + tmp->ranges[i].font_size = cfg->size; + tmp->ranges[i].first_unicode_codepoint_in_range = (int)in_range[0]; + tmp->ranges[i].num_chars = (int)(in_range[1]- in_range[0]) + 1; + tmp->ranges[i].chardata_for_range = baker->packed_chars + char_n; + char_n += tmp->ranges[i].num_chars; + } + + /* pack */ + tmp->rects = baker->rects + rect_n; + rect_n += glyph_count; + stbtt_PackSetOversampling(&baker->spc, cfg->oversample_h, cfg->oversample_v); + n = stbtt_PackFontRangesGatherRects(&baker->spc, &tmp->info, + tmp->ranges, (int)tmp->range_count, tmp->rects); + stbrp_pack_rects((struct stbrp_context*)baker->spc.pack_info, tmp->rects, (int)n); + + /* texture height */ + for (i = 0; i < n; ++i) { + if (tmp->rects[i].was_packed) + *height = NK_MAX(*height, tmp->rects[i].y + tmp->rects[i].h); + } + } while ((it = it->n) != config_iter); + } + NK_ASSERT(rect_n == total_glyph_count); + NK_ASSERT(char_n == total_glyph_count); + NK_ASSERT(range_n == total_range_count); + } + *height = (int)nk_round_up_pow2((nk_uint)*height); + *image_memory = (nk_size)(*width) * (nk_size)(*height); + return nk_true; +} +NK_INTERN void +nk_font_bake(struct nk_font_baker *baker, void *image_memory, int width, int height, + struct nk_font_glyph *glyphs, int glyphs_count, + const struct nk_font_config *config_list, int font_count) +{ + int input_i = 0; + nk_rune glyph_n = 0; + const struct nk_font_config *config_iter; + const struct nk_font_config *it; + + NK_ASSERT(image_memory); + NK_ASSERT(width); + NK_ASSERT(height); + NK_ASSERT(config_list); + NK_ASSERT(baker); + NK_ASSERT(font_count); + NK_ASSERT(glyphs_count); + if (!image_memory || !width || !height || !config_list || + !font_count || !glyphs || !glyphs_count) + return; + + /* second font pass: render glyphs */ + nk_zero(image_memory, (nk_size)((nk_size)width * (nk_size)height)); + baker->spc.pixels = (unsigned char*)image_memory; + baker->spc.height = (int)height; + for (input_i = 0, config_iter = config_list; input_i < font_count && config_iter; + config_iter = config_iter->next) { + it = config_iter; + do {const struct nk_font_config *cfg = it; + struct nk_font_bake_data *tmp = &baker->build[input_i++]; + stbtt_PackSetOversampling(&baker->spc, cfg->oversample_h, cfg->oversample_v); + stbtt_PackFontRangesRenderIntoRects(&baker->spc, &tmp->info, tmp->ranges, (int)tmp->range_count, tmp->rects); + } while ((it = it->n) != config_iter); + } stbtt_PackEnd(&baker->spc); + + /* third pass: setup font and glyphs */ + for (input_i = 0, config_iter = config_list; input_i < font_count && config_iter; + config_iter = config_iter->next) { + it = config_iter; + do {nk_size i = 0; + int char_idx = 0; + nk_rune glyph_count = 0; + const struct nk_font_config *cfg = it; + struct nk_font_bake_data *tmp = &baker->build[input_i++]; + struct nk_baked_font *dst_font = cfg->font; + + float font_scale = stbtt_ScaleForPixelHeight(&tmp->info, cfg->size); + int unscaled_ascent, unscaled_descent, unscaled_line_gap; + stbtt_GetFontVMetrics(&tmp->info, &unscaled_ascent, &unscaled_descent, + &unscaled_line_gap); + + /* fill baked font */ + if (!cfg->merge_mode) { + dst_font->ranges = cfg->range; + dst_font->height = cfg->size; + dst_font->ascent = ((float)unscaled_ascent * font_scale); + dst_font->descent = ((float)unscaled_descent * font_scale); + dst_font->glyph_offset = glyph_n; + /* + Need to zero this, or it will carry over from a previous + bake, and cause a segfault when accessing glyphs[]. + */ + dst_font->glyph_count = 0; + } + + /* fill own baked font glyph array */ + for (i = 0; i < tmp->range_count; ++i) { + stbtt_pack_range *range = &tmp->ranges[i]; + for (char_idx = 0; char_idx < range->num_chars; char_idx++) + { + nk_rune codepoint = 0; + float dummy_x = 0, dummy_y = 0; + stbtt_aligned_quad q; + struct nk_font_glyph *glyph; + + /* query glyph bounds from stb_truetype */ + const stbtt_packedchar *pc = &range->chardata_for_range[char_idx]; + codepoint = (nk_rune)(range->first_unicode_codepoint_in_range + char_idx); + stbtt_GetPackedQuad(range->chardata_for_range, (int)width, + (int)height, char_idx, &dummy_x, &dummy_y, &q, 0); + + /* fill own glyph type with data */ + glyph = &glyphs[dst_font->glyph_offset + dst_font->glyph_count + (unsigned int)glyph_count]; + glyph->codepoint = codepoint; + glyph->x0 = q.x0; glyph->y0 = q.y0; + glyph->x1 = q.x1; glyph->y1 = q.y1; + glyph->y0 += (dst_font->ascent + 0.5f); + glyph->y1 += (dst_font->ascent + 0.5f); + glyph->w = glyph->x1 - glyph->x0 + 0.5f; + glyph->h = glyph->y1 - glyph->y0; + + if (cfg->coord_type == NK_COORD_PIXEL) { + glyph->u0 = q.s0 * (float)width; + glyph->v0 = q.t0 * (float)height; + glyph->u1 = q.s1 * (float)width; + glyph->v1 = q.t1 * (float)height; + } else { + glyph->u0 = q.s0; + glyph->v0 = q.t0; + glyph->u1 = q.s1; + glyph->v1 = q.t1; + } + glyph->xadvance = (pc->xadvance + cfg->spacing.x); + if (cfg->pixel_snap) + glyph->xadvance = (float)(int)(glyph->xadvance + 0.5f); + glyph_count++; + } + } + dst_font->glyph_count += glyph_count; + glyph_n += glyph_count; + } while ((it = it->n) != config_iter); + } +} +NK_INTERN void +nk_font_bake_custom_data(void *img_memory, int img_width, int img_height, + struct nk_recti img_dst, const char *texture_data_mask, int tex_width, + int tex_height, char white, char black) +{ + nk_byte *pixels; + int y = 0; + int x = 0; + int n = 0; + + NK_ASSERT(img_memory); + NK_ASSERT(img_width); + NK_ASSERT(img_height); + NK_ASSERT(texture_data_mask); + NK_UNUSED(tex_height); + if (!img_memory || !img_width || !img_height || !texture_data_mask) + return; + + pixels = (nk_byte*)img_memory; + for (y = 0, n = 0; y < tex_height; ++y) { + for (x = 0; x < tex_width; ++x, ++n) { + const int off0 = ((img_dst.x + x) + (img_dst.y + y) * img_width); + const int off1 = off0 + 1 + tex_width; + pixels[off0] = (texture_data_mask[n] == white) ? 0xFF : 0x00; + pixels[off1] = (texture_data_mask[n] == black) ? 0xFF : 0x00; + } + } +} +NK_INTERN void +nk_font_bake_convert(void *out_memory, int img_width, int img_height, + const void *in_memory) +{ + int n = 0; + nk_rune *dst; + const nk_byte *src; + + NK_ASSERT(out_memory); + NK_ASSERT(in_memory); + NK_ASSERT(img_width); + NK_ASSERT(img_height); + if (!out_memory || !in_memory || !img_height || !img_width) return; + + dst = (nk_rune*)out_memory; + src = (const nk_byte*)in_memory; + for (n = (int)(img_width * img_height); n > 0; n--) + *dst++ = ((nk_rune)(*src++) << 24) | 0x00FFFFFF; +} + +/* ------------------------------------------------------------- + * + * FONT + * + * --------------------------------------------------------------*/ +NK_INTERN float +nk_font_text_width(nk_handle handle, float height, const char *text, int len) +{ + nk_rune unicode; + int text_len = 0; + float text_width = 0; + int glyph_len = 0; + float scale = 0; + + struct nk_font *font = (struct nk_font*)handle.ptr; + NK_ASSERT(font); + NK_ASSERT(font->glyphs); + if (!font || !text || !len) + return 0; + + scale = height/font->info.height; + glyph_len = text_len = nk_utf_decode(text, &unicode, (int)len); + if (!glyph_len) return 0; + while (text_len <= (int)len && glyph_len) { + const struct nk_font_glyph *g; + if (unicode == NK_UTF_INVALID) break; + + /* query currently drawn glyph information */ + g = nk_font_find_glyph(font, unicode); + text_width += g->xadvance * scale; + + /* offset next glyph */ + glyph_len = nk_utf_decode(text + text_len, &unicode, (int)len - text_len); + text_len += glyph_len; + } + return text_width; +} +#ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT +NK_INTERN void +nk_font_query_font_glyph(nk_handle handle, float height, + struct nk_user_font_glyph *glyph, nk_rune codepoint, nk_rune next_codepoint) +{ + float scale; + const struct nk_font_glyph *g; + struct nk_font *font; + + NK_ASSERT(glyph); + NK_UNUSED(next_codepoint); + + font = (struct nk_font*)handle.ptr; + NK_ASSERT(font); + NK_ASSERT(font->glyphs); + if (!font || !glyph) + return; + + scale = height/font->info.height; + g = nk_font_find_glyph(font, codepoint); + glyph->width = (g->x1 - g->x0) * scale; + glyph->height = (g->y1 - g->y0) * scale; + glyph->offset = nk_vec2(g->x0 * scale, g->y0 * scale); + glyph->xadvance = (g->xadvance * scale); + glyph->uv[0] = nk_vec2(g->u0, g->v0); + glyph->uv[1] = nk_vec2(g->u1, g->v1); +} +#endif +NK_API const struct nk_font_glyph* +nk_font_find_glyph(struct nk_font *font, nk_rune unicode) +{ + int i = 0; + int count; + int total_glyphs = 0; + const struct nk_font_glyph *glyph = 0; + const struct nk_font_config *iter = 0; + + NK_ASSERT(font); + NK_ASSERT(font->glyphs); + NK_ASSERT(font->info.ranges); + if (!font || !font->glyphs) return 0; + + glyph = font->fallback; + iter = font->config; + do {count = nk_range_count(iter->range); + for (i = 0; i < count; ++i) { + nk_rune f = iter->range[(i*2)+0]; + nk_rune t = iter->range[(i*2)+1]; + int diff = (int)((t - f) + 1); + if (unicode >= f && unicode <= t) + return &font->glyphs[((nk_rune)total_glyphs + (unicode - f))]; + total_glyphs += diff; + } + } while ((iter = iter->n) != font->config); + return glyph; +} +NK_INTERN void +nk_font_init(struct nk_font *font, float pixel_height, + nk_rune fallback_codepoint, struct nk_font_glyph *glyphs, + const struct nk_baked_font *baked_font, nk_handle atlas) +{ + struct nk_baked_font baked; + NK_ASSERT(font); + NK_ASSERT(glyphs); + NK_ASSERT(baked_font); + if (!font || !glyphs || !baked_font) + return; + + baked = *baked_font; + font->fallback = 0; + font->info = baked; + font->scale = (float)pixel_height / (float)font->info.height; + font->glyphs = &glyphs[baked_font->glyph_offset]; + font->texture = atlas; + font->fallback_codepoint = fallback_codepoint; + font->fallback = nk_font_find_glyph(font, fallback_codepoint); + + font->handle.height = font->info.height * font->scale; + font->handle.width = nk_font_text_width; + font->handle.userdata.ptr = font; +#ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT + font->handle.query = nk_font_query_font_glyph; + font->handle.texture = font->texture; +#endif +} + +/* --------------------------------------------------------------------------- + * + * DEFAULT FONT + * + * ProggyClean.ttf + * Copyright (c) 2004, 2005 Tristan Grimmer + * MIT license (see License.txt in http://www.upperbounds.net/download/ProggyClean.ttf.zip) + * Download and more information at http://upperbounds.net + *-----------------------------------------------------------------------------*/ +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Woverlength-strings" +#elif defined(__GNUC__) || defined(__GNUG__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Woverlength-strings" +#endif + +#ifdef NK_INCLUDE_DEFAULT_FONT + +NK_GLOBAL const char nk_proggy_clean_ttf_compressed_data_base85[11980+1] = + "7])#######hV0qs'/###[),##/l:$#Q6>##5[n42>c-TH`->>#/e>11NNV=Bv(*:.F?uu#(gRU.o0XGH`$vhLG1hxt9?W`#,5LsCp#-i>.r$<$6pD>Lb';9Crc6tgXmKVeU2cD4Eo3R/" + "2*>]b(MC;$jPfY.;h^`IWM9Qo#t'X#(v#Y9w0#1D$CIf;W'#pWUPXOuxXuU(H9M(1=Ke$$'5F%)]0^#0X@U.a$FBjVQTSDgEKnIS7EM9>ZY9w0#L;>>#Mx&4Mvt//L[MkA#W@lK.N'[0#7RL_&#w+F%HtG9M#XL`N&.,GM4Pg;--VsM.M0rJfLH2eTM`*oJMHRC`N" + "kfimM2J,W-jXS:)r0wK#@Fge$U>`w'N7G#$#fB#$E^$#:9:hk+eOe--6x)F7*E%?76%^GMHePW-Z5l'&GiF#$956:rS?dA#fiK:)Yr+`�j@'DbG&#^$PG.Ll+DNa&VZ>1i%h1S9u5o@YaaW$e+bROPOpxTO7Stwi1::iB1q)C_=dV26J;2,]7op$]uQr@_V7$q^%lQwtuHY]=DX,n3L#0PHDO4f9>dC@O>HBuKPpP*E,N+b3L#lpR/MrTEH.IAQk.a>D[.e;mc." + "x]Ip.PH^'/aqUO/$1WxLoW0[iLAw=4h(9.`G" + "CRUxHPeR`5Mjol(dUWxZa(>STrPkrJiWx`5U7F#.g*jrohGg`cg:lSTvEY/EV_7H4Q9[Z%cnv;JQYZ5q.l7Zeas:HOIZOB?Ggv:[7MI2k).'2($5FNP&EQ(,)" + "U]W]+fh18.vsai00);D3@4ku5P?DP8aJt+;qUM]=+b'8@;mViBKx0DE[-auGl8:PJ&Dj+M6OC]O^((##]`0i)drT;-7X`=-H3[igUnPG-NZlo.#k@h#=Ork$m>a>$-?Tm$UV(?#P6YY#" + "'/###xe7q.73rI3*pP/$1>s9)W,JrM7SN]'/4C#v$U`0#V.[0>xQsH$fEmPMgY2u7Kh(G%siIfLSoS+MK2eTM$=5,M8p`A.;_R%#u[K#$x4AG8.kK/HSB==-'Ie/QTtG?-.*^N-4B/ZM" + "_3YlQC7(p7q)&](`6_c)$/*JL(L-^(]$wIM`dPtOdGA,U3:w2M-0+WomX2u7lqM2iEumMTcsF?-aT=Z-97UEnXglEn1K-bnEO`gu" + "Ft(c%=;Am_Qs@jLooI&NX;]0#j4#F14;gl8-GQpgwhrq8'=l_f-b49'UOqkLu7-##oDY2L(te+Mch&gLYtJ,MEtJfLh'x'M=$CS-ZZ%P]8bZ>#S?YY#%Q&q'3^Fw&?D)UDNrocM3A76/" + "/oL?#h7gl85[qW/NDOk%16ij;+:1a'iNIdb-ou8.P*w,v5#EI$TWS>Pot-R*H'-SEpA:g)f+O$%%`kA#G=8RMmG1&O`>to8bC]T&$,n.LoO>29sp3dt-52U%VM#q7'DHpg+#Z9%H[Ket`e;)f#Km8&+DC$I46>#Kr]]u-[=99tts1.qb#q72g1WJO81q+eN'03'eM>&1XxY-caEnO" + "j%2n8)),?ILR5^.Ibn<-X-Mq7[a82Lq:F&#ce+S9wsCK*x`569E8ew'He]h:sI[2LM$[guka3ZRd6:t%IG:;$%YiJ:Nq=?eAw;/:nnDq0(CYcMpG)qLN4$##&J-XTt,%OVU4)S1+R-#dg0/Nn?Ku1^0f$B*P:Rowwm-`0PKjYDDM'3]d39VZHEl4,.j']Pk-M.h^&:0FACm$maq-&sgw0t7/6(^xtk%" + "LuH88Fj-ekm>GA#_>568x6(OFRl-IZp`&b,_P'$MhLbxfc$mj`,O;&%W2m`Zh:/)Uetw:aJ%]K9h:TcF]u_-Sj9,VK3M.*'&0D[Ca]J9gp8,kAW]" + "%(?A%R$f<->Zts'^kn=-^@c4%-pY6qI%J%1IGxfLU9CP8cbPlXv);C=b),<2mOvP8up,UVf3839acAWAW-W?#ao/^#%KYo8fRULNd2.>%m]UK:n%r$'sw]J;5pAoO_#2mO3n,'=H5(et" + "Hg*`+RLgv>=4U8guD$I%D:W>-r5V*%j*W:Kvej.Lp$'?;++O'>()jLR-^u68PHm8ZFWe+ej8h:9r6L*0//c&iH&R8pRbA#Kjm%upV1g:" + "a_#Ur7FuA#(tRh#.Y5K+@?3<-8m0$PEn;J:rh6?I6uG<-`wMU'ircp0LaE_OtlMb&1#6T.#FDKu#1Lw%u%+GM+X'e?YLfjM[VO0MbuFp7;>Q&#WIo)0@F%q7c#4XAXN-U&VBpqB>0ie&jhZ[?iLR@@_AvA-iQC(=ksRZRVp7`.=+NpBC%rh&3]R:8XDmE5^V8O(x<-+k?'(^](H.aREZSi,#1:[IXaZFOm<-ui#qUq2$##Ri;u75OK#(RtaW-K-F`S+cF]uN`-KMQ%rP/Xri.LRcB##=YL3BgM/3M" + "D?@f&1'BW-)Ju#bmmWCMkk&#TR`C,5d>g)F;t,4:@_l8G/5h4vUd%&%950:VXD'QdWoY-F$BtUwmfe$YqL'8(PWX(" + "P?^@Po3$##`MSs?DWBZ/S>+4%>fX,VWv/w'KD`LP5IbH;rTV>n3cEK8U#bX]l-/V+^lj3;vlMb&[5YQ8#pekX9JP3XUC72L,,?+Ni&co7ApnO*5NK,((W-i:$,kp'UDAO(G0Sq7MVjJs" + "bIu)'Z,*[>br5fX^:FPAWr-m2KgLQ_nN6'8uTGT5g)uLv:873UpTLgH+#FgpH'_o1780Ph8KmxQJ8#H72L4@768@Tm&Q" + "h4CB/5OvmA&,Q&QbUoi$a_%3M01H)4x7I^&KQVgtFnV+;[Pc>[m4k//,]1?#`VY[Jr*3&&slRfLiVZJ:]?=K3Sw=[$=uRB?3xk48@aege0jT6'N#(q%.O=?2S]u*(m<-" + "V8J'(1)G][68hW$5'q[GC&5j`TE?m'esFGNRM)j,ffZ?-qx8;->g4t*:CIP/[Qap7/9'#(1sao7w-.qNUdkJ)tCF&#B^;xGvn2r9FEPFFFcL@.iFNkTve$m%#QvQS8U@)2Z+3K:AKM5i" + "sZ88+dKQ)W6>J%CL`.d*(B`-n8D9oK-XV1q['-5k'cAZ69e;D_?$ZPP&s^+7])$*$#@QYi9,5P r+$%CE=68>K8r0=dSC%%(@p7" + ".m7jilQ02'0-VWAgTlGW'b)Tq7VT9q^*^$$.:&N@@" + "$&)WHtPm*5_rO0&e%K&#-30j(E4#'Zb.o/(Tpm$>K'f@[PvFl,hfINTNU6u'0pao7%XUp9]5.>%h`8_=VYbxuel.NTSsJfLacFu3B'lQSu/m6-Oqem8T+oE--$0a/k]uj9EwsG>%veR*" + "hv^BFpQj:K'#SJ,sB-'#](j.Lg92rTw-*n%@/;39rrJF,l#qV%OrtBeC6/,;qB3ebNW[?,Hqj2L.1NP&GjUR=1D8QaS3Up&@*9wP?+lo7b?@%'k4`p0Z$22%K3+iCZj?XJN4Nm&+YF]u" + "@-W$U%VEQ/,,>>#)D#%8cY#YZ?=,`Wdxu/ae&#" + "w6)R89tI#6@s'(6Bf7a&?S=^ZI_kS&ai`&=tE72L_D,;^R)7[$so8lKN%5/$(vdfq7+ebA#" + "u1p]ovUKW&Y%q]'>$1@-[xfn$7ZTp7mM,G,Ko7a&Gu%G[RMxJs[0MM%wci.LFDK)(%:_i2B5CsR8&9Z&#=mPEnm0f`<&c)QL5uJ#%u%lJj+D-r;BoFDoS97h5g)E#o:&S4weDF,9^Hoe`h*L+_a*NrLW-1pG_&2UdB8" + "6e%B/:=>)N4xeW.*wft-;$'58-ESqr#U`'6AQ]m&6/`Z>#S?YY#Vc;r7U2&326d=w&H####?TZ`*4?&.MK?LP8Vxg>$[QXc%QJv92.(Db*B)gb*BM9dM*hJMAo*c&#" + "b0v=Pjer]$gG&JXDf->'StvU7505l9$AFvgYRI^&<^b68?j#q9QX4SM'RO#&sL1IM.rJfLUAj221]d##DW=m83u5;'bYx,*Sl0hL(W;;$doB&O/TQ:(Z^xBdLjLV#*8U_72Lh+2Q8Cj0i:6hp&$C/:p(HK>T8Y[gHQ4`4)'$Ab(Nof%V'8hL&#SfD07&6D@M.*J:;$-rv29'M]8qMv-tLp,'886iaC=Hb*YJoKJ,(j%K=H`K.v9HggqBIiZu'QvBT.#=)0ukruV&.)3=(^1`o*Pj4<-#MJ+gLq9-##@HuZPN0]u:h7.T..G:;$/Usj(T7`Q8tT72LnYl<-qx8;-HV7Q-&Xdx%1a,hC=0u+HlsV>nuIQL-5" + "_>@kXQtMacfD.m-VAb8;IReM3$wf0''hra*so568'Ip&vRs849'MRYSp%:t:h5qSgwpEr$B>Q,;s(C#$)`svQuF$##-D,##,g68@2[T;.XSdN9Qe)rpt._K-#5wF)sP'##p#C0c%-Gb%" + "hd+<-j'Ai*x&&HMkT]C'OSl##5RG[JXaHN;d'uA#x._U;.`PU@(Z3dt4r152@:v,'R.Sj'w#0<-;kPI)FfJ&#AYJ&#//)>-k=m=*XnK$>=)72L]0I%>.G690a:$##<,);?;72#?x9+d;" + "^V'9;jY@;)br#q^YQpx:X#Te$Z^'=-=bGhLf:D6&bNwZ9-ZD#n^9HhLMr5G;']d&6'wYmTFmLq9wI>P(9mI[>kC-ekLC/R&CH+s'B;K-M6$EB%is00:" + "+A4[7xks.LrNk0&E)wILYF@2L'0Nb$+pv<(2.768/FrY&h$^3i&@+G%JT'<-,v`3;_)I9M^AE]CN?Cl2AZg+%4iTpT3$U4O]GKx'm9)b@p7YsvK3w^YR-" + "CdQ*:Ir<($u&)#(&?L9Rg3H)4fiEp^iI9O8KnTj,]H?D*r7'M;PwZ9K0E^k&-cpI;.p/6_vwoFMV<->#%Xi.LxVnrU(4&8/P+:hLSKj$#U%]49t'I:rgMi'FL@a:0Y-uA[39',(vbma*" + "hU%<-SRF`Tt:542R_VV$p@[p8DV[A,?1839FWdFTi1O*H&#(AL8[_P%.M>v^-))qOT*F5Cq0`Ye%+$B6i:7@0IXSsDiWP,##P`%/L-" + "S(qw%sf/@%#B6;/U7K]uZbi^Oc^2n%t<)'mEVE''n`WnJra$^TKvX5B>;_aSEK',(hwa0:i4G?.Bci.(X[?b*($,=-n<.Q%`(X=?+@Am*Js0&=3bh8K]mL69=Lb,OcZV/);TTm8VI;?%OtJ<(b4mq7M6:u?KRdFl*:xP?Yb.5)%w_I?7uk5JC+FS(m#i'k.'a0i)9<7b'fs'59hq$*5Uhv##pi^8+hIEBF`nvo`;'l0.^S1<-wUK2/Coh58KKhLj" + "M=SO*rfO`+qC`W-On.=AJ56>>i2@2LH6A:&5q`?9I3@@'04&p2/LVa*T-4<-i3;M9UvZd+N7>b*eIwg:CC)c<>nO&#$(>.Z-I&J(Q0Hd5Q%7Co-b`-cP)hI;*_F]u`Rb[.j8_Q/<&>uu+VsH$sM9TA%?)(vmJ80),P7E>)tjD%2L=-t#fK[%`v=Q8WlA2);Sa" + ">gXm8YB`1d@K#n]76-a$U,mF%Ul:#/'xoFM9QX-$.QN'>" + "[%$Z$uF6pA6Ki2O5:8w*vP1<-1`[G,)-m#>0`P&#eb#.3i)rtB61(o'$?X3B2Qft^ae_5tKL9MUe9b*sLEQ95C&`=G?@Mj=wh*'3E>=-<)Gt*Iw)'QG:`@I" + "wOf7&]1i'S01B+Ev/Nac#9S;=;YQpg_6U`*kVY39xK,[/6Aj7:'1Bm-_1EYfa1+o&o4hp7KN_Q(OlIo@S%;jVdn0'1h19w,WQhLI)3S#f$2(eb,jr*b;3Vw]*7NH%$c4Vs,eD9>XW8?N]o+(*pgC%/72LV-uW%iewS8W6m2rtCpo'RS1R84=@paTKt)>=%&1[)*vp'u+x,VrwN;&]kuO9JDbg=pO$J*.jVe;u'm0dr9l,<*wMK*Oe=g8lV_KEBFkO'oU]^=[-792#ok,)" + "i]lR8qQ2oA8wcRCZ^7w/Njh;?.stX?Q1>S1q4Bn$)K1<-rGdO'$Wr.Lc.CG)$/*JL4tNR/,SVO3,aUw'DJN:)Ss;wGn9A32ijw%FL+Z0Fn.U9;reSq)bmI32U==5ALuG&#Vf1398/pVo" + "1*c-(aY168o<`JsSbk-,1N;$>0:OUas(3:8Z972LSfF8eb=c-;>SPw7.6hn3m`9^Xkn(r.qS[0;T%&Qc=+STRxX'q1BNk3&*eu2;&8q$&x>Q#Q7^Tf+6<(d%ZVmj2bDi%.3L2n+4W'$P" + "iDDG)g,r%+?,$@?uou5tSe2aN_AQU*'IAO" + "URQ##V^Fv-XFbGM7Fl(N<3DhLGF%q.1rC$#:T__&Pi68%0xi_&[qFJ(77j_&JWoF.V735&T,[R*:xFR*K5>>#`bW-?4Ne_&6Ne_&6Ne_&n`kr-#GJcM6X;uM6X;uM(.a..^2TkL%oR(#" + ";u.T%fAr%4tJ8&><1=GHZ_+m9/#H1F^R#SC#*N=BA9(D?v[UiFY>>^8p,KKF.W]L29uLkLlu/+4T" + "w$)F./^n3+rlo+DB;5sIYGNk+i1t-69Jg--0pao7Sm#K)pdHW&;LuDNH@H>#/X-TI(;P>#,Gc>#0Su>#4`1?#8lC?#xL$#B.`$#F:r$#JF.%#NR@%#R_R%#Vke%#Zww%#_-4^Rh%Sflr-k'MS.o?.5/sWel/wpEM0%3'/1)K^f1-d>G21&v(35>V`39V7A4=onx4" + "A1OY5EI0;6Ibgr6M$HS7Q<)58C5w,;WoA*#[%T*#`1g*#d=#+#hI5+#lUG+#pbY+#tnl+#x$),#&1;,#*=M,#.I`,#2Ur,#6b.-#;w[H#iQtA#m^0B#qjBB#uvTB##-hB#'9$C#+E6C#" + "/QHC#3^ZC#7jmC#;v)D#?,)4kMYD4lVu`4m`:&5niUA5@(A5BA1]PBB:xlBCC=2CDLXMCEUtiCf&0g2'tN?PGT4CPGT4CPGT4CPGT4CPGT4CPGT4CPGT4CP" + "GT4CPGT4CPGT4CPGT4CPGT4CPGT4CP-qekC`.9kEg^+F$kwViFJTB&5KTB&5KTB&5KTB&5KTB&5KTB&5KTB&5KTB&5KTB&5KTB&5KTB&5KTB&5KTB&5KTB&5KTB&5o,^<-28ZI'O?;xp" + "O?;xpO?;xpO?;xpO?;xpO?;xpO?;xpO?;xpO?;xpO?;xpO?;xpO?;xpO?;xpO?;xp;7q-#lLYI:xvD=#"; + +#endif /* NK_INCLUDE_DEFAULT_FONT */ + +#define NK_CURSOR_DATA_W 90 +#define NK_CURSOR_DATA_H 27 +NK_GLOBAL const char nk_custom_cursor_data[NK_CURSOR_DATA_W * NK_CURSOR_DATA_H + 1] = +{ + "..- -XXXXXXX- X - X -XXXXXXX - XXXXXXX" + "..- -X.....X- X.X - X.X -X.....X - X.....X" + "--- -XXX.XXX- X...X - X...X -X....X - X....X" + "X - X.X - X.....X - X.....X -X...X - X...X" + "XX - X.X -X.......X- X.......X -X..X.X - X.X..X" + "X.X - X.X -XXXX.XXXX- XXXX.XXXX -X.X X.X - X.X X.X" + "X..X - X.X - X.X - X.X -XX X.X - X.X XX" + "X...X - X.X - X.X - XX X.X XX - X.X - X.X " + "X....X - X.X - X.X - X.X X.X X.X - X.X - X.X " + "X.....X - X.X - X.X - X..X X.X X..X - X.X - X.X " + "X......X - X.X - X.X - X...XXXXXX.XXXXXX...X - X.X XX-XX X.X " + "X.......X - X.X - X.X -X.....................X- X.X X.X-X.X X.X " + "X........X - X.X - X.X - X...XXXXXX.XXXXXX...X - X.X..X-X..X.X " + "X.........X -XXX.XXX- X.X - X..X X.X X..X - X...X-X...X " + "X..........X-X.....X- X.X - X.X X.X X.X - X....X-X....X " + "X......XXXXX-XXXXXXX- X.X - XX X.X XX - X.....X-X.....X " + "X...X..X --------- X.X - X.X - XXXXXXX-XXXXXXX " + "X..X X..X - -XXXX.XXXX- XXXX.XXXX ------------------------------------" + "X.X X..X - -X.......X- X.......X - XX XX - " + "XX X..X - - X.....X - X.....X - X.X X.X - " + " X..X - X...X - X...X - X..X X..X - " + " XX - X.X - X.X - X...XXXXXXXXXXXXX...X - " + "------------ - X - X -X.....................X- " + " ----------------------------------- X...XXXXXXXXXXXXX...X - " + " - X..X X..X - " + " - X.X X.X - " + " - XX XX - " +}; + +#ifdef __clang__ +#pragma clang diagnostic pop +#elif defined(__GNUC__) || defined(__GNUG__) +#pragma GCC diagnostic pop +#endif + +NK_GLOBAL unsigned char *nk__barrier; +NK_GLOBAL unsigned char *nk__barrier2; +NK_GLOBAL unsigned char *nk__barrier3; +NK_GLOBAL unsigned char *nk__barrier4; +NK_GLOBAL unsigned char *nk__dout; + +NK_INTERN unsigned int +nk_decompress_length(unsigned char *input) +{ + return (unsigned int)((input[8] << 24) + (input[9] << 16) + (input[10] << 8) + input[11]); +} +NK_INTERN void +nk__match(unsigned char *data, unsigned int length) +{ + /* INVERSE of memmove... write each byte before copying the next...*/ + NK_ASSERT (nk__dout + length <= nk__barrier); + if (nk__dout + length > nk__barrier) { nk__dout += length; return; } + if (data < nk__barrier4) { nk__dout = nk__barrier+1; return; } + while (length--) *nk__dout++ = *data++; +} +NK_INTERN void +nk__lit(unsigned char *data, unsigned int length) +{ + NK_ASSERT (nk__dout + length <= nk__barrier); + if (nk__dout + length > nk__barrier) { nk__dout += length; return; } + if (data < nk__barrier2) { nk__dout = nk__barrier+1; return; } + NK_MEMCPY(nk__dout, data, length); + nk__dout += length; +} +NK_INTERN unsigned char* +nk_decompress_token(unsigned char *i) +{ + #define nk__in2(x) ((i[x] << 8) + i[(x)+1]) + #define nk__in3(x) ((i[x] << 16) + nk__in2((x)+1)) + #define nk__in4(x) ((i[x] << 24) + nk__in3((x)+1)) + + if (*i >= 0x20) { /* use fewer if's for cases that expand small */ + if (*i >= 0x80) nk__match(nk__dout-i[1]-1, (unsigned int)i[0] - 0x80 + 1), i += 2; + else if (*i >= 0x40) nk__match(nk__dout-(nk__in2(0) - 0x4000 + 1), (unsigned int)i[2]+1), i += 3; + else /* *i >= 0x20 */ nk__lit(i+1, (unsigned int)i[0] - 0x20 + 1), i += 1 + (i[0] - 0x20 + 1); + } else { /* more ifs for cases that expand large, since overhead is amortized */ + if (*i >= 0x18) nk__match(nk__dout-(unsigned int)(nk__in3(0) - 0x180000 + 1), (unsigned int)i[3]+1), i += 4; + else if (*i >= 0x10) nk__match(nk__dout-(unsigned int)(nk__in3(0) - 0x100000 + 1), (unsigned int)nk__in2(3)+1), i += 5; + else if (*i >= 0x08) nk__lit(i+2, (unsigned int)nk__in2(0) - 0x0800 + 1), i += 2 + (nk__in2(0) - 0x0800 + 1); + else if (*i == 0x07) nk__lit(i+3, (unsigned int)nk__in2(1) + 1), i += 3 + (nk__in2(1) + 1); + else if (*i == 0x06) nk__match(nk__dout-(unsigned int)(nk__in3(1)+1), i[4]+1u), i += 5; + else if (*i == 0x04) nk__match(nk__dout-(unsigned int)(nk__in3(1)+1), (unsigned int)nk__in2(4)+1u), i += 6; + } + return i; +} +NK_INTERN unsigned int +nk_adler32(unsigned int adler32, unsigned char *buffer, unsigned int buflen) +{ + const unsigned long ADLER_MOD = 65521; + unsigned long s1 = adler32 & 0xffff, s2 = adler32 >> 16; + unsigned long blocklen, i; + + blocklen = buflen % 5552; + while (buflen) { + for (i=0; i + 7 < blocklen; i += 8) { + s1 += buffer[0]; s2 += s1; + s1 += buffer[1]; s2 += s1; + s1 += buffer[2]; s2 += s1; + s1 += buffer[3]; s2 += s1; + s1 += buffer[4]; s2 += s1; + s1 += buffer[5]; s2 += s1; + s1 += buffer[6]; s2 += s1; + s1 += buffer[7]; s2 += s1; + buffer += 8; + } + for (; i < blocklen; ++i) { + s1 += *buffer++; s2 += s1; + } + + s1 %= ADLER_MOD; s2 %= ADLER_MOD; + buflen -= (unsigned int)blocklen; + blocklen = 5552; + } + return (unsigned int)(s2 << 16) + (unsigned int)s1; +} +NK_INTERN unsigned int +nk_decompress(unsigned char *output, unsigned char *i, unsigned int length) +{ + unsigned int olen; + if (nk__in4(0) != 0x57bC0000) return 0; + if (nk__in4(4) != 0) return 0; /* error! stream is > 4GB */ + olen = nk_decompress_length(i); + nk__barrier2 = i; + nk__barrier3 = i+length; + nk__barrier = output + olen; + nk__barrier4 = output; + i += 16; + + nk__dout = output; + for (;;) { + unsigned char *old_i = i; + i = nk_decompress_token(i); + if (i == old_i) { + if (*i == 0x05 && i[1] == 0xfa) { + NK_ASSERT(nk__dout == output + olen); + if (nk__dout != output + olen) return 0; + if (nk_adler32(1, output, olen) != (unsigned int) nk__in4(2)) + return 0; + return olen; + } else { + NK_ASSERT(0); /* NOTREACHED */ + return 0; + } + } + NK_ASSERT(nk__dout <= output + olen); + if (nk__dout > output + olen) + return 0; + } +} +NK_INTERN unsigned int +nk_decode_85_byte(char c) +{ + return (unsigned int)((c >= '\\') ? c-36 : c-35); +} +NK_INTERN void +nk_decode_85(unsigned char* dst, const unsigned char* src) +{ + while (*src) + { + unsigned int tmp = + nk_decode_85_byte((char)src[0]) + + 85 * (nk_decode_85_byte((char)src[1]) + + 85 * (nk_decode_85_byte((char)src[2]) + + 85 * (nk_decode_85_byte((char)src[3]) + + 85 * nk_decode_85_byte((char)src[4])))); + + /* we can't assume little-endianess. */ + dst[0] = (unsigned char)((tmp >> 0) & 0xFF); + dst[1] = (unsigned char)((tmp >> 8) & 0xFF); + dst[2] = (unsigned char)((tmp >> 16) & 0xFF); + dst[3] = (unsigned char)((tmp >> 24) & 0xFF); + + src += 5; + dst += 4; + } +} + +/* ------------------------------------------------------------- + * + * FONT ATLAS + * + * --------------------------------------------------------------*/ +NK_API struct nk_font_config +nk_font_config(float pixel_height) +{ + struct nk_font_config cfg; + nk_zero_struct(cfg); + cfg.ttf_blob = 0; + cfg.ttf_size = 0; + cfg.ttf_data_owned_by_atlas = 0; + cfg.size = pixel_height; + cfg.oversample_h = 3; + cfg.oversample_v = 1; + cfg.pixel_snap = 0; + cfg.coord_type = NK_COORD_UV; + cfg.spacing = nk_vec2(0,0); + cfg.range = nk_font_default_glyph_ranges(); + cfg.merge_mode = 0; + cfg.fallback_glyph = '?'; + cfg.font = 0; + cfg.n = 0; + return cfg; +} +#ifdef NK_INCLUDE_DEFAULT_ALLOCATOR +NK_API void +nk_font_atlas_init_default(struct nk_font_atlas *atlas) +{ + NK_ASSERT(atlas); + if (!atlas) return; + nk_zero_struct(*atlas); + atlas->temporary.userdata.ptr = 0; + atlas->temporary.alloc = nk_malloc; + atlas->temporary.free = nk_mfree; + atlas->permanent.userdata.ptr = 0; + atlas->permanent.alloc = nk_malloc; + atlas->permanent.free = nk_mfree; +} +#endif +NK_API void +nk_font_atlas_init(struct nk_font_atlas *atlas, struct nk_allocator *alloc) +{ + NK_ASSERT(atlas); + NK_ASSERT(alloc); + if (!atlas || !alloc) return; + nk_zero_struct(*atlas); + atlas->permanent = *alloc; + atlas->temporary = *alloc; +} +NK_API void +nk_font_atlas_init_custom(struct nk_font_atlas *atlas, + struct nk_allocator *permanent, struct nk_allocator *temporary) +{ + NK_ASSERT(atlas); + NK_ASSERT(permanent); + NK_ASSERT(temporary); + if (!atlas || !permanent || !temporary) return; + nk_zero_struct(*atlas); + atlas->permanent = *permanent; + atlas->temporary = *temporary; +} +NK_API void +nk_font_atlas_begin(struct nk_font_atlas *atlas) +{ + NK_ASSERT(atlas); + NK_ASSERT(atlas->temporary.alloc && atlas->temporary.free); + NK_ASSERT(atlas->permanent.alloc && atlas->permanent.free); + if (!atlas || !atlas->permanent.alloc || !atlas->permanent.free || + !atlas->temporary.alloc || !atlas->temporary.free) return; + if (atlas->glyphs) { + atlas->permanent.free(atlas->permanent.userdata, atlas->glyphs); + atlas->glyphs = 0; + } + if (atlas->pixel) { + atlas->permanent.free(atlas->permanent.userdata, atlas->pixel); + atlas->pixel = 0; + } +} +NK_API struct nk_font* +nk_font_atlas_add(struct nk_font_atlas *atlas, const struct nk_font_config *config) +{ + struct nk_font *font = 0; + struct nk_font_config *cfg; + + NK_ASSERT(atlas); + NK_ASSERT(atlas->permanent.alloc); + NK_ASSERT(atlas->permanent.free); + NK_ASSERT(atlas->temporary.alloc); + NK_ASSERT(atlas->temporary.free); + + NK_ASSERT(config); + NK_ASSERT(config->ttf_blob); + NK_ASSERT(config->ttf_size); + NK_ASSERT(config->size > 0.0f); + + if (!atlas || !config || !config->ttf_blob || !config->ttf_size || config->size <= 0.0f|| + !atlas->permanent.alloc || !atlas->permanent.free || + !atlas->temporary.alloc || !atlas->temporary.free) + return 0; + + /* allocate font config */ + cfg = (struct nk_font_config*) + atlas->permanent.alloc(atlas->permanent.userdata,0, sizeof(struct nk_font_config)); + NK_MEMCPY(cfg, config, sizeof(*config)); + cfg->n = cfg; + cfg->p = cfg; + + if (!config->merge_mode) { + /* insert font config into list */ + if (!atlas->config) { + atlas->config = cfg; + cfg->next = 0; + } else { + struct nk_font_config *i = atlas->config; + while (i->next) i = i->next; + i->next = cfg; + cfg->next = 0; + } + /* allocate new font */ + font = (struct nk_font*) + atlas->permanent.alloc(atlas->permanent.userdata,0, sizeof(struct nk_font)); + NK_ASSERT(font); + nk_zero(font, sizeof(*font)); + if (!font) return 0; + font->config = cfg; + + /* insert font into list */ + if (!atlas->fonts) { + atlas->fonts = font; + font->next = 0; + } else { + struct nk_font *i = atlas->fonts; + while (i->next) i = i->next; + i->next = font; + font->next = 0; + } + cfg->font = &font->info; + } else { + /* extend previously added font */ + struct nk_font *f = 0; + struct nk_font_config *c = 0; + NK_ASSERT(atlas->font_num); + f = atlas->fonts; + c = f->config; + cfg->font = &f->info; + + cfg->n = c; + cfg->p = c->p; + c->p->n = cfg; + c->p = cfg; + } + /* create own copy of .TTF font blob */ + if (!config->ttf_data_owned_by_atlas) { + cfg->ttf_blob = atlas->permanent.alloc(atlas->permanent.userdata,0, cfg->ttf_size); + NK_ASSERT(cfg->ttf_blob); + if (!cfg->ttf_blob) { + atlas->font_num++; + return 0; + } + NK_MEMCPY(cfg->ttf_blob, config->ttf_blob, cfg->ttf_size); + cfg->ttf_data_owned_by_atlas = 1; + } + atlas->font_num++; + return font; +} +NK_API struct nk_font* +nk_font_atlas_add_from_memory(struct nk_font_atlas *atlas, void *memory, + nk_size size, float height, const struct nk_font_config *config) +{ + struct nk_font_config cfg; + NK_ASSERT(memory); + NK_ASSERT(size); + + NK_ASSERT(atlas); + NK_ASSERT(atlas->temporary.alloc); + NK_ASSERT(atlas->temporary.free); + NK_ASSERT(atlas->permanent.alloc); + NK_ASSERT(atlas->permanent.free); + if (!atlas || !atlas->temporary.alloc || !atlas->temporary.free || !memory || !size || + !atlas->permanent.alloc || !atlas->permanent.free) + return 0; + + cfg = (config) ? *config: nk_font_config(height); + cfg.ttf_blob = memory; + cfg.ttf_size = size; + cfg.size = height; + cfg.ttf_data_owned_by_atlas = 0; + return nk_font_atlas_add(atlas, &cfg); +} +#ifdef NK_INCLUDE_STANDARD_IO +NK_API struct nk_font* +nk_font_atlas_add_from_file(struct nk_font_atlas *atlas, const char *file_path, + float height, const struct nk_font_config *config) +{ + nk_size size; + char *memory; + struct nk_font_config cfg; + + NK_ASSERT(atlas); + NK_ASSERT(atlas->temporary.alloc); + NK_ASSERT(atlas->temporary.free); + NK_ASSERT(atlas->permanent.alloc); + NK_ASSERT(atlas->permanent.free); + + if (!atlas || !file_path) return 0; + memory = nk_file_load(file_path, &size, &atlas->permanent); + if (!memory) return 0; + + cfg = (config) ? *config: nk_font_config(height); + cfg.ttf_blob = memory; + cfg.ttf_size = size; + cfg.size = height; + cfg.ttf_data_owned_by_atlas = 1; + return nk_font_atlas_add(atlas, &cfg); +} +#endif +NK_API struct nk_font* +nk_font_atlas_add_compressed(struct nk_font_atlas *atlas, + void *compressed_data, nk_size compressed_size, float height, + const struct nk_font_config *config) +{ + unsigned int decompressed_size; + void *decompressed_data; + struct nk_font_config cfg; + + NK_ASSERT(atlas); + NK_ASSERT(atlas->temporary.alloc); + NK_ASSERT(atlas->temporary.free); + NK_ASSERT(atlas->permanent.alloc); + NK_ASSERT(atlas->permanent.free); + + NK_ASSERT(compressed_data); + NK_ASSERT(compressed_size); + if (!atlas || !compressed_data || !atlas->temporary.alloc || !atlas->temporary.free || + !atlas->permanent.alloc || !atlas->permanent.free) + return 0; + + decompressed_size = nk_decompress_length((unsigned char*)compressed_data); + decompressed_data = atlas->permanent.alloc(atlas->permanent.userdata,0,decompressed_size); + NK_ASSERT(decompressed_data); + if (!decompressed_data) return 0; + nk_decompress((unsigned char*)decompressed_data, (unsigned char*)compressed_data, + (unsigned int)compressed_size); + + cfg = (config) ? *config: nk_font_config(height); + cfg.ttf_blob = decompressed_data; + cfg.ttf_size = decompressed_size; + cfg.size = height; + cfg.ttf_data_owned_by_atlas = 1; + return nk_font_atlas_add(atlas, &cfg); +} +NK_API struct nk_font* +nk_font_atlas_add_compressed_base85(struct nk_font_atlas *atlas, + const char *data_base85, float height, const struct nk_font_config *config) +{ + int compressed_size; + void *compressed_data; + struct nk_font *font; + + NK_ASSERT(atlas); + NK_ASSERT(atlas->temporary.alloc); + NK_ASSERT(atlas->temporary.free); + NK_ASSERT(atlas->permanent.alloc); + NK_ASSERT(atlas->permanent.free); + + NK_ASSERT(data_base85); + if (!atlas || !data_base85 || !atlas->temporary.alloc || !atlas->temporary.free || + !atlas->permanent.alloc || !atlas->permanent.free) + return 0; + + compressed_size = (((int)nk_strlen(data_base85) + 4) / 5) * 4; + compressed_data = atlas->temporary.alloc(atlas->temporary.userdata,0, (nk_size)compressed_size); + NK_ASSERT(compressed_data); + if (!compressed_data) return 0; + nk_decode_85((unsigned char*)compressed_data, (const unsigned char*)data_base85); + font = nk_font_atlas_add_compressed(atlas, compressed_data, + (nk_size)compressed_size, height, config); + atlas->temporary.free(atlas->temporary.userdata, compressed_data); + return font; +} + +#ifdef NK_INCLUDE_DEFAULT_FONT +NK_API struct nk_font* +nk_font_atlas_add_default(struct nk_font_atlas *atlas, + float pixel_height, const struct nk_font_config *config) +{ + NK_ASSERT(atlas); + NK_ASSERT(atlas->temporary.alloc); + NK_ASSERT(atlas->temporary.free); + NK_ASSERT(atlas->permanent.alloc); + NK_ASSERT(atlas->permanent.free); + return nk_font_atlas_add_compressed_base85(atlas, + nk_proggy_clean_ttf_compressed_data_base85, pixel_height, config); +} +#endif +NK_API const void* +nk_font_atlas_bake(struct nk_font_atlas *atlas, int *width, int *height, + enum nk_font_atlas_format fmt) +{ + int i = 0; + void *tmp = 0; + nk_size tmp_size, img_size; + struct nk_font *font_iter; + struct nk_font_baker *baker; + + NK_ASSERT(atlas); + NK_ASSERT(atlas->temporary.alloc); + NK_ASSERT(atlas->temporary.free); + NK_ASSERT(atlas->permanent.alloc); + NK_ASSERT(atlas->permanent.free); + + NK_ASSERT(width); + NK_ASSERT(height); + if (!atlas || !width || !height || + !atlas->temporary.alloc || !atlas->temporary.free || + !atlas->permanent.alloc || !atlas->permanent.free) + return 0; + +#ifdef NK_INCLUDE_DEFAULT_FONT + /* no font added so just use default font */ + if (!atlas->font_num) + atlas->default_font = nk_font_atlas_add_default(atlas, 13.0f, 0); +#endif + NK_ASSERT(atlas->font_num); + if (!atlas->font_num) return 0; + + /* allocate temporary baker memory required for the baking process */ + nk_font_baker_memory(&tmp_size, &atlas->glyph_count, atlas->config, atlas->font_num); + tmp = atlas->temporary.alloc(atlas->temporary.userdata,0, tmp_size); + NK_ASSERT(tmp); + if (!tmp) goto failed; + NK_MEMSET(tmp,0,tmp_size); + + /* allocate glyph memory for all fonts */ + baker = nk_font_baker(tmp, atlas->glyph_count, atlas->font_num, &atlas->temporary); + atlas->glyphs = (struct nk_font_glyph*)atlas->permanent.alloc( + atlas->permanent.userdata,0, sizeof(struct nk_font_glyph)*(nk_size)atlas->glyph_count); + NK_ASSERT(atlas->glyphs); + if (!atlas->glyphs) + goto failed; + + /* pack all glyphs into a tight fit space */ + atlas->custom.w = (NK_CURSOR_DATA_W*2)+1; + atlas->custom.h = NK_CURSOR_DATA_H + 1; + if (!nk_font_bake_pack(baker, &img_size, width, height, &atlas->custom, + atlas->config, atlas->font_num, &atlas->temporary)) + goto failed; + + /* allocate memory for the baked image font atlas */ + atlas->pixel = atlas->temporary.alloc(atlas->temporary.userdata,0, img_size); + NK_ASSERT(atlas->pixel); + if (!atlas->pixel) + goto failed; + + /* bake glyphs and custom white pixel into image */ + nk_font_bake(baker, atlas->pixel, *width, *height, + atlas->glyphs, atlas->glyph_count, atlas->config, atlas->font_num); + nk_font_bake_custom_data(atlas->pixel, *width, *height, atlas->custom, + nk_custom_cursor_data, NK_CURSOR_DATA_W, NK_CURSOR_DATA_H, '.', 'X'); + + if (fmt == NK_FONT_ATLAS_RGBA32) { + /* convert alpha8 image into rgba32 image */ + void *img_rgba = atlas->temporary.alloc(atlas->temporary.userdata,0, + (nk_size)(*width * *height * 4)); + NK_ASSERT(img_rgba); + if (!img_rgba) goto failed; + nk_font_bake_convert(img_rgba, *width, *height, atlas->pixel); + atlas->temporary.free(atlas->temporary.userdata, atlas->pixel); + atlas->pixel = img_rgba; + } + atlas->tex_width = *width; + atlas->tex_height = *height; + + /* initialize each font */ + for (font_iter = atlas->fonts; font_iter; font_iter = font_iter->next) { + struct nk_font *font = font_iter; + struct nk_font_config *config = font->config; + nk_font_init(font, config->size, config->fallback_glyph, atlas->glyphs, + config->font, nk_handle_ptr(0)); + } + + /* initialize each cursor */ + {NK_STORAGE const struct nk_vec2 nk_cursor_data[NK_CURSOR_COUNT][3] = { + /* Pos Size Offset */ + {{ 0, 3}, {12,19}, { 0, 0}}, + {{13, 0}, { 7,16}, { 4, 8}}, + {{31, 0}, {23,23}, {11,11}}, + {{21, 0}, { 9, 23}, { 5,11}}, + {{55,18}, {23, 9}, {11, 5}}, + {{73, 0}, {17,17}, { 9, 9}}, + {{55, 0}, {17,17}, { 9, 9}} + }; + for (i = 0; i < NK_CURSOR_COUNT; ++i) { + struct nk_cursor *cursor = &atlas->cursors[i]; + cursor->img.w = (unsigned short)*width; + cursor->img.h = (unsigned short)*height; + cursor->img.region[0] = (unsigned short)(atlas->custom.x + nk_cursor_data[i][0].x); + cursor->img.region[1] = (unsigned short)(atlas->custom.y + nk_cursor_data[i][0].y); + cursor->img.region[2] = (unsigned short)nk_cursor_data[i][1].x; + cursor->img.region[3] = (unsigned short)nk_cursor_data[i][1].y; + cursor->size = nk_cursor_data[i][1]; + cursor->offset = nk_cursor_data[i][2]; + }} + /* free temporary memory */ + atlas->temporary.free(atlas->temporary.userdata, tmp); + return atlas->pixel; + +failed: + /* error so cleanup all memory */ + if (tmp) atlas->temporary.free(atlas->temporary.userdata, tmp); + if (atlas->glyphs) { + atlas->permanent.free(atlas->permanent.userdata, atlas->glyphs); + atlas->glyphs = 0; + } + if (atlas->pixel) { + atlas->temporary.free(atlas->temporary.userdata, atlas->pixel); + atlas->pixel = 0; + } + return 0; +} +NK_API void +nk_font_atlas_end(struct nk_font_atlas *atlas, nk_handle texture, + struct nk_draw_null_texture *tex_null) +{ + int i = 0; + struct nk_font *font_iter; + NK_ASSERT(atlas); + if (!atlas) { + if (!tex_null) return; + tex_null->texture = texture; + tex_null->uv = nk_vec2(0.5f,0.5f); + } + if (tex_null) { + tex_null->texture = texture; + tex_null->uv.x = (atlas->custom.x + 0.5f)/(float)atlas->tex_width; + tex_null->uv.y = (atlas->custom.y + 0.5f)/(float)atlas->tex_height; + } + for (font_iter = atlas->fonts; font_iter; font_iter = font_iter->next) { + font_iter->texture = texture; +#ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT + font_iter->handle.texture = texture; +#endif + } + for (i = 0; i < NK_CURSOR_COUNT; ++i) + atlas->cursors[i].img.handle = texture; + + atlas->temporary.free(atlas->temporary.userdata, atlas->pixel); + atlas->pixel = 0; + atlas->tex_width = 0; + atlas->tex_height = 0; + atlas->custom.x = 0; + atlas->custom.y = 0; + atlas->custom.w = 0; + atlas->custom.h = 0; +} +NK_API void +nk_font_atlas_cleanup(struct nk_font_atlas *atlas) +{ + NK_ASSERT(atlas); + NK_ASSERT(atlas->temporary.alloc); + NK_ASSERT(atlas->temporary.free); + NK_ASSERT(atlas->permanent.alloc); + NK_ASSERT(atlas->permanent.free); + if (!atlas || !atlas->permanent.alloc || !atlas->permanent.free) return; + if (atlas->config) { + struct nk_font_config *iter; + for (iter = atlas->config; iter; iter = iter->next) { + struct nk_font_config *i; + for (i = iter->n; i != iter; i = i->n) { + atlas->permanent.free(atlas->permanent.userdata, i->ttf_blob); + i->ttf_blob = 0; + } + atlas->permanent.free(atlas->permanent.userdata, iter->ttf_blob); + iter->ttf_blob = 0; + } + } +} +NK_API void +nk_font_atlas_clear(struct nk_font_atlas *atlas) +{ + NK_ASSERT(atlas); + NK_ASSERT(atlas->temporary.alloc); + NK_ASSERT(atlas->temporary.free); + NK_ASSERT(atlas->permanent.alloc); + NK_ASSERT(atlas->permanent.free); + if (!atlas || !atlas->permanent.alloc || !atlas->permanent.free) return; + + if (atlas->config) { + struct nk_font_config *iter, *next; + for (iter = atlas->config; iter; iter = next) { + struct nk_font_config *i, *n; + for (i = iter->n; i != iter; i = n) { + n = i->n; + if (i->ttf_blob) + atlas->permanent.free(atlas->permanent.userdata, i->ttf_blob); + atlas->permanent.free(atlas->permanent.userdata, i); + } + next = iter->next; + if (i->ttf_blob) + atlas->permanent.free(atlas->permanent.userdata, iter->ttf_blob); + atlas->permanent.free(atlas->permanent.userdata, iter); + } + atlas->config = 0; + } + if (atlas->fonts) { + struct nk_font *iter, *next; + for (iter = atlas->fonts; iter; iter = next) { + next = iter->next; + atlas->permanent.free(atlas->permanent.userdata, iter); + } + atlas->fonts = 0; + } + if (atlas->glyphs) + atlas->permanent.free(atlas->permanent.userdata, atlas->glyphs); + nk_zero_struct(*atlas); +} +#endif + + + + + +/* =============================================================== + * + * INPUT + * + * ===============================================================*/ +NK_API void +nk_input_begin(struct nk_context *ctx) +{ + int i; + struct nk_input *in; + NK_ASSERT(ctx); + if (!ctx) return; + in = &ctx->input; + for (i = 0; i < NK_BUTTON_MAX; ++i) + in->mouse.buttons[i].clicked = 0; + + in->keyboard.text_len = 0; + in->mouse.scroll_delta = nk_vec2(0,0); + in->mouse.prev.x = in->mouse.pos.x; + in->mouse.prev.y = in->mouse.pos.y; + in->mouse.delta.x = 0; + in->mouse.delta.y = 0; + for (i = 0; i < NK_KEY_MAX; i++) + in->keyboard.keys[i].clicked = 0; +} +NK_API void +nk_input_end(struct nk_context *ctx) +{ + struct nk_input *in; + NK_ASSERT(ctx); + if (!ctx) return; + in = &ctx->input; + if (in->mouse.grab) + in->mouse.grab = 0; + if (in->mouse.ungrab) { + in->mouse.grabbed = 0; + in->mouse.ungrab = 0; + in->mouse.grab = 0; + } +} +NK_API void +nk_input_motion(struct nk_context *ctx, int x, int y) +{ + struct nk_input *in; + NK_ASSERT(ctx); + if (!ctx) return; + in = &ctx->input; + in->mouse.pos.x = (float)x; + in->mouse.pos.y = (float)y; + in->mouse.delta.x = in->mouse.pos.x - in->mouse.prev.x; + in->mouse.delta.y = in->mouse.pos.y - in->mouse.prev.y; +} +NK_API void +nk_input_key(struct nk_context *ctx, enum nk_keys key, nk_bool down) +{ + struct nk_input *in; + NK_ASSERT(ctx); + if (!ctx) return; + in = &ctx->input; +#ifdef NK_KEYSTATE_BASED_INPUT + if (in->keyboard.keys[key].down != down) + in->keyboard.keys[key].clicked++; +#else + in->keyboard.keys[key].clicked++; +#endif + in->keyboard.keys[key].down = down; +} +NK_API void +nk_input_button(struct nk_context *ctx, enum nk_buttons id, int x, int y, nk_bool down) +{ + struct nk_mouse_button *btn; + struct nk_input *in; + NK_ASSERT(ctx); + if (!ctx) return; + in = &ctx->input; + if (in->mouse.buttons[id].down == down) return; + + btn = &in->mouse.buttons[id]; + btn->clicked_pos.x = (float)x; + btn->clicked_pos.y = (float)y; + btn->down = down; + btn->clicked++; + + /* Fix Click-Drag for touch events. */ + in->mouse.delta.x = 0; + in->mouse.delta.y = 0; +#ifdef NK_BUTTON_TRIGGER_ON_RELEASE + if (down == 1 && id == NK_BUTTON_LEFT) + { + in->mouse.down_pos.x = btn->clicked_pos.x; + in->mouse.down_pos.y = btn->clicked_pos.y; + } +#endif +} +NK_API void +nk_input_scroll(struct nk_context *ctx, struct nk_vec2 val) +{ + NK_ASSERT(ctx); + if (!ctx) return; + ctx->input.mouse.scroll_delta.x += val.x; + ctx->input.mouse.scroll_delta.y += val.y; +} +NK_API void +nk_input_glyph(struct nk_context *ctx, const nk_glyph glyph) +{ + int len = 0; + nk_rune unicode; + struct nk_input *in; + + NK_ASSERT(ctx); + if (!ctx) return; + in = &ctx->input; + + len = nk_utf_decode(glyph, &unicode, NK_UTF_SIZE); + if (len && ((in->keyboard.text_len + len) < NK_INPUT_MAX)) { + nk_utf_encode(unicode, &in->keyboard.text[in->keyboard.text_len], + NK_INPUT_MAX - in->keyboard.text_len); + in->keyboard.text_len += len; + } +} +NK_API void +nk_input_char(struct nk_context *ctx, char c) +{ + nk_glyph glyph; + NK_ASSERT(ctx); + if (!ctx) return; + glyph[0] = c; + nk_input_glyph(ctx, glyph); +} +NK_API void +nk_input_unicode(struct nk_context *ctx, nk_rune unicode) +{ + nk_glyph rune; + NK_ASSERT(ctx); + if (!ctx) return; + nk_utf_encode(unicode, rune, NK_UTF_SIZE); + nk_input_glyph(ctx, rune); +} +NK_API nk_bool +nk_input_has_mouse_click(const struct nk_input *i, enum nk_buttons id) +{ + const struct nk_mouse_button *btn; + if (!i) return nk_false; + btn = &i->mouse.buttons[id]; + return (btn->clicked && btn->down == nk_false) ? nk_true : nk_false; +} +NK_API nk_bool +nk_input_has_mouse_click_in_rect(const struct nk_input *i, enum nk_buttons id, + struct nk_rect b) +{ + const struct nk_mouse_button *btn; + if (!i) return nk_false; + btn = &i->mouse.buttons[id]; + if (!NK_INBOX(btn->clicked_pos.x,btn->clicked_pos.y,b.x,b.y,b.w,b.h)) + return nk_false; + return nk_true; +} +NK_API nk_bool +nk_input_has_mouse_click_in_button_rect(const struct nk_input *i, enum nk_buttons id, + struct nk_rect b) +{ + const struct nk_mouse_button *btn; + if (!i) return nk_false; + btn = &i->mouse.buttons[id]; +#ifdef NK_BUTTON_TRIGGER_ON_RELEASE + if (!NK_INBOX(btn->clicked_pos.x,btn->clicked_pos.y,b.x,b.y,b.w,b.h) + || !NK_INBOX(i->mouse.down_pos.x,i->mouse.down_pos.y,b.x,b.y,b.w,b.h)) +#else + if (!NK_INBOX(btn->clicked_pos.x,btn->clicked_pos.y,b.x,b.y,b.w,b.h)) +#endif + return nk_false; + return nk_true; +} +NK_API nk_bool +nk_input_has_mouse_click_down_in_rect(const struct nk_input *i, enum nk_buttons id, + struct nk_rect b, nk_bool down) +{ + const struct nk_mouse_button *btn; + if (!i) return nk_false; + btn = &i->mouse.buttons[id]; + return nk_input_has_mouse_click_in_rect(i, id, b) && (btn->down == down); +} +NK_API nk_bool +nk_input_is_mouse_click_in_rect(const struct nk_input *i, enum nk_buttons id, + struct nk_rect b) +{ + const struct nk_mouse_button *btn; + if (!i) return nk_false; + btn = &i->mouse.buttons[id]; + return (nk_input_has_mouse_click_down_in_rect(i, id, b, nk_false) && + btn->clicked) ? nk_true : nk_false; +} +NK_API nk_bool +nk_input_is_mouse_click_down_in_rect(const struct nk_input *i, enum nk_buttons id, + struct nk_rect b, nk_bool down) +{ + const struct nk_mouse_button *btn; + if (!i) return nk_false; + btn = &i->mouse.buttons[id]; + return (nk_input_has_mouse_click_down_in_rect(i, id, b, down) && + btn->clicked) ? nk_true : nk_false; +} +NK_API nk_bool +nk_input_any_mouse_click_in_rect(const struct nk_input *in, struct nk_rect b) +{ + int i, down = 0; + for (i = 0; i < NK_BUTTON_MAX; ++i) + down = down || nk_input_is_mouse_click_in_rect(in, (enum nk_buttons)i, b); + return down; +} +NK_API nk_bool +nk_input_is_mouse_hovering_rect(const struct nk_input *i, struct nk_rect rect) +{ + if (!i) return nk_false; + return NK_INBOX(i->mouse.pos.x, i->mouse.pos.y, rect.x, rect.y, rect.w, rect.h); +} +NK_API nk_bool +nk_input_is_mouse_prev_hovering_rect(const struct nk_input *i, struct nk_rect rect) +{ + if (!i) return nk_false; + return NK_INBOX(i->mouse.prev.x, i->mouse.prev.y, rect.x, rect.y, rect.w, rect.h); +} +NK_API nk_bool +nk_input_mouse_clicked(const struct nk_input *i, enum nk_buttons id, struct nk_rect rect) +{ + if (!i) return nk_false; + if (!nk_input_is_mouse_hovering_rect(i, rect)) return nk_false; + return nk_input_is_mouse_click_in_rect(i, id, rect); +} +NK_API nk_bool +nk_input_is_mouse_down(const struct nk_input *i, enum nk_buttons id) +{ + if (!i) return nk_false; + return i->mouse.buttons[id].down; +} +NK_API nk_bool +nk_input_is_mouse_pressed(const struct nk_input *i, enum nk_buttons id) +{ + const struct nk_mouse_button *b; + if (!i) return nk_false; + b = &i->mouse.buttons[id]; + if (b->down && b->clicked) + return nk_true; + return nk_false; +} +NK_API nk_bool +nk_input_is_mouse_released(const struct nk_input *i, enum nk_buttons id) +{ + if (!i) return nk_false; + return (!i->mouse.buttons[id].down && i->mouse.buttons[id].clicked); +} +NK_API nk_bool +nk_input_is_key_pressed(const struct nk_input *i, enum nk_keys key) +{ + const struct nk_key *k; + if (!i) return nk_false; + k = &i->keyboard.keys[key]; + if ((k->down && k->clicked) || (!k->down && k->clicked >= 2)) + return nk_true; + return nk_false; +} +NK_API nk_bool +nk_input_is_key_released(const struct nk_input *i, enum nk_keys key) +{ + const struct nk_key *k; + if (!i) return nk_false; + k = &i->keyboard.keys[key]; + if ((!k->down && k->clicked) || (k->down && k->clicked >= 2)) + return nk_true; + return nk_false; +} +NK_API nk_bool +nk_input_is_key_down(const struct nk_input *i, enum nk_keys key) +{ + const struct nk_key *k; + if (!i) return nk_false; + k = &i->keyboard.keys[key]; + if (k->down) return nk_true; + return nk_false; +} + + + + + +/* =============================================================== + * + * STYLE + * + * ===============================================================*/ +NK_API void nk_style_default(struct nk_context *ctx){nk_style_from_table(ctx, 0);} +#define NK_COLOR_MAP(NK_COLOR)\ + NK_COLOR(NK_COLOR_TEXT, 175,175,175,255) \ + NK_COLOR(NK_COLOR_WINDOW, 45, 45, 45, 255) \ + NK_COLOR(NK_COLOR_HEADER, 40, 40, 40, 255) \ + NK_COLOR(NK_COLOR_BORDER, 65, 65, 65, 255) \ + NK_COLOR(NK_COLOR_BUTTON, 50, 50, 50, 255) \ + NK_COLOR(NK_COLOR_BUTTON_HOVER, 40, 40, 40, 255) \ + NK_COLOR(NK_COLOR_BUTTON_ACTIVE, 35, 35, 35, 255) \ + NK_COLOR(NK_COLOR_TOGGLE, 100,100,100,255) \ + NK_COLOR(NK_COLOR_TOGGLE_HOVER, 120,120,120,255) \ + NK_COLOR(NK_COLOR_TOGGLE_CURSOR, 45, 45, 45, 255) \ + NK_COLOR(NK_COLOR_SELECT, 45, 45, 45, 255) \ + NK_COLOR(NK_COLOR_SELECT_ACTIVE, 35, 35, 35,255) \ + NK_COLOR(NK_COLOR_SLIDER, 38, 38, 38, 255) \ + NK_COLOR(NK_COLOR_SLIDER_CURSOR, 100,100,100,255) \ + NK_COLOR(NK_COLOR_SLIDER_CURSOR_HOVER, 120,120,120,255) \ + NK_COLOR(NK_COLOR_SLIDER_CURSOR_ACTIVE, 150,150,150,255) \ + NK_COLOR(NK_COLOR_PROPERTY, 38, 38, 38, 255) \ + NK_COLOR(NK_COLOR_EDIT, 38, 38, 38, 255) \ + NK_COLOR(NK_COLOR_EDIT_CURSOR, 175,175,175,255) \ + NK_COLOR(NK_COLOR_COMBO, 45, 45, 45, 255) \ + NK_COLOR(NK_COLOR_CHART, 120,120,120,255) \ + NK_COLOR(NK_COLOR_CHART_COLOR, 45, 45, 45, 255) \ + NK_COLOR(NK_COLOR_CHART_COLOR_HIGHLIGHT, 255, 0, 0, 255) \ + NK_COLOR(NK_COLOR_SCROLLBAR, 40, 40, 40, 255) \ + NK_COLOR(NK_COLOR_SCROLLBAR_CURSOR, 100,100,100,255) \ + NK_COLOR(NK_COLOR_SCROLLBAR_CURSOR_HOVER, 120,120,120,255) \ + NK_COLOR(NK_COLOR_SCROLLBAR_CURSOR_ACTIVE, 150,150,150,255) \ + NK_COLOR(NK_COLOR_TAB_HEADER, 40, 40, 40,255) + +NK_GLOBAL const struct nk_color +nk_default_color_style[NK_COLOR_COUNT] = { +#define NK_COLOR(a,b,c,d,e) {b,c,d,e}, + NK_COLOR_MAP(NK_COLOR) +#undef NK_COLOR +}; +NK_GLOBAL const char *nk_color_names[NK_COLOR_COUNT] = { +#define NK_COLOR(a,b,c,d,e) #a, + NK_COLOR_MAP(NK_COLOR) +#undef NK_COLOR +}; + +NK_API const char* +nk_style_get_color_by_name(enum nk_style_colors c) +{ + return nk_color_names[c]; +} +NK_API struct nk_style_item +nk_style_item_color(struct nk_color col) +{ + struct nk_style_item i; + i.type = NK_STYLE_ITEM_COLOR; + i.data.color = col; + return i; +} +NK_API struct nk_style_item +nk_style_item_image(struct nk_image img) +{ + struct nk_style_item i; + i.type = NK_STYLE_ITEM_IMAGE; + i.data.image = img; + return i; +} +NK_API struct nk_style_item +nk_style_item_nine_slice(struct nk_nine_slice slice) +{ + struct nk_style_item i; + i.type = NK_STYLE_ITEM_NINE_SLICE; + i.data.slice = slice; + return i; +} +NK_API struct nk_style_item +nk_style_item_hide(void) +{ + struct nk_style_item i; + i.type = NK_STYLE_ITEM_COLOR; + i.data.color = nk_rgba(0,0,0,0); + return i; +} +NK_API void +nk_style_from_table(struct nk_context *ctx, const struct nk_color *table) +{ + struct nk_style *style; + struct nk_style_text *text; + struct nk_style_button *button; + struct nk_style_toggle *toggle; + struct nk_style_selectable *select; + struct nk_style_slider *slider; + struct nk_style_progress *prog; + struct nk_style_scrollbar *scroll; + struct nk_style_edit *edit; + struct nk_style_property *property; + struct nk_style_combo *combo; + struct nk_style_chart *chart; + struct nk_style_tab *tab; + struct nk_style_window *win; + + NK_ASSERT(ctx); + if (!ctx) return; + style = &ctx->style; + table = (!table) ? nk_default_color_style: table; + + /* default text */ + text = &style->text; + text->color = table[NK_COLOR_TEXT]; + text->padding = nk_vec2(0,0); + + /* default button */ + button = &style->button; + nk_zero_struct(*button); + button->normal = nk_style_item_color(table[NK_COLOR_BUTTON]); + button->hover = nk_style_item_color(table[NK_COLOR_BUTTON_HOVER]); + button->active = nk_style_item_color(table[NK_COLOR_BUTTON_ACTIVE]); + button->border_color = table[NK_COLOR_BORDER]; + button->text_background = table[NK_COLOR_BUTTON]; + button->text_normal = table[NK_COLOR_TEXT]; + button->text_hover = table[NK_COLOR_TEXT]; + button->text_active = table[NK_COLOR_TEXT]; + button->padding = nk_vec2(2.0f,2.0f); + button->image_padding = nk_vec2(0.0f,0.0f); + button->touch_padding = nk_vec2(0.0f, 0.0f); + button->userdata = nk_handle_ptr(0); + button->text_alignment = NK_TEXT_CENTERED; + button->border = 1.0f; + button->rounding = 4.0f; + button->draw_begin = 0; + button->draw_end = 0; + + /* contextual button */ + button = &style->contextual_button; + nk_zero_struct(*button); + button->normal = nk_style_item_color(table[NK_COLOR_WINDOW]); + button->hover = nk_style_item_color(table[NK_COLOR_BUTTON_HOVER]); + button->active = nk_style_item_color(table[NK_COLOR_BUTTON_ACTIVE]); + button->border_color = table[NK_COLOR_WINDOW]; + button->text_background = table[NK_COLOR_WINDOW]; + button->text_normal = table[NK_COLOR_TEXT]; + button->text_hover = table[NK_COLOR_TEXT]; + button->text_active = table[NK_COLOR_TEXT]; + button->padding = nk_vec2(2.0f,2.0f); + button->touch_padding = nk_vec2(0.0f,0.0f); + button->userdata = nk_handle_ptr(0); + button->text_alignment = NK_TEXT_CENTERED; + button->border = 0.0f; + button->rounding = 0.0f; + button->draw_begin = 0; + button->draw_end = 0; + + /* menu button */ + button = &style->menu_button; + nk_zero_struct(*button); + button->normal = nk_style_item_color(table[NK_COLOR_WINDOW]); + button->hover = nk_style_item_color(table[NK_COLOR_WINDOW]); + button->active = nk_style_item_color(table[NK_COLOR_WINDOW]); + button->border_color = table[NK_COLOR_WINDOW]; + button->text_background = table[NK_COLOR_WINDOW]; + button->text_normal = table[NK_COLOR_TEXT]; + button->text_hover = table[NK_COLOR_TEXT]; + button->text_active = table[NK_COLOR_TEXT]; + button->padding = nk_vec2(2.0f,2.0f); + button->touch_padding = nk_vec2(0.0f,0.0f); + button->userdata = nk_handle_ptr(0); + button->text_alignment = NK_TEXT_CENTERED; + button->border = 0.0f; + button->rounding = 1.0f; + button->draw_begin = 0; + button->draw_end = 0; + + /* checkbox toggle */ + toggle = &style->checkbox; + nk_zero_struct(*toggle); + toggle->normal = nk_style_item_color(table[NK_COLOR_TOGGLE]); + toggle->hover = nk_style_item_color(table[NK_COLOR_TOGGLE_HOVER]); + toggle->active = nk_style_item_color(table[NK_COLOR_TOGGLE_HOVER]); + toggle->cursor_normal = nk_style_item_color(table[NK_COLOR_TOGGLE_CURSOR]); + toggle->cursor_hover = nk_style_item_color(table[NK_COLOR_TOGGLE_CURSOR]); + toggle->userdata = nk_handle_ptr(0); + toggle->text_background = table[NK_COLOR_WINDOW]; + toggle->text_normal = table[NK_COLOR_TEXT]; + toggle->text_hover = table[NK_COLOR_TEXT]; + toggle->text_active = table[NK_COLOR_TEXT]; + toggle->padding = nk_vec2(2.0f, 2.0f); + toggle->touch_padding = nk_vec2(0,0); + toggle->border_color = nk_rgba(0,0,0,0); + toggle->border = 0.0f; + toggle->spacing = 4; + + /* option toggle */ + toggle = &style->option; + nk_zero_struct(*toggle); + toggle->normal = nk_style_item_color(table[NK_COLOR_TOGGLE]); + toggle->hover = nk_style_item_color(table[NK_COLOR_TOGGLE_HOVER]); + toggle->active = nk_style_item_color(table[NK_COLOR_TOGGLE_HOVER]); + toggle->cursor_normal = nk_style_item_color(table[NK_COLOR_TOGGLE_CURSOR]); + toggle->cursor_hover = nk_style_item_color(table[NK_COLOR_TOGGLE_CURSOR]); + toggle->userdata = nk_handle_ptr(0); + toggle->text_background = table[NK_COLOR_WINDOW]; + toggle->text_normal = table[NK_COLOR_TEXT]; + toggle->text_hover = table[NK_COLOR_TEXT]; + toggle->text_active = table[NK_COLOR_TEXT]; + toggle->padding = nk_vec2(3.0f, 3.0f); + toggle->touch_padding = nk_vec2(0,0); + toggle->border_color = nk_rgba(0,0,0,0); + toggle->border = 0.0f; + toggle->spacing = 4; + + /* selectable */ + select = &style->selectable; + nk_zero_struct(*select); + select->normal = nk_style_item_color(table[NK_COLOR_SELECT]); + select->hover = nk_style_item_color(table[NK_COLOR_SELECT]); + select->pressed = nk_style_item_color(table[NK_COLOR_SELECT]); + select->normal_active = nk_style_item_color(table[NK_COLOR_SELECT_ACTIVE]); + select->hover_active = nk_style_item_color(table[NK_COLOR_SELECT_ACTIVE]); + select->pressed_active = nk_style_item_color(table[NK_COLOR_SELECT_ACTIVE]); + select->text_normal = table[NK_COLOR_TEXT]; + select->text_hover = table[NK_COLOR_TEXT]; + select->text_pressed = table[NK_COLOR_TEXT]; + select->text_normal_active = table[NK_COLOR_TEXT]; + select->text_hover_active = table[NK_COLOR_TEXT]; + select->text_pressed_active = table[NK_COLOR_TEXT]; + select->padding = nk_vec2(2.0f,2.0f); + select->image_padding = nk_vec2(2.0f,2.0f); + select->touch_padding = nk_vec2(0,0); + select->userdata = nk_handle_ptr(0); + select->rounding = 0.0f; + select->draw_begin = 0; + select->draw_end = 0; + + /* slider */ + slider = &style->slider; + nk_zero_struct(*slider); + slider->normal = nk_style_item_hide(); + slider->hover = nk_style_item_hide(); + slider->active = nk_style_item_hide(); + slider->bar_normal = table[NK_COLOR_SLIDER]; + slider->bar_hover = table[NK_COLOR_SLIDER]; + slider->bar_active = table[NK_COLOR_SLIDER]; + slider->bar_filled = table[NK_COLOR_SLIDER_CURSOR]; + slider->cursor_normal = nk_style_item_color(table[NK_COLOR_SLIDER_CURSOR]); + slider->cursor_hover = nk_style_item_color(table[NK_COLOR_SLIDER_CURSOR_HOVER]); + slider->cursor_active = nk_style_item_color(table[NK_COLOR_SLIDER_CURSOR_ACTIVE]); + slider->inc_symbol = NK_SYMBOL_TRIANGLE_RIGHT; + slider->dec_symbol = NK_SYMBOL_TRIANGLE_LEFT; + slider->cursor_size = nk_vec2(16,16); + slider->padding = nk_vec2(2,2); + slider->spacing = nk_vec2(2,2); + slider->userdata = nk_handle_ptr(0); + slider->show_buttons = nk_false; + slider->bar_height = 8; + slider->rounding = 0; + slider->draw_begin = 0; + slider->draw_end = 0; + + /* slider buttons */ + button = &style->slider.inc_button; + button->normal = nk_style_item_color(nk_rgb(40,40,40)); + button->hover = nk_style_item_color(nk_rgb(42,42,42)); + button->active = nk_style_item_color(nk_rgb(44,44,44)); + button->border_color = nk_rgb(65,65,65); + button->text_background = nk_rgb(40,40,40); + button->text_normal = nk_rgb(175,175,175); + button->text_hover = nk_rgb(175,175,175); + button->text_active = nk_rgb(175,175,175); + button->padding = nk_vec2(8.0f,8.0f); + button->touch_padding = nk_vec2(0.0f,0.0f); + button->userdata = nk_handle_ptr(0); + button->text_alignment = NK_TEXT_CENTERED; + button->border = 1.0f; + button->rounding = 0.0f; + button->draw_begin = 0; + button->draw_end = 0; + style->slider.dec_button = style->slider.inc_button; + + /* progressbar */ + prog = &style->progress; + nk_zero_struct(*prog); + prog->normal = nk_style_item_color(table[NK_COLOR_SLIDER]); + prog->hover = nk_style_item_color(table[NK_COLOR_SLIDER]); + prog->active = nk_style_item_color(table[NK_COLOR_SLIDER]); + prog->cursor_normal = nk_style_item_color(table[NK_COLOR_SLIDER_CURSOR]); + prog->cursor_hover = nk_style_item_color(table[NK_COLOR_SLIDER_CURSOR_HOVER]); + prog->cursor_active = nk_style_item_color(table[NK_COLOR_SLIDER_CURSOR_ACTIVE]); + prog->border_color = nk_rgba(0,0,0,0); + prog->cursor_border_color = nk_rgba(0,0,0,0); + prog->userdata = nk_handle_ptr(0); + prog->padding = nk_vec2(4,4); + prog->rounding = 0; + prog->border = 0; + prog->cursor_rounding = 0; + prog->cursor_border = 0; + prog->draw_begin = 0; + prog->draw_end = 0; + + /* scrollbars */ + scroll = &style->scrollh; + nk_zero_struct(*scroll); + scroll->normal = nk_style_item_color(table[NK_COLOR_SCROLLBAR]); + scroll->hover = nk_style_item_color(table[NK_COLOR_SCROLLBAR]); + scroll->active = nk_style_item_color(table[NK_COLOR_SCROLLBAR]); + scroll->cursor_normal = nk_style_item_color(table[NK_COLOR_SCROLLBAR_CURSOR]); + scroll->cursor_hover = nk_style_item_color(table[NK_COLOR_SCROLLBAR_CURSOR_HOVER]); + scroll->cursor_active = nk_style_item_color(table[NK_COLOR_SCROLLBAR_CURSOR_ACTIVE]); + scroll->dec_symbol = NK_SYMBOL_CIRCLE_SOLID; + scroll->inc_symbol = NK_SYMBOL_CIRCLE_SOLID; + scroll->userdata = nk_handle_ptr(0); + scroll->border_color = table[NK_COLOR_SCROLLBAR]; + scroll->cursor_border_color = table[NK_COLOR_SCROLLBAR]; + scroll->padding = nk_vec2(0,0); + scroll->show_buttons = nk_false; + scroll->border = 0; + scroll->rounding = 0; + scroll->border_cursor = 0; + scroll->rounding_cursor = 0; + scroll->draw_begin = 0; + scroll->draw_end = 0; + style->scrollv = style->scrollh; + + /* scrollbars buttons */ + button = &style->scrollh.inc_button; + button->normal = nk_style_item_color(nk_rgb(40,40,40)); + button->hover = nk_style_item_color(nk_rgb(42,42,42)); + button->active = nk_style_item_color(nk_rgb(44,44,44)); + button->border_color = nk_rgb(65,65,65); + button->text_background = nk_rgb(40,40,40); + button->text_normal = nk_rgb(175,175,175); + button->text_hover = nk_rgb(175,175,175); + button->text_active = nk_rgb(175,175,175); + button->padding = nk_vec2(4.0f,4.0f); + button->touch_padding = nk_vec2(0.0f,0.0f); + button->userdata = nk_handle_ptr(0); + button->text_alignment = NK_TEXT_CENTERED; + button->border = 1.0f; + button->rounding = 0.0f; + button->draw_begin = 0; + button->draw_end = 0; + style->scrollh.dec_button = style->scrollh.inc_button; + style->scrollv.inc_button = style->scrollh.inc_button; + style->scrollv.dec_button = style->scrollh.inc_button; + + /* edit */ + edit = &style->edit; + nk_zero_struct(*edit); + edit->normal = nk_style_item_color(table[NK_COLOR_EDIT]); + edit->hover = nk_style_item_color(table[NK_COLOR_EDIT]); + edit->active = nk_style_item_color(table[NK_COLOR_EDIT]); + edit->cursor_normal = table[NK_COLOR_TEXT]; + edit->cursor_hover = table[NK_COLOR_TEXT]; + edit->cursor_text_normal= table[NK_COLOR_EDIT]; + edit->cursor_text_hover = table[NK_COLOR_EDIT]; + edit->border_color = table[NK_COLOR_BORDER]; + edit->text_normal = table[NK_COLOR_TEXT]; + edit->text_hover = table[NK_COLOR_TEXT]; + edit->text_active = table[NK_COLOR_TEXT]; + edit->selected_normal = table[NK_COLOR_TEXT]; + edit->selected_hover = table[NK_COLOR_TEXT]; + edit->selected_text_normal = table[NK_COLOR_EDIT]; + edit->selected_text_hover = table[NK_COLOR_EDIT]; + edit->scrollbar_size = nk_vec2(10,10); + edit->scrollbar = style->scrollv; + edit->padding = nk_vec2(4,4); + edit->row_padding = 2; + edit->cursor_size = 4; + edit->border = 1; + edit->rounding = 0; + + /* property */ + property = &style->property; + nk_zero_struct(*property); + property->normal = nk_style_item_color(table[NK_COLOR_PROPERTY]); + property->hover = nk_style_item_color(table[NK_COLOR_PROPERTY]); + property->active = nk_style_item_color(table[NK_COLOR_PROPERTY]); + property->border_color = table[NK_COLOR_BORDER]; + property->label_normal = table[NK_COLOR_TEXT]; + property->label_hover = table[NK_COLOR_TEXT]; + property->label_active = table[NK_COLOR_TEXT]; + property->sym_left = NK_SYMBOL_TRIANGLE_LEFT; + property->sym_right = NK_SYMBOL_TRIANGLE_RIGHT; + property->userdata = nk_handle_ptr(0); + property->padding = nk_vec2(4,4); + property->border = 1; + property->rounding = 10; + property->draw_begin = 0; + property->draw_end = 0; + + /* property buttons */ + button = &style->property.dec_button; + nk_zero_struct(*button); + button->normal = nk_style_item_color(table[NK_COLOR_PROPERTY]); + button->hover = nk_style_item_color(table[NK_COLOR_PROPERTY]); + button->active = nk_style_item_color(table[NK_COLOR_PROPERTY]); + button->border_color = nk_rgba(0,0,0,0); + button->text_background = table[NK_COLOR_PROPERTY]; + button->text_normal = table[NK_COLOR_TEXT]; + button->text_hover = table[NK_COLOR_TEXT]; + button->text_active = table[NK_COLOR_TEXT]; + button->padding = nk_vec2(0.0f,0.0f); + button->touch_padding = nk_vec2(0.0f,0.0f); + button->userdata = nk_handle_ptr(0); + button->text_alignment = NK_TEXT_CENTERED; + button->border = 0.0f; + button->rounding = 0.0f; + button->draw_begin = 0; + button->draw_end = 0; + style->property.inc_button = style->property.dec_button; + + /* property edit */ + edit = &style->property.edit; + nk_zero_struct(*edit); + edit->normal = nk_style_item_color(table[NK_COLOR_PROPERTY]); + edit->hover = nk_style_item_color(table[NK_COLOR_PROPERTY]); + edit->active = nk_style_item_color(table[NK_COLOR_PROPERTY]); + edit->border_color = nk_rgba(0,0,0,0); + edit->cursor_normal = table[NK_COLOR_TEXT]; + edit->cursor_hover = table[NK_COLOR_TEXT]; + edit->cursor_text_normal= table[NK_COLOR_EDIT]; + edit->cursor_text_hover = table[NK_COLOR_EDIT]; + edit->text_normal = table[NK_COLOR_TEXT]; + edit->text_hover = table[NK_COLOR_TEXT]; + edit->text_active = table[NK_COLOR_TEXT]; + edit->selected_normal = table[NK_COLOR_TEXT]; + edit->selected_hover = table[NK_COLOR_TEXT]; + edit->selected_text_normal = table[NK_COLOR_EDIT]; + edit->selected_text_hover = table[NK_COLOR_EDIT]; + edit->padding = nk_vec2(0,0); + edit->cursor_size = 8; + edit->border = 0; + edit->rounding = 0; + + /* chart */ + chart = &style->chart; + nk_zero_struct(*chart); + chart->background = nk_style_item_color(table[NK_COLOR_CHART]); + chart->border_color = table[NK_COLOR_BORDER]; + chart->selected_color = table[NK_COLOR_CHART_COLOR_HIGHLIGHT]; + chart->color = table[NK_COLOR_CHART_COLOR]; + chart->padding = nk_vec2(4,4); + chart->border = 0; + chart->rounding = 0; + + /* combo */ + combo = &style->combo; + combo->normal = nk_style_item_color(table[NK_COLOR_COMBO]); + combo->hover = nk_style_item_color(table[NK_COLOR_COMBO]); + combo->active = nk_style_item_color(table[NK_COLOR_COMBO]); + combo->border_color = table[NK_COLOR_BORDER]; + combo->label_normal = table[NK_COLOR_TEXT]; + combo->label_hover = table[NK_COLOR_TEXT]; + combo->label_active = table[NK_COLOR_TEXT]; + combo->sym_normal = NK_SYMBOL_TRIANGLE_DOWN; + combo->sym_hover = NK_SYMBOL_TRIANGLE_DOWN; + combo->sym_active = NK_SYMBOL_TRIANGLE_DOWN; + combo->content_padding = nk_vec2(4,4); + combo->button_padding = nk_vec2(0,4); + combo->spacing = nk_vec2(4,0); + combo->border = 1; + combo->rounding = 0; + + /* combo button */ + button = &style->combo.button; + nk_zero_struct(*button); + button->normal = nk_style_item_color(table[NK_COLOR_COMBO]); + button->hover = nk_style_item_color(table[NK_COLOR_COMBO]); + button->active = nk_style_item_color(table[NK_COLOR_COMBO]); + button->border_color = nk_rgba(0,0,0,0); + button->text_background = table[NK_COLOR_COMBO]; + button->text_normal = table[NK_COLOR_TEXT]; + button->text_hover = table[NK_COLOR_TEXT]; + button->text_active = table[NK_COLOR_TEXT]; + button->padding = nk_vec2(2.0f,2.0f); + button->touch_padding = nk_vec2(0.0f,0.0f); + button->userdata = nk_handle_ptr(0); + button->text_alignment = NK_TEXT_CENTERED; + button->border = 0.0f; + button->rounding = 0.0f; + button->draw_begin = 0; + button->draw_end = 0; + + /* tab */ + tab = &style->tab; + tab->background = nk_style_item_color(table[NK_COLOR_TAB_HEADER]); + tab->border_color = table[NK_COLOR_BORDER]; + tab->text = table[NK_COLOR_TEXT]; + tab->sym_minimize = NK_SYMBOL_TRIANGLE_RIGHT; + tab->sym_maximize = NK_SYMBOL_TRIANGLE_DOWN; + tab->padding = nk_vec2(4,4); + tab->spacing = nk_vec2(4,4); + tab->indent = 10.0f; + tab->border = 1; + tab->rounding = 0; + + /* tab button */ + button = &style->tab.tab_minimize_button; + nk_zero_struct(*button); + button->normal = nk_style_item_color(table[NK_COLOR_TAB_HEADER]); + button->hover = nk_style_item_color(table[NK_COLOR_TAB_HEADER]); + button->active = nk_style_item_color(table[NK_COLOR_TAB_HEADER]); + button->border_color = nk_rgba(0,0,0,0); + button->text_background = table[NK_COLOR_TAB_HEADER]; + button->text_normal = table[NK_COLOR_TEXT]; + button->text_hover = table[NK_COLOR_TEXT]; + button->text_active = table[NK_COLOR_TEXT]; + button->padding = nk_vec2(2.0f,2.0f); + button->touch_padding = nk_vec2(0.0f,0.0f); + button->userdata = nk_handle_ptr(0); + button->text_alignment = NK_TEXT_CENTERED; + button->border = 0.0f; + button->rounding = 0.0f; + button->draw_begin = 0; + button->draw_end = 0; + style->tab.tab_maximize_button =*button; + + /* node button */ + button = &style->tab.node_minimize_button; + nk_zero_struct(*button); + button->normal = nk_style_item_color(table[NK_COLOR_WINDOW]); + button->hover = nk_style_item_color(table[NK_COLOR_WINDOW]); + button->active = nk_style_item_color(table[NK_COLOR_WINDOW]); + button->border_color = nk_rgba(0,0,0,0); + button->text_background = table[NK_COLOR_TAB_HEADER]; + button->text_normal = table[NK_COLOR_TEXT]; + button->text_hover = table[NK_COLOR_TEXT]; + button->text_active = table[NK_COLOR_TEXT]; + button->padding = nk_vec2(2.0f,2.0f); + button->touch_padding = nk_vec2(0.0f,0.0f); + button->userdata = nk_handle_ptr(0); + button->text_alignment = NK_TEXT_CENTERED; + button->border = 0.0f; + button->rounding = 0.0f; + button->draw_begin = 0; + button->draw_end = 0; + style->tab.node_maximize_button =*button; + + /* window header */ + win = &style->window; + win->header.align = NK_HEADER_RIGHT; + win->header.close_symbol = NK_SYMBOL_X; + win->header.minimize_symbol = NK_SYMBOL_MINUS; + win->header.maximize_symbol = NK_SYMBOL_PLUS; + win->header.normal = nk_style_item_color(table[NK_COLOR_HEADER]); + win->header.hover = nk_style_item_color(table[NK_COLOR_HEADER]); + win->header.active = nk_style_item_color(table[NK_COLOR_HEADER]); + win->header.label_normal = table[NK_COLOR_TEXT]; + win->header.label_hover = table[NK_COLOR_TEXT]; + win->header.label_active = table[NK_COLOR_TEXT]; + win->header.label_padding = nk_vec2(4,4); + win->header.padding = nk_vec2(4,4); + win->header.spacing = nk_vec2(0,0); + + /* window header close button */ + button = &style->window.header.close_button; + nk_zero_struct(*button); + button->normal = nk_style_item_color(table[NK_COLOR_HEADER]); + button->hover = nk_style_item_color(table[NK_COLOR_HEADER]); + button->active = nk_style_item_color(table[NK_COLOR_HEADER]); + button->border_color = nk_rgba(0,0,0,0); + button->text_background = table[NK_COLOR_HEADER]; + button->text_normal = table[NK_COLOR_TEXT]; + button->text_hover = table[NK_COLOR_TEXT]; + button->text_active = table[NK_COLOR_TEXT]; + button->padding = nk_vec2(0.0f,0.0f); + button->touch_padding = nk_vec2(0.0f,0.0f); + button->userdata = nk_handle_ptr(0); + button->text_alignment = NK_TEXT_CENTERED; + button->border = 0.0f; + button->rounding = 0.0f; + button->draw_begin = 0; + button->draw_end = 0; + + /* window header minimize button */ + button = &style->window.header.minimize_button; + nk_zero_struct(*button); + button->normal = nk_style_item_color(table[NK_COLOR_HEADER]); + button->hover = nk_style_item_color(table[NK_COLOR_HEADER]); + button->active = nk_style_item_color(table[NK_COLOR_HEADER]); + button->border_color = nk_rgba(0,0,0,0); + button->text_background = table[NK_COLOR_HEADER]; + button->text_normal = table[NK_COLOR_TEXT]; + button->text_hover = table[NK_COLOR_TEXT]; + button->text_active = table[NK_COLOR_TEXT]; + button->padding = nk_vec2(0.0f,0.0f); + button->touch_padding = nk_vec2(0.0f,0.0f); + button->userdata = nk_handle_ptr(0); + button->text_alignment = NK_TEXT_CENTERED; + button->border = 0.0f; + button->rounding = 0.0f; + button->draw_begin = 0; + button->draw_end = 0; + + /* window */ + win->background = table[NK_COLOR_WINDOW]; + win->fixed_background = nk_style_item_color(table[NK_COLOR_WINDOW]); + win->border_color = table[NK_COLOR_BORDER]; + win->popup_border_color = table[NK_COLOR_BORDER]; + win->combo_border_color = table[NK_COLOR_BORDER]; + win->contextual_border_color = table[NK_COLOR_BORDER]; + win->menu_border_color = table[NK_COLOR_BORDER]; + win->group_border_color = table[NK_COLOR_BORDER]; + win->tooltip_border_color = table[NK_COLOR_BORDER]; + win->scaler = nk_style_item_color(table[NK_COLOR_TEXT]); + + win->rounding = 0.0f; + win->spacing = nk_vec2(4,4); + win->scrollbar_size = nk_vec2(10,10); + win->min_size = nk_vec2(64,64); + + win->combo_border = 1.0f; + win->contextual_border = 1.0f; + win->menu_border = 1.0f; + win->group_border = 1.0f; + win->tooltip_border = 1.0f; + win->popup_border = 1.0f; + win->border = 2.0f; + win->min_row_height_padding = 8; + + win->padding = nk_vec2(4,4); + win->group_padding = nk_vec2(4,4); + win->popup_padding = nk_vec2(4,4); + win->combo_padding = nk_vec2(4,4); + win->contextual_padding = nk_vec2(4,4); + win->menu_padding = nk_vec2(4,4); + win->tooltip_padding = nk_vec2(4,4); +} +NK_API void +nk_style_set_font(struct nk_context *ctx, const struct nk_user_font *font) +{ + struct nk_style *style; + NK_ASSERT(ctx); + + if (!ctx) return; + style = &ctx->style; + style->font = font; + ctx->stacks.fonts.head = 0; + if (ctx->current) + nk_layout_reset_min_row_height(ctx); +} +NK_API nk_bool +nk_style_push_font(struct nk_context *ctx, const struct nk_user_font *font) +{ + struct nk_config_stack_user_font *font_stack; + struct nk_config_stack_user_font_element *element; + + NK_ASSERT(ctx); + if (!ctx) return 0; + + font_stack = &ctx->stacks.fonts; + NK_ASSERT(font_stack->head < (int)NK_LEN(font_stack->elements)); + if (font_stack->head >= (int)NK_LEN(font_stack->elements)) + return 0; + + element = &font_stack->elements[font_stack->head++]; + element->address = &ctx->style.font; + element->old_value = ctx->style.font; + ctx->style.font = font; + return 1; +} +NK_API nk_bool +nk_style_pop_font(struct nk_context *ctx) +{ + struct nk_config_stack_user_font *font_stack; + struct nk_config_stack_user_font_element *element; + + NK_ASSERT(ctx); + if (!ctx) return 0; + + font_stack = &ctx->stacks.fonts; + NK_ASSERT(font_stack->head > 0); + if (font_stack->head < 1) + return 0; + + element = &font_stack->elements[--font_stack->head]; + *element->address = element->old_value; + return 1; +} +#define NK_STYLE_PUSH_IMPLEMENATION(prefix, type, stack) \ +nk_style_push_##type(struct nk_context *ctx, prefix##_##type *address, prefix##_##type value)\ +{\ + struct nk_config_stack_##type * type_stack;\ + struct nk_config_stack_##type##_element *element;\ + NK_ASSERT(ctx);\ + if (!ctx) return 0;\ + type_stack = &ctx->stacks.stack;\ + NK_ASSERT(type_stack->head < (int)NK_LEN(type_stack->elements));\ + if (type_stack->head >= (int)NK_LEN(type_stack->elements))\ + return 0;\ + element = &type_stack->elements[type_stack->head++];\ + element->address = address;\ + element->old_value = *address;\ + *address = value;\ + return 1;\ +} +#define NK_STYLE_POP_IMPLEMENATION(type, stack) \ +nk_style_pop_##type(struct nk_context *ctx)\ +{\ + struct nk_config_stack_##type *type_stack;\ + struct nk_config_stack_##type##_element *element;\ + NK_ASSERT(ctx);\ + if (!ctx) return 0;\ + type_stack = &ctx->stacks.stack;\ + NK_ASSERT(type_stack->head > 0);\ + if (type_stack->head < 1)\ + return 0;\ + element = &type_stack->elements[--type_stack->head];\ + *element->address = element->old_value;\ + return 1;\ +} +NK_API nk_bool NK_STYLE_PUSH_IMPLEMENATION(struct nk, style_item, style_items) +NK_API nk_bool NK_STYLE_PUSH_IMPLEMENATION(nk,float, floats) +NK_API nk_bool NK_STYLE_PUSH_IMPLEMENATION(struct nk, vec2, vectors) +NK_API nk_bool NK_STYLE_PUSH_IMPLEMENATION(nk,flags, flags) +NK_API nk_bool NK_STYLE_PUSH_IMPLEMENATION(struct nk,color, colors) + +NK_API nk_bool NK_STYLE_POP_IMPLEMENATION(style_item, style_items) +NK_API nk_bool NK_STYLE_POP_IMPLEMENATION(float,floats) +NK_API nk_bool NK_STYLE_POP_IMPLEMENATION(vec2, vectors) +NK_API nk_bool NK_STYLE_POP_IMPLEMENATION(flags,flags) +NK_API nk_bool NK_STYLE_POP_IMPLEMENATION(color,colors) + +NK_API nk_bool +nk_style_set_cursor(struct nk_context *ctx, enum nk_style_cursor c) +{ + struct nk_style *style; + NK_ASSERT(ctx); + if (!ctx) return 0; + style = &ctx->style; + if (style->cursors[c]) { + style->cursor_active = style->cursors[c]; + return 1; + } + return 0; +} +NK_API void +nk_style_show_cursor(struct nk_context *ctx) +{ + ctx->style.cursor_visible = nk_true; +} +NK_API void +nk_style_hide_cursor(struct nk_context *ctx) +{ + ctx->style.cursor_visible = nk_false; +} +NK_API void +nk_style_load_cursor(struct nk_context *ctx, enum nk_style_cursor cursor, + const struct nk_cursor *c) +{ + struct nk_style *style; + NK_ASSERT(ctx); + if (!ctx) return; + style = &ctx->style; + style->cursors[cursor] = c; +} +NK_API void +nk_style_load_all_cursors(struct nk_context *ctx, struct nk_cursor *cursors) +{ + int i = 0; + struct nk_style *style; + NK_ASSERT(ctx); + if (!ctx) return; + style = &ctx->style; + for (i = 0; i < NK_CURSOR_COUNT; ++i) + style->cursors[i] = &cursors[i]; + style->cursor_visible = nk_true; +} + + + + + +/* ============================================================== + * + * CONTEXT + * + * ===============================================================*/ +NK_INTERN void +nk_setup(struct nk_context *ctx, const struct nk_user_font *font) +{ + NK_ASSERT(ctx); + if (!ctx) return; + nk_zero_struct(*ctx); + nk_style_default(ctx); + ctx->seq = 1; + if (font) ctx->style.font = font; +#ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT + nk_draw_list_init(&ctx->draw_list); +#endif +} +#ifdef NK_INCLUDE_DEFAULT_ALLOCATOR +NK_API nk_bool +nk_init_default(struct nk_context *ctx, const struct nk_user_font *font) +{ + struct nk_allocator alloc; + alloc.userdata.ptr = 0; + alloc.alloc = nk_malloc; + alloc.free = nk_mfree; + return nk_init(ctx, &alloc, font); +} +#endif +NK_API nk_bool +nk_init_fixed(struct nk_context *ctx, void *memory, nk_size size, + const struct nk_user_font *font) +{ + NK_ASSERT(memory); + if (!memory) return 0; + nk_setup(ctx, font); + nk_buffer_init_fixed(&ctx->memory, memory, size); + ctx->use_pool = nk_false; + return 1; +} +NK_API nk_bool +nk_init_custom(struct nk_context *ctx, struct nk_buffer *cmds, + struct nk_buffer *pool, const struct nk_user_font *font) +{ + NK_ASSERT(cmds); + NK_ASSERT(pool); + if (!cmds || !pool) return 0; + + nk_setup(ctx, font); + ctx->memory = *cmds; + if (pool->type == NK_BUFFER_FIXED) { + /* take memory from buffer and alloc fixed pool */ + nk_pool_init_fixed(&ctx->pool, pool->memory.ptr, pool->memory.size); + } else { + /* create dynamic pool from buffer allocator */ + struct nk_allocator *alloc = &pool->pool; + nk_pool_init(&ctx->pool, alloc, NK_POOL_DEFAULT_CAPACITY); + } + ctx->use_pool = nk_true; + return 1; +} +NK_API nk_bool +nk_init(struct nk_context *ctx, struct nk_allocator *alloc, + const struct nk_user_font *font) +{ + NK_ASSERT(alloc); + if (!alloc) return 0; + nk_setup(ctx, font); + nk_buffer_init(&ctx->memory, alloc, NK_DEFAULT_COMMAND_BUFFER_SIZE); + nk_pool_init(&ctx->pool, alloc, NK_POOL_DEFAULT_CAPACITY); + ctx->use_pool = nk_true; + return 1; +} +#ifdef NK_INCLUDE_COMMAND_USERDATA +NK_API void +nk_set_user_data(struct nk_context *ctx, nk_handle handle) +{ + if (!ctx) return; + ctx->userdata = handle; + if (ctx->current) + ctx->current->buffer.userdata = handle; +} +#endif +NK_API void +nk_free(struct nk_context *ctx) +{ + NK_ASSERT(ctx); + if (!ctx) return; + nk_buffer_free(&ctx->memory); + if (ctx->use_pool) + nk_pool_free(&ctx->pool); + + nk_zero(&ctx->input, sizeof(ctx->input)); + nk_zero(&ctx->style, sizeof(ctx->style)); + nk_zero(&ctx->memory, sizeof(ctx->memory)); + + ctx->seq = 0; + ctx->build = 0; + ctx->begin = 0; + ctx->end = 0; + ctx->active = 0; + ctx->current = 0; + ctx->freelist = 0; + ctx->count = 0; +} +NK_API void +nk_clear(struct nk_context *ctx) +{ + struct nk_window *iter; + struct nk_window *next; + NK_ASSERT(ctx); + + if (!ctx) return; + if (ctx->use_pool) + nk_buffer_clear(&ctx->memory); + else nk_buffer_reset(&ctx->memory, NK_BUFFER_FRONT); + + ctx->build = 0; + ctx->memory.calls = 0; + ctx->last_widget_state = 0; + ctx->style.cursor_active = ctx->style.cursors[NK_CURSOR_ARROW]; + NK_MEMSET(&ctx->overlay, 0, sizeof(ctx->overlay)); + + /* garbage collector */ + iter = ctx->begin; + while (iter) { + /* make sure valid minimized windows do not get removed */ + if ((iter->flags & NK_WINDOW_MINIMIZED) && + !(iter->flags & NK_WINDOW_CLOSED) && + iter->seq == ctx->seq) { + iter = iter->next; + continue; + } + /* remove hotness from hidden or closed windows*/ + if (((iter->flags & NK_WINDOW_HIDDEN) || + (iter->flags & NK_WINDOW_CLOSED)) && + iter == ctx->active) { + ctx->active = iter->prev; + ctx->end = iter->prev; + if (!ctx->end) + ctx->begin = 0; + if (ctx->active) + ctx->active->flags &= ~(unsigned)NK_WINDOW_ROM; + } + /* free unused popup windows */ + if (iter->popup.win && iter->popup.win->seq != ctx->seq) { + nk_free_window(ctx, iter->popup.win); + iter->popup.win = 0; + } + /* remove unused window state tables */ + {struct nk_table *n, *it = iter->tables; + while (it) { + n = it->next; + if (it->seq != ctx->seq) { + nk_remove_table(iter, it); + nk_zero(it, sizeof(union nk_page_data)); + nk_free_table(ctx, it); + if (it == iter->tables) + iter->tables = n; + } it = n; + }} + /* window itself is not used anymore so free */ + if (iter->seq != ctx->seq || iter->flags & NK_WINDOW_CLOSED) { + next = iter->next; + nk_remove_window(ctx, iter); + nk_free_window(ctx, iter); + iter = next; + } else iter = iter->next; + } + ctx->seq++; +} +NK_LIB void +nk_start_buffer(struct nk_context *ctx, struct nk_command_buffer *buffer) +{ + NK_ASSERT(ctx); + NK_ASSERT(buffer); + if (!ctx || !buffer) return; + buffer->begin = ctx->memory.allocated; + buffer->end = buffer->begin; + buffer->last = buffer->begin; + buffer->clip = nk_null_rect; +} +NK_LIB void +nk_start(struct nk_context *ctx, struct nk_window *win) +{ + NK_ASSERT(ctx); + NK_ASSERT(win); + nk_start_buffer(ctx, &win->buffer); +} +NK_LIB void +nk_start_popup(struct nk_context *ctx, struct nk_window *win) +{ + struct nk_popup_buffer *buf; + NK_ASSERT(ctx); + NK_ASSERT(win); + if (!ctx || !win) return; + + /* save buffer fill state for popup */ + buf = &win->popup.buf; + buf->begin = win->buffer.end; + buf->end = win->buffer.end; + buf->parent = win->buffer.last; + buf->last = buf->begin; + buf->active = nk_true; +} +NK_LIB void +nk_finish_popup(struct nk_context *ctx, struct nk_window *win) +{ + struct nk_popup_buffer *buf; + NK_ASSERT(ctx); + NK_ASSERT(win); + if (!ctx || !win) return; + + buf = &win->popup.buf; + buf->last = win->buffer.last; + buf->end = win->buffer.end; +} +NK_LIB void +nk_finish_buffer(struct nk_context *ctx, struct nk_command_buffer *buffer) +{ + NK_ASSERT(ctx); + NK_ASSERT(buffer); + if (!ctx || !buffer) return; + buffer->end = ctx->memory.allocated; +} +NK_LIB void +nk_finish(struct nk_context *ctx, struct nk_window *win) +{ + struct nk_popup_buffer *buf; + struct nk_command *parent_last; + void *memory; + + NK_ASSERT(ctx); + NK_ASSERT(win); + if (!ctx || !win) return; + nk_finish_buffer(ctx, &win->buffer); + if (!win->popup.buf.active) return; + + buf = &win->popup.buf; + memory = ctx->memory.memory.ptr; + parent_last = nk_ptr_add(struct nk_command, memory, buf->parent); + parent_last->next = buf->end; +} +NK_LIB void +nk_build(struct nk_context *ctx) +{ + struct nk_window *it = 0; + struct nk_command *cmd = 0; + nk_byte *buffer = 0; + + /* draw cursor overlay */ + if (!ctx->style.cursor_active) + ctx->style.cursor_active = ctx->style.cursors[NK_CURSOR_ARROW]; + if (ctx->style.cursor_active && !ctx->input.mouse.grabbed && ctx->style.cursor_visible) { + struct nk_rect mouse_bounds; + const struct nk_cursor *cursor = ctx->style.cursor_active; + nk_command_buffer_init(&ctx->overlay, &ctx->memory, NK_CLIPPING_OFF); + nk_start_buffer(ctx, &ctx->overlay); + + mouse_bounds.x = ctx->input.mouse.pos.x - cursor->offset.x; + mouse_bounds.y = ctx->input.mouse.pos.y - cursor->offset.y; + mouse_bounds.w = cursor->size.x; + mouse_bounds.h = cursor->size.y; + + nk_draw_image(&ctx->overlay, mouse_bounds, &cursor->img, nk_white); + nk_finish_buffer(ctx, &ctx->overlay); + } + /* build one big draw command list out of all window buffers */ + it = ctx->begin; + buffer = (nk_byte*)ctx->memory.memory.ptr; + while (it != 0) { + struct nk_window *next = it->next; + if (it->buffer.last == it->buffer.begin || (it->flags & NK_WINDOW_HIDDEN)|| + it->seq != ctx->seq) + goto cont; + + cmd = nk_ptr_add(struct nk_command, buffer, it->buffer.last); + while (next && ((next->buffer.last == next->buffer.begin) || + (next->flags & NK_WINDOW_HIDDEN) || next->seq != ctx->seq)) + next = next->next; /* skip empty command buffers */ + + if (next) cmd->next = next->buffer.begin; + cont: it = next; + } + /* append all popup draw commands into lists */ + it = ctx->begin; + while (it != 0) { + struct nk_window *next = it->next; + struct nk_popup_buffer *buf; + if (!it->popup.buf.active) + goto skip; + + buf = &it->popup.buf; + cmd->next = buf->begin; + cmd = nk_ptr_add(struct nk_command, buffer, buf->last); + buf->active = nk_false; + skip: it = next; + } + if (cmd) { + /* append overlay commands */ + if (ctx->overlay.end != ctx->overlay.begin) + cmd->next = ctx->overlay.begin; + else cmd->next = ctx->memory.allocated; + } +} +NK_API const struct nk_command* +nk__begin(struct nk_context *ctx) +{ + struct nk_window *iter; + nk_byte *buffer; + NK_ASSERT(ctx); + if (!ctx) return 0; + if (!ctx->count) return 0; + + buffer = (nk_byte*)ctx->memory.memory.ptr; + if (!ctx->build) { + nk_build(ctx); + ctx->build = nk_true; + } + iter = ctx->begin; + while (iter && ((iter->buffer.begin == iter->buffer.end) || + (iter->flags & NK_WINDOW_HIDDEN) || iter->seq != ctx->seq)) + iter = iter->next; + if (!iter) return 0; + return nk_ptr_add_const(struct nk_command, buffer, iter->buffer.begin); +} + +NK_API const struct nk_command* +nk__next(struct nk_context *ctx, const struct nk_command *cmd) +{ + nk_byte *buffer; + const struct nk_command *next; + NK_ASSERT(ctx); + if (!ctx || !cmd || !ctx->count) return 0; + if (cmd->next >= ctx->memory.allocated) return 0; + buffer = (nk_byte*)ctx->memory.memory.ptr; + next = nk_ptr_add_const(struct nk_command, buffer, cmd->next); + return next; +} + + + + + + +/* =============================================================== + * + * POOL + * + * ===============================================================*/ +NK_LIB void +nk_pool_init(struct nk_pool *pool, struct nk_allocator *alloc, + unsigned int capacity) +{ + NK_ASSERT(capacity >= 1); + nk_zero(pool, sizeof(*pool)); + pool->alloc = *alloc; + pool->capacity = capacity; + pool->type = NK_BUFFER_DYNAMIC; + pool->pages = 0; +} +NK_LIB void +nk_pool_free(struct nk_pool *pool) +{ + struct nk_page *iter; + if (!pool) return; + iter = pool->pages; + if (pool->type == NK_BUFFER_FIXED) return; + while (iter) { + struct nk_page *next = iter->next; + pool->alloc.free(pool->alloc.userdata, iter); + iter = next; + } +} +NK_LIB void +nk_pool_init_fixed(struct nk_pool *pool, void *memory, nk_size size) +{ + nk_zero(pool, sizeof(*pool)); + NK_ASSERT(size >= sizeof(struct nk_page)); + if (size < sizeof(struct nk_page)) return; + /* first nk_page_element is embedded in nk_page, additional elements follow in adjacent space */ + pool->capacity = (unsigned)(1 + (size - sizeof(struct nk_page)) / sizeof(struct nk_page_element)); + pool->pages = (struct nk_page*)memory; + pool->type = NK_BUFFER_FIXED; + pool->size = size; +} +NK_LIB struct nk_page_element* +nk_pool_alloc(struct nk_pool *pool) +{ + if (!pool->pages || pool->pages->size >= pool->capacity) { + /* allocate new page */ + struct nk_page *page; + if (pool->type == NK_BUFFER_FIXED) { + NK_ASSERT(pool->pages); + if (!pool->pages) return 0; + NK_ASSERT(pool->pages->size < pool->capacity); + return 0; + } else { + nk_size size = sizeof(struct nk_page); + size += (pool->capacity - 1) * sizeof(struct nk_page_element); + page = (struct nk_page*)pool->alloc.alloc(pool->alloc.userdata,0, size); + page->next = pool->pages; + pool->pages = page; + page->size = 0; + } + } return &pool->pages->win[pool->pages->size++]; +} + + + + + +/* =============================================================== + * + * PAGE ELEMENT + * + * ===============================================================*/ +NK_LIB struct nk_page_element* +nk_create_page_element(struct nk_context *ctx) +{ + struct nk_page_element *elem; + if (ctx->freelist) { + /* unlink page element from free list */ + elem = ctx->freelist; + ctx->freelist = elem->next; + } else if (ctx->use_pool) { + /* allocate page element from memory pool */ + elem = nk_pool_alloc(&ctx->pool); + NK_ASSERT(elem); + if (!elem) return 0; + } else { + /* allocate new page element from back of fixed size memory buffer */ + NK_STORAGE const nk_size size = sizeof(struct nk_page_element); + NK_STORAGE const nk_size align = NK_ALIGNOF(struct nk_page_element); + elem = (struct nk_page_element*)nk_buffer_alloc(&ctx->memory, NK_BUFFER_BACK, size, align); + NK_ASSERT(elem); + if (!elem) return 0; + } + nk_zero_struct(*elem); + elem->next = 0; + elem->prev = 0; + return elem; +} +NK_LIB void +nk_link_page_element_into_freelist(struct nk_context *ctx, + struct nk_page_element *elem) +{ + /* link table into freelist */ + if (!ctx->freelist) { + ctx->freelist = elem; + } else { + elem->next = ctx->freelist; + ctx->freelist = elem; + } +} +NK_LIB void +nk_free_page_element(struct nk_context *ctx, struct nk_page_element *elem) +{ + /* we have a pool so just add to free list */ + if (ctx->use_pool) { + nk_link_page_element_into_freelist(ctx, elem); + return; + } + /* if possible remove last element from back of fixed memory buffer */ + {void *elem_end = (void*)(elem + 1); + void *buffer_end = (nk_byte*)ctx->memory.memory.ptr + ctx->memory.size; + if (elem_end == buffer_end) + ctx->memory.size -= sizeof(struct nk_page_element); + else nk_link_page_element_into_freelist(ctx, elem);} +} + + + + + +/* =============================================================== + * + * TABLE + * + * ===============================================================*/ +NK_LIB struct nk_table* +nk_create_table(struct nk_context *ctx) +{ + struct nk_page_element *elem; + elem = nk_create_page_element(ctx); + if (!elem) return 0; + nk_zero_struct(*elem); + return &elem->data.tbl; +} +NK_LIB void +nk_free_table(struct nk_context *ctx, struct nk_table *tbl) +{ + union nk_page_data *pd = NK_CONTAINER_OF(tbl, union nk_page_data, tbl); + struct nk_page_element *pe = NK_CONTAINER_OF(pd, struct nk_page_element, data); + nk_free_page_element(ctx, pe); +} +NK_LIB void +nk_push_table(struct nk_window *win, struct nk_table *tbl) +{ + if (!win->tables) { + win->tables = tbl; + tbl->next = 0; + tbl->prev = 0; + tbl->size = 0; + win->table_count = 1; + return; + } + win->tables->prev = tbl; + tbl->next = win->tables; + tbl->prev = 0; + tbl->size = 0; + win->tables = tbl; + win->table_count++; +} +NK_LIB void +nk_remove_table(struct nk_window *win, struct nk_table *tbl) +{ + if (win->tables == tbl) + win->tables = tbl->next; + if (tbl->next) + tbl->next->prev = tbl->prev; + if (tbl->prev) + tbl->prev->next = tbl->next; + tbl->next = 0; + tbl->prev = 0; +} +NK_LIB nk_uint* +nk_add_value(struct nk_context *ctx, struct nk_window *win, + nk_hash name, nk_uint value) +{ + NK_ASSERT(ctx); + NK_ASSERT(win); + if (!win || !ctx) return 0; + if (!win->tables || win->tables->size >= NK_VALUE_PAGE_CAPACITY) { + struct nk_table *tbl = nk_create_table(ctx); + NK_ASSERT(tbl); + if (!tbl) return 0; + nk_push_table(win, tbl); + } + win->tables->seq = win->seq; + win->tables->keys[win->tables->size] = name; + win->tables->values[win->tables->size] = value; + return &win->tables->values[win->tables->size++]; +} +NK_LIB nk_uint* +nk_find_value(struct nk_window *win, nk_hash name) +{ + struct nk_table *iter = win->tables; + while (iter) { + unsigned int i = 0; + unsigned int size = iter->size; + for (i = 0; i < size; ++i) { + if (iter->keys[i] == name) { + iter->seq = win->seq; + return &iter->values[i]; + } + } size = NK_VALUE_PAGE_CAPACITY; + iter = iter->next; + } + return 0; +} + + + + + +/* =============================================================== + * + * PANEL + * + * ===============================================================*/ +NK_LIB void* +nk_create_panel(struct nk_context *ctx) +{ + struct nk_page_element *elem; + elem = nk_create_page_element(ctx); + if (!elem) return 0; + nk_zero_struct(*elem); + return &elem->data.pan; +} +NK_LIB void +nk_free_panel(struct nk_context *ctx, struct nk_panel *pan) +{ + union nk_page_data *pd = NK_CONTAINER_OF(pan, union nk_page_data, pan); + struct nk_page_element *pe = NK_CONTAINER_OF(pd, struct nk_page_element, data); + nk_free_page_element(ctx, pe); +} +NK_LIB nk_bool +nk_panel_has_header(nk_flags flags, const char *title) +{ + nk_bool active = 0; + active = (flags & (NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE)); + active = active || (flags & NK_WINDOW_TITLE); + active = active && !(flags & NK_WINDOW_HIDDEN) && title; + return active; +} +NK_LIB struct nk_vec2 +nk_panel_get_padding(const struct nk_style *style, enum nk_panel_type type) +{ + switch (type) { + default: + case NK_PANEL_WINDOW: return style->window.padding; + case NK_PANEL_GROUP: return style->window.group_padding; + case NK_PANEL_POPUP: return style->window.popup_padding; + case NK_PANEL_CONTEXTUAL: return style->window.contextual_padding; + case NK_PANEL_COMBO: return style->window.combo_padding; + case NK_PANEL_MENU: return style->window.menu_padding; + case NK_PANEL_TOOLTIP: return style->window.menu_padding;} +} +NK_LIB float +nk_panel_get_border(const struct nk_style *style, nk_flags flags, + enum nk_panel_type type) +{ + if (flags & NK_WINDOW_BORDER) { + switch (type) { + default: + case NK_PANEL_WINDOW: return style->window.border; + case NK_PANEL_GROUP: return style->window.group_border; + case NK_PANEL_POPUP: return style->window.popup_border; + case NK_PANEL_CONTEXTUAL: return style->window.contextual_border; + case NK_PANEL_COMBO: return style->window.combo_border; + case NK_PANEL_MENU: return style->window.menu_border; + case NK_PANEL_TOOLTIP: return style->window.menu_border; + }} else return 0; +} +NK_LIB struct nk_color +nk_panel_get_border_color(const struct nk_style *style, enum nk_panel_type type) +{ + switch (type) { + default: + case NK_PANEL_WINDOW: return style->window.border_color; + case NK_PANEL_GROUP: return style->window.group_border_color; + case NK_PANEL_POPUP: return style->window.popup_border_color; + case NK_PANEL_CONTEXTUAL: return style->window.contextual_border_color; + case NK_PANEL_COMBO: return style->window.combo_border_color; + case NK_PANEL_MENU: return style->window.menu_border_color; + case NK_PANEL_TOOLTIP: return style->window.menu_border_color;} +} +NK_LIB nk_bool +nk_panel_is_sub(enum nk_panel_type type) +{ + return (type & NK_PANEL_SET_SUB)?1:0; +} +NK_LIB nk_bool +nk_panel_is_nonblock(enum nk_panel_type type) +{ + return (type & NK_PANEL_SET_NONBLOCK)?1:0; +} +NK_LIB nk_bool +nk_panel_begin(struct nk_context *ctx, const char *title, enum nk_panel_type panel_type) +{ + struct nk_input *in; + struct nk_window *win; + struct nk_panel *layout; + struct nk_command_buffer *out; + const struct nk_style *style; + const struct nk_user_font *font; + + struct nk_vec2 scrollbar_size; + struct nk_vec2 panel_padding; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) return 0; + nk_zero(ctx->current->layout, sizeof(*ctx->current->layout)); + if ((ctx->current->flags & NK_WINDOW_HIDDEN) || (ctx->current->flags & NK_WINDOW_CLOSED)) { + nk_zero(ctx->current->layout, sizeof(struct nk_panel)); + ctx->current->layout->type = panel_type; + return 0; + } + /* pull state into local stack */ + style = &ctx->style; + font = style->font; + win = ctx->current; + layout = win->layout; + out = &win->buffer; + in = (win->flags & NK_WINDOW_NO_INPUT) ? 0: &ctx->input; +#ifdef NK_INCLUDE_COMMAND_USERDATA + win->buffer.userdata = ctx->userdata; +#endif + /* pull style configuration into local stack */ + scrollbar_size = style->window.scrollbar_size; + panel_padding = nk_panel_get_padding(style, panel_type); + + /* window movement */ + if ((win->flags & NK_WINDOW_MOVABLE) && !(win->flags & NK_WINDOW_ROM)) { + nk_bool left_mouse_down; + unsigned int left_mouse_clicked; + int left_mouse_click_in_cursor; + + /* calculate draggable window space */ + struct nk_rect header; + header.x = win->bounds.x; + header.y = win->bounds.y; + header.w = win->bounds.w; + if (nk_panel_has_header(win->flags, title)) { + header.h = font->height + 2.0f * style->window.header.padding.y; + header.h += 2.0f * style->window.header.label_padding.y; + } else header.h = panel_padding.y; + + /* window movement by dragging */ + left_mouse_down = in->mouse.buttons[NK_BUTTON_LEFT].down; + left_mouse_clicked = in->mouse.buttons[NK_BUTTON_LEFT].clicked; + left_mouse_click_in_cursor = nk_input_has_mouse_click_down_in_rect(in, + NK_BUTTON_LEFT, header, nk_true); + if (left_mouse_down && left_mouse_click_in_cursor && !left_mouse_clicked) { + win->bounds.x = win->bounds.x + in->mouse.delta.x; + win->bounds.y = win->bounds.y + in->mouse.delta.y; + in->mouse.buttons[NK_BUTTON_LEFT].clicked_pos.x += in->mouse.delta.x; + in->mouse.buttons[NK_BUTTON_LEFT].clicked_pos.y += in->mouse.delta.y; + ctx->style.cursor_active = ctx->style.cursors[NK_CURSOR_MOVE]; + } + } + + /* setup panel */ + layout->type = panel_type; + layout->flags = win->flags; + layout->bounds = win->bounds; + layout->bounds.x += panel_padding.x; + layout->bounds.w -= 2*panel_padding.x; + if (win->flags & NK_WINDOW_BORDER) { + layout->border = nk_panel_get_border(style, win->flags, panel_type); + layout->bounds = nk_shrink_rect(layout->bounds, layout->border); + } else layout->border = 0; + layout->at_y = layout->bounds.y; + layout->at_x = layout->bounds.x; + layout->max_x = 0; + layout->header_height = 0; + layout->footer_height = 0; + nk_layout_reset_min_row_height(ctx); + layout->row.index = 0; + layout->row.columns = 0; + layout->row.ratio = 0; + layout->row.item_width = 0; + layout->row.tree_depth = 0; + layout->row.height = panel_padding.y; + layout->has_scrolling = nk_true; + if (!(win->flags & NK_WINDOW_NO_SCROLLBAR)) + layout->bounds.w -= scrollbar_size.x; + if (!nk_panel_is_nonblock(panel_type)) { + layout->footer_height = 0; + if (!(win->flags & NK_WINDOW_NO_SCROLLBAR) || win->flags & NK_WINDOW_SCALABLE) + layout->footer_height = scrollbar_size.y; + layout->bounds.h -= layout->footer_height; + } + + /* panel header */ + if (nk_panel_has_header(win->flags, title)) + { + struct nk_text text; + struct nk_rect header; + const struct nk_style_item *background = 0; + + /* calculate header bounds */ + header.x = win->bounds.x; + header.y = win->bounds.y; + header.w = win->bounds.w; + header.h = font->height + 2.0f * style->window.header.padding.y; + header.h += (2.0f * style->window.header.label_padding.y); + + /* shrink panel by header */ + layout->header_height = header.h; + layout->bounds.y += header.h; + layout->bounds.h -= header.h; + layout->at_y += header.h; + + /* select correct header background and text color */ + if (ctx->active == win) { + background = &style->window.header.active; + text.text = style->window.header.label_active; + } else if (nk_input_is_mouse_hovering_rect(&ctx->input, header)) { + background = &style->window.header.hover; + text.text = style->window.header.label_hover; + } else { + background = &style->window.header.normal; + text.text = style->window.header.label_normal; + } + + /* draw header background */ + header.h += 1.0f; + + switch(background->type) { + case NK_STYLE_ITEM_IMAGE: + text.background = nk_rgba(0,0,0,0); + nk_draw_image(&win->buffer, header, &background->data.image, nk_white); + break; + case NK_STYLE_ITEM_NINE_SLICE: + text.background = nk_rgba(0, 0, 0, 0); + nk_draw_nine_slice(&win->buffer, header, &background->data.slice, nk_white); + break; + case NK_STYLE_ITEM_COLOR: + text.background = background->data.color; + nk_fill_rect(out, header, 0, background->data.color); + break; + } + + /* window close button */ + {struct nk_rect button; + button.y = header.y + style->window.header.padding.y; + button.h = header.h - 2 * style->window.header.padding.y; + button.w = button.h; + if (win->flags & NK_WINDOW_CLOSABLE) { + nk_flags ws = 0; + if (style->window.header.align == NK_HEADER_RIGHT) { + button.x = (header.w + header.x) - (button.w + style->window.header.padding.x); + header.w -= button.w + style->window.header.spacing.x + style->window.header.padding.x; + } else { + button.x = header.x + style->window.header.padding.x; + header.x += button.w + style->window.header.spacing.x + style->window.header.padding.x; + } + + if (nk_do_button_symbol(&ws, &win->buffer, button, + style->window.header.close_symbol, NK_BUTTON_DEFAULT, + &style->window.header.close_button, in, style->font) && !(win->flags & NK_WINDOW_ROM)) + { + layout->flags |= NK_WINDOW_HIDDEN; + layout->flags &= (nk_flags)~NK_WINDOW_MINIMIZED; + } + } + + /* window minimize button */ + if (win->flags & NK_WINDOW_MINIMIZABLE) { + nk_flags ws = 0; + if (style->window.header.align == NK_HEADER_RIGHT) { + button.x = (header.w + header.x) - button.w; + if (!(win->flags & NK_WINDOW_CLOSABLE)) { + button.x -= style->window.header.padding.x; + header.w -= style->window.header.padding.x; + } + header.w -= button.w + style->window.header.spacing.x; + } else { + button.x = header.x; + header.x += button.w + style->window.header.spacing.x + style->window.header.padding.x; + } + if (nk_do_button_symbol(&ws, &win->buffer, button, (layout->flags & NK_WINDOW_MINIMIZED)? + style->window.header.maximize_symbol: style->window.header.minimize_symbol, + NK_BUTTON_DEFAULT, &style->window.header.minimize_button, in, style->font) && !(win->flags & NK_WINDOW_ROM)) + layout->flags = (layout->flags & NK_WINDOW_MINIMIZED) ? + layout->flags & (nk_flags)~NK_WINDOW_MINIMIZED: + layout->flags | NK_WINDOW_MINIMIZED; + }} + + {/* window header title */ + int text_len = nk_strlen(title); + struct nk_rect label = {0,0,0,0}; + float t = font->width(font->userdata, font->height, title, text_len); + text.padding = nk_vec2(0,0); + + label.x = header.x + style->window.header.padding.x; + label.x += style->window.header.label_padding.x; + label.y = header.y + style->window.header.label_padding.y; + label.h = font->height + 2 * style->window.header.label_padding.y; + label.w = t + 2 * style->window.header.spacing.x; + label.w = NK_CLAMP(0, label.w, header.x + header.w - label.x); + nk_widget_text(out, label, (const char*)title, text_len, &text, NK_TEXT_LEFT, font);} + } + + /* draw window background */ + if (!(layout->flags & NK_WINDOW_MINIMIZED) && !(layout->flags & NK_WINDOW_DYNAMIC)) { + struct nk_rect body; + body.x = win->bounds.x; + body.w = win->bounds.w; + body.y = (win->bounds.y + layout->header_height); + body.h = (win->bounds.h - layout->header_height); + + switch(style->window.fixed_background.type) { + case NK_STYLE_ITEM_IMAGE: + nk_draw_image(out, body, &style->window.fixed_background.data.image, nk_white); + break; + case NK_STYLE_ITEM_NINE_SLICE: + nk_draw_nine_slice(out, body, &style->window.fixed_background.data.slice, nk_white); + break; + case NK_STYLE_ITEM_COLOR: + nk_fill_rect(out, body, 0, style->window.fixed_background.data.color); + break; + } + } + + /* set clipping rectangle */ + {struct nk_rect clip; + layout->clip = layout->bounds; + nk_unify(&clip, &win->buffer.clip, layout->clip.x, layout->clip.y, + layout->clip.x + layout->clip.w, layout->clip.y + layout->clip.h); + nk_push_scissor(out, clip); + layout->clip = clip;} + return !(layout->flags & NK_WINDOW_HIDDEN) && !(layout->flags & NK_WINDOW_MINIMIZED); +} +NK_LIB void +nk_panel_end(struct nk_context *ctx) +{ + struct nk_input *in; + struct nk_window *window; + struct nk_panel *layout; + const struct nk_style *style; + struct nk_command_buffer *out; + + struct nk_vec2 scrollbar_size; + struct nk_vec2 panel_padding; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return; + + window = ctx->current; + layout = window->layout; + style = &ctx->style; + out = &window->buffer; + in = (layout->flags & NK_WINDOW_ROM || layout->flags & NK_WINDOW_NO_INPUT) ? 0 :&ctx->input; + if (!nk_panel_is_sub(layout->type)) + nk_push_scissor(out, nk_null_rect); + + /* cache configuration data */ + scrollbar_size = style->window.scrollbar_size; + panel_padding = nk_panel_get_padding(style, layout->type); + + /* update the current cursor Y-position to point over the last added widget */ + layout->at_y += layout->row.height; + + /* dynamic panels */ + if (layout->flags & NK_WINDOW_DYNAMIC && !(layout->flags & NK_WINDOW_MINIMIZED)) + { + /* update panel height to fit dynamic growth */ + struct nk_rect empty_space; + if (layout->at_y < (layout->bounds.y + layout->bounds.h)) + layout->bounds.h = layout->at_y - layout->bounds.y; + + /* fill top empty space */ + empty_space.x = window->bounds.x; + empty_space.y = layout->bounds.y; + empty_space.h = panel_padding.y; + empty_space.w = window->bounds.w; + nk_fill_rect(out, empty_space, 0, style->window.background); + + /* fill left empty space */ + empty_space.x = window->bounds.x; + empty_space.y = layout->bounds.y; + empty_space.w = panel_padding.x + layout->border; + empty_space.h = layout->bounds.h; + nk_fill_rect(out, empty_space, 0, style->window.background); + + /* fill right empty space */ + empty_space.x = layout->bounds.x + layout->bounds.w; + empty_space.y = layout->bounds.y; + empty_space.w = panel_padding.x + layout->border; + empty_space.h = layout->bounds.h; + if (*layout->offset_y == 0 && !(layout->flags & NK_WINDOW_NO_SCROLLBAR)) + empty_space.w += scrollbar_size.x; + nk_fill_rect(out, empty_space, 0, style->window.background); + + /* fill bottom empty space */ + if (layout->footer_height > 0) { + empty_space.x = window->bounds.x; + empty_space.y = layout->bounds.y + layout->bounds.h; + empty_space.w = window->bounds.w; + empty_space.h = layout->footer_height; + nk_fill_rect(out, empty_space, 0, style->window.background); + } + } + + /* scrollbars */ + if (!(layout->flags & NK_WINDOW_NO_SCROLLBAR) && + !(layout->flags & NK_WINDOW_MINIMIZED) && + window->scrollbar_hiding_timer < NK_SCROLLBAR_HIDING_TIMEOUT) + { + struct nk_rect scroll; + int scroll_has_scrolling; + float scroll_target; + float scroll_offset; + float scroll_step; + float scroll_inc; + + /* mouse wheel scrolling */ + if (nk_panel_is_sub(layout->type)) + { + /* sub-window mouse wheel scrolling */ + struct nk_window *root_window = window; + struct nk_panel *root_panel = window->layout; + while (root_panel->parent) + root_panel = root_panel->parent; + while (root_window->parent) + root_window = root_window->parent; + + /* only allow scrolling if parent window is active */ + scroll_has_scrolling = 0; + if ((root_window == ctx->active) && layout->has_scrolling) { + /* and panel is being hovered and inside clip rect*/ + if (nk_input_is_mouse_hovering_rect(in, layout->bounds) && + NK_INTERSECT(layout->bounds.x, layout->bounds.y, layout->bounds.w, layout->bounds.h, + root_panel->clip.x, root_panel->clip.y, root_panel->clip.w, root_panel->clip.h)) + { + /* deactivate all parent scrolling */ + root_panel = window->layout; + while (root_panel->parent) { + root_panel->has_scrolling = nk_false; + root_panel = root_panel->parent; + } + root_panel->has_scrolling = nk_false; + scroll_has_scrolling = nk_true; + } + } + } else if (!nk_panel_is_sub(layout->type)) { + /* window mouse wheel scrolling */ + scroll_has_scrolling = (window == ctx->active) && layout->has_scrolling; + if (in && (in->mouse.scroll_delta.y > 0 || in->mouse.scroll_delta.x > 0) && scroll_has_scrolling) + window->scrolled = nk_true; + else window->scrolled = nk_false; + } else scroll_has_scrolling = nk_false; + + { + /* vertical scrollbar */ + nk_flags state = 0; + scroll.x = layout->bounds.x + layout->bounds.w + panel_padding.x; + scroll.y = layout->bounds.y; + scroll.w = scrollbar_size.x; + scroll.h = layout->bounds.h; + + scroll_offset = (float)*layout->offset_y; + scroll_step = scroll.h * 0.10f; + scroll_inc = scroll.h * 0.01f; + scroll_target = (float)(int)(layout->at_y - scroll.y); + scroll_offset = nk_do_scrollbarv(&state, out, scroll, scroll_has_scrolling, + scroll_offset, scroll_target, scroll_step, scroll_inc, + &ctx->style.scrollv, in, style->font); + *layout->offset_y = (nk_uint)scroll_offset; + if (in && scroll_has_scrolling) + in->mouse.scroll_delta.y = 0; + } + { + /* horizontal scrollbar */ + nk_flags state = 0; + scroll.x = layout->bounds.x; + scroll.y = layout->bounds.y + layout->bounds.h; + scroll.w = layout->bounds.w; + scroll.h = scrollbar_size.y; + + scroll_offset = (float)*layout->offset_x; + scroll_target = (float)(int)(layout->max_x - scroll.x); + scroll_step = layout->max_x * 0.05f; + scroll_inc = layout->max_x * 0.005f; + scroll_offset = nk_do_scrollbarh(&state, out, scroll, scroll_has_scrolling, + scroll_offset, scroll_target, scroll_step, scroll_inc, + &ctx->style.scrollh, in, style->font); + *layout->offset_x = (nk_uint)scroll_offset; + } + } + + /* hide scroll if no user input */ + if (window->flags & NK_WINDOW_SCROLL_AUTO_HIDE) { + int has_input = ctx->input.mouse.delta.x != 0 || ctx->input.mouse.delta.y != 0 || ctx->input.mouse.scroll_delta.y != 0; + int is_window_hovered = nk_window_is_hovered(ctx); + int any_item_active = (ctx->last_widget_state & NK_WIDGET_STATE_MODIFIED); + if ((!has_input && is_window_hovered) || (!is_window_hovered && !any_item_active)) + window->scrollbar_hiding_timer += ctx->delta_time_seconds; + else window->scrollbar_hiding_timer = 0; + } else window->scrollbar_hiding_timer = 0; + + /* window border */ + if (layout->flags & NK_WINDOW_BORDER) + { + struct nk_color border_color = nk_panel_get_border_color(style, layout->type); + const float padding_y = (layout->flags & NK_WINDOW_MINIMIZED) + ? (style->window.border + window->bounds.y + layout->header_height) + : ((layout->flags & NK_WINDOW_DYNAMIC) + ? (layout->bounds.y + layout->bounds.h + layout->footer_height) + : (window->bounds.y + window->bounds.h)); + struct nk_rect b = window->bounds; + b.h = padding_y - window->bounds.y; + nk_stroke_rect(out, b, 0, layout->border, border_color); + } + + /* scaler */ + if ((layout->flags & NK_WINDOW_SCALABLE) && in && !(layout->flags & NK_WINDOW_MINIMIZED)) + { + /* calculate scaler bounds */ + struct nk_rect scaler; + scaler.w = scrollbar_size.x; + scaler.h = scrollbar_size.y; + scaler.y = layout->bounds.y + layout->bounds.h; + if (layout->flags & NK_WINDOW_SCALE_LEFT) + scaler.x = layout->bounds.x - panel_padding.x * 0.5f; + else scaler.x = layout->bounds.x + layout->bounds.w + panel_padding.x; + if (layout->flags & NK_WINDOW_NO_SCROLLBAR) + scaler.x -= scaler.w; + + /* draw scaler */ + {const struct nk_style_item *item = &style->window.scaler; + if (item->type == NK_STYLE_ITEM_IMAGE) + nk_draw_image(out, scaler, &item->data.image, nk_white); + else { + if (layout->flags & NK_WINDOW_SCALE_LEFT) { + nk_fill_triangle(out, scaler.x, scaler.y, scaler.x, + scaler.y + scaler.h, scaler.x + scaler.w, + scaler.y + scaler.h, item->data.color); + } else { + nk_fill_triangle(out, scaler.x + scaler.w, scaler.y, scaler.x + scaler.w, + scaler.y + scaler.h, scaler.x, scaler.y + scaler.h, item->data.color); + } + }} + + /* do window scaling */ + if (!(window->flags & NK_WINDOW_ROM)) { + struct nk_vec2 window_size = style->window.min_size; + int left_mouse_down = in->mouse.buttons[NK_BUTTON_LEFT].down; + int left_mouse_click_in_scaler = nk_input_has_mouse_click_down_in_rect(in, + NK_BUTTON_LEFT, scaler, nk_true); + + if (left_mouse_down && left_mouse_click_in_scaler) { + float delta_x = in->mouse.delta.x; + if (layout->flags & NK_WINDOW_SCALE_LEFT) { + delta_x = -delta_x; + window->bounds.x += in->mouse.delta.x; + } + /* dragging in x-direction */ + if (window->bounds.w + delta_x >= window_size.x) { + if ((delta_x < 0) || (delta_x > 0 && in->mouse.pos.x >= scaler.x)) { + window->bounds.w = window->bounds.w + delta_x; + scaler.x += in->mouse.delta.x; + } + } + /* dragging in y-direction (only possible if static window) */ + if (!(layout->flags & NK_WINDOW_DYNAMIC)) { + if (window_size.y < window->bounds.h + in->mouse.delta.y) { + if ((in->mouse.delta.y < 0) || (in->mouse.delta.y > 0 && in->mouse.pos.y >= scaler.y)) { + window->bounds.h = window->bounds.h + in->mouse.delta.y; + scaler.y += in->mouse.delta.y; + } + } + } + ctx->style.cursor_active = ctx->style.cursors[NK_CURSOR_RESIZE_TOP_RIGHT_DOWN_LEFT]; + in->mouse.buttons[NK_BUTTON_LEFT].clicked_pos.x = scaler.x + scaler.w/2.0f; + in->mouse.buttons[NK_BUTTON_LEFT].clicked_pos.y = scaler.y + scaler.h/2.0f; + } + } + } + if (!nk_panel_is_sub(layout->type)) { + /* window is hidden so clear command buffer */ + if (layout->flags & NK_WINDOW_HIDDEN) + nk_command_buffer_reset(&window->buffer); + /* window is visible and not tab */ + else nk_finish(ctx, window); + } + + /* NK_WINDOW_REMOVE_ROM flag was set so remove NK_WINDOW_ROM */ + if (layout->flags & NK_WINDOW_REMOVE_ROM) { + layout->flags &= ~(nk_flags)NK_WINDOW_ROM; + layout->flags &= ~(nk_flags)NK_WINDOW_REMOVE_ROM; + } + window->flags = layout->flags; + + /* property garbage collector */ + if (window->property.active && window->property.old != window->property.seq && + window->property.active == window->property.prev) { + nk_zero(&window->property, sizeof(window->property)); + } else { + window->property.old = window->property.seq; + window->property.prev = window->property.active; + window->property.seq = 0; + } + /* edit garbage collector */ + if (window->edit.active && window->edit.old != window->edit.seq && + window->edit.active == window->edit.prev) { + nk_zero(&window->edit, sizeof(window->edit)); + } else { + window->edit.old = window->edit.seq; + window->edit.prev = window->edit.active; + window->edit.seq = 0; + } + /* contextual garbage collector */ + if (window->popup.active_con && window->popup.con_old != window->popup.con_count) { + window->popup.con_count = 0; + window->popup.con_old = 0; + window->popup.active_con = 0; + } else { + window->popup.con_old = window->popup.con_count; + window->popup.con_count = 0; + } + window->popup.combo_count = 0; + /* helper to make sure you have a 'nk_tree_push' for every 'nk_tree_pop' */ + NK_ASSERT(!layout->row.tree_depth); +} + + + + + +/* =============================================================== + * + * WINDOW + * + * ===============================================================*/ +NK_LIB void* +nk_create_window(struct nk_context *ctx) +{ + struct nk_page_element *elem; + elem = nk_create_page_element(ctx); + if (!elem) return 0; + elem->data.win.seq = ctx->seq; + return &elem->data.win; +} +NK_LIB void +nk_free_window(struct nk_context *ctx, struct nk_window *win) +{ + /* unlink windows from list */ + struct nk_table *it = win->tables; + if (win->popup.win) { + nk_free_window(ctx, win->popup.win); + win->popup.win = 0; + } + win->next = 0; + win->prev = 0; + + while (it) { + /*free window state tables */ + struct nk_table *n = it->next; + nk_remove_table(win, it); + nk_free_table(ctx, it); + if (it == win->tables) + win->tables = n; + it = n; + } + + /* link windows into freelist */ + {union nk_page_data *pd = NK_CONTAINER_OF(win, union nk_page_data, win); + struct nk_page_element *pe = NK_CONTAINER_OF(pd, struct nk_page_element, data); + nk_free_page_element(ctx, pe);} +} +NK_LIB struct nk_window* +nk_find_window(struct nk_context *ctx, nk_hash hash, const char *name) +{ + struct nk_window *iter; + iter = ctx->begin; + while (iter) { + NK_ASSERT(iter != iter->next); + if (iter->name == hash) { + int max_len = nk_strlen(iter->name_string); + if (!nk_stricmpn(iter->name_string, name, max_len)) + return iter; + } + iter = iter->next; + } + return 0; +} +NK_LIB void +nk_insert_window(struct nk_context *ctx, struct nk_window *win, + enum nk_window_insert_location loc) +{ + const struct nk_window *iter; + NK_ASSERT(ctx); + NK_ASSERT(win); + if (!win || !ctx) return; + + iter = ctx->begin; + while (iter) { + NK_ASSERT(iter != iter->next); + NK_ASSERT(iter != win); + if (iter == win) return; + iter = iter->next; + } + + if (!ctx->begin) { + win->next = 0; + win->prev = 0; + ctx->begin = win; + ctx->end = win; + ctx->count = 1; + return; + } + if (loc == NK_INSERT_BACK) { + struct nk_window *end; + end = ctx->end; + end->flags |= NK_WINDOW_ROM; + end->next = win; + win->prev = ctx->end; + win->next = 0; + ctx->end = win; + ctx->active = ctx->end; + ctx->end->flags &= ~(nk_flags)NK_WINDOW_ROM; + } else { + /*ctx->end->flags |= NK_WINDOW_ROM;*/ + ctx->begin->prev = win; + win->next = ctx->begin; + win->prev = 0; + ctx->begin = win; + ctx->begin->flags &= ~(nk_flags)NK_WINDOW_ROM; + } + ctx->count++; +} +NK_LIB void +nk_remove_window(struct nk_context *ctx, struct nk_window *win) +{ + if (win == ctx->begin || win == ctx->end) { + if (win == ctx->begin) { + ctx->begin = win->next; + if (win->next) + win->next->prev = 0; + } + if (win == ctx->end) { + ctx->end = win->prev; + if (win->prev) + win->prev->next = 0; + } + } else { + if (win->next) + win->next->prev = win->prev; + if (win->prev) + win->prev->next = win->next; + } + if (win == ctx->active || !ctx->active) { + ctx->active = ctx->end; + if (ctx->end) + ctx->end->flags &= ~(nk_flags)NK_WINDOW_ROM; + } + win->next = 0; + win->prev = 0; + ctx->count--; +} +NK_API nk_bool +nk_begin(struct nk_context *ctx, const char *title, + struct nk_rect bounds, nk_flags flags) +{ + return nk_begin_titled(ctx, title, title, bounds, flags); +} +NK_API nk_bool +nk_begin_titled(struct nk_context *ctx, const char *name, const char *title, + struct nk_rect bounds, nk_flags flags) +{ + struct nk_window *win; + struct nk_style *style; + nk_hash name_hash; + int name_len; + int ret = 0; + + NK_ASSERT(ctx); + NK_ASSERT(name); + NK_ASSERT(title); + NK_ASSERT(ctx->style.font && ctx->style.font->width && "if this triggers you forgot to add a font"); + NK_ASSERT(!ctx->current && "if this triggers you missed a `nk_end` call"); + if (!ctx || ctx->current || !title || !name) + return 0; + + /* find or create window */ + style = &ctx->style; + name_len = (int)nk_strlen(name); + name_hash = nk_murmur_hash(name, (int)name_len, NK_WINDOW_TITLE); + win = nk_find_window(ctx, name_hash, name); + if (!win) { + /* create new window */ + nk_size name_length = (nk_size)name_len; + win = (struct nk_window*)nk_create_window(ctx); + NK_ASSERT(win); + if (!win) return 0; + + if (flags & NK_WINDOW_BACKGROUND) + nk_insert_window(ctx, win, NK_INSERT_FRONT); + else nk_insert_window(ctx, win, NK_INSERT_BACK); + nk_command_buffer_init(&win->buffer, &ctx->memory, NK_CLIPPING_ON); + + win->flags = flags; + win->bounds = bounds; + win->name = name_hash; + name_length = NK_MIN(name_length, NK_WINDOW_MAX_NAME-1); + NK_MEMCPY(win->name_string, name, name_length); + win->name_string[name_length] = 0; + win->popup.win = 0; + if (!ctx->active) + ctx->active = win; + } else { + /* update window */ + win->flags &= ~(nk_flags)(NK_WINDOW_PRIVATE-1); + win->flags |= flags; + if (!(win->flags & (NK_WINDOW_MOVABLE | NK_WINDOW_SCALABLE))) + win->bounds = bounds; + /* If this assert triggers you either: + * + * I.) Have more than one window with the same name or + * II.) You forgot to actually draw the window. + * More specific you did not call `nk_clear` (nk_clear will be + * automatically called for you if you are using one of the + * provided demo backends). */ + NK_ASSERT(win->seq != ctx->seq); + win->seq = ctx->seq; + if (!ctx->active && !(win->flags & NK_WINDOW_HIDDEN)) { + ctx->active = win; + ctx->end = win; + } + } + if (win->flags & NK_WINDOW_HIDDEN) { + ctx->current = win; + win->layout = 0; + return 0; + } else nk_start(ctx, win); + + /* window overlapping */ + if (!(win->flags & NK_WINDOW_HIDDEN) && !(win->flags & NK_WINDOW_NO_INPUT)) + { + int inpanel, ishovered; + struct nk_window *iter = win; + float h = ctx->style.font->height + 2.0f * style->window.header.padding.y + + (2.0f * style->window.header.label_padding.y); + struct nk_rect win_bounds = (!(win->flags & NK_WINDOW_MINIMIZED))? + win->bounds: nk_rect(win->bounds.x, win->bounds.y, win->bounds.w, h); + + /* activate window if hovered and no other window is overlapping this window */ + inpanel = nk_input_has_mouse_click_down_in_rect(&ctx->input, NK_BUTTON_LEFT, win_bounds, nk_true); + inpanel = inpanel && ctx->input.mouse.buttons[NK_BUTTON_LEFT].clicked; + ishovered = nk_input_is_mouse_hovering_rect(&ctx->input, win_bounds); + if ((win != ctx->active) && ishovered && !ctx->input.mouse.buttons[NK_BUTTON_LEFT].down) { + iter = win->next; + while (iter) { + struct nk_rect iter_bounds = (!(iter->flags & NK_WINDOW_MINIMIZED))? + iter->bounds: nk_rect(iter->bounds.x, iter->bounds.y, iter->bounds.w, h); + if (NK_INTERSECT(win_bounds.x, win_bounds.y, win_bounds.w, win_bounds.h, + iter_bounds.x, iter_bounds.y, iter_bounds.w, iter_bounds.h) && + (!(iter->flags & NK_WINDOW_HIDDEN))) + break; + + if (iter->popup.win && iter->popup.active && !(iter->flags & NK_WINDOW_HIDDEN) && + NK_INTERSECT(win->bounds.x, win_bounds.y, win_bounds.w, win_bounds.h, + iter->popup.win->bounds.x, iter->popup.win->bounds.y, + iter->popup.win->bounds.w, iter->popup.win->bounds.h)) + break; + iter = iter->next; + } + } + + /* activate window if clicked */ + if (iter && inpanel && (win != ctx->end)) { + iter = win->next; + while (iter) { + /* try to find a panel with higher priority in the same position */ + struct nk_rect iter_bounds = (!(iter->flags & NK_WINDOW_MINIMIZED))? + iter->bounds: nk_rect(iter->bounds.x, iter->bounds.y, iter->bounds.w, h); + if (NK_INBOX(ctx->input.mouse.pos.x, ctx->input.mouse.pos.y, + iter_bounds.x, iter_bounds.y, iter_bounds.w, iter_bounds.h) && + !(iter->flags & NK_WINDOW_HIDDEN)) + break; + if (iter->popup.win && iter->popup.active && !(iter->flags & NK_WINDOW_HIDDEN) && + NK_INTERSECT(win_bounds.x, win_bounds.y, win_bounds.w, win_bounds.h, + iter->popup.win->bounds.x, iter->popup.win->bounds.y, + iter->popup.win->bounds.w, iter->popup.win->bounds.h)) + break; + iter = iter->next; + } + } + if (iter && !(win->flags & NK_WINDOW_ROM) && (win->flags & NK_WINDOW_BACKGROUND)) { + win->flags |= (nk_flags)NK_WINDOW_ROM; + iter->flags &= ~(nk_flags)NK_WINDOW_ROM; + ctx->active = iter; + if (!(iter->flags & NK_WINDOW_BACKGROUND)) { + /* current window is active in that position so transfer to top + * at the highest priority in stack */ + nk_remove_window(ctx, iter); + nk_insert_window(ctx, iter, NK_INSERT_BACK); + } + } else { + if (!iter && ctx->end != win) { + if (!(win->flags & NK_WINDOW_BACKGROUND)) { + /* current window is active in that position so transfer to top + * at the highest priority in stack */ + nk_remove_window(ctx, win); + nk_insert_window(ctx, win, NK_INSERT_BACK); + } + win->flags &= ~(nk_flags)NK_WINDOW_ROM; + ctx->active = win; + } + if (ctx->end != win && !(win->flags & NK_WINDOW_BACKGROUND)) + win->flags |= NK_WINDOW_ROM; + } + } + win->layout = (struct nk_panel*)nk_create_panel(ctx); + ctx->current = win; + ret = nk_panel_begin(ctx, title, NK_PANEL_WINDOW); + win->layout->offset_x = &win->scrollbar.x; + win->layout->offset_y = &win->scrollbar.y; + return ret; +} +NK_API void +nk_end(struct nk_context *ctx) +{ + struct nk_panel *layout; + NK_ASSERT(ctx); + NK_ASSERT(ctx->current && "if this triggers you forgot to call `nk_begin`"); + if (!ctx || !ctx->current) + return; + + layout = ctx->current->layout; + if (!layout || (layout->type == NK_PANEL_WINDOW && (ctx->current->flags & NK_WINDOW_HIDDEN))) { + ctx->current = 0; + return; + } + nk_panel_end(ctx); + nk_free_panel(ctx, ctx->current->layout); + ctx->current = 0; +} +NK_API struct nk_rect +nk_window_get_bounds(const struct nk_context *ctx) +{ + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + if (!ctx || !ctx->current) return nk_rect(0,0,0,0); + return ctx->current->bounds; +} +NK_API struct nk_vec2 +nk_window_get_position(const struct nk_context *ctx) +{ + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + if (!ctx || !ctx->current) return nk_vec2(0,0); + return nk_vec2(ctx->current->bounds.x, ctx->current->bounds.y); +} +NK_API struct nk_vec2 +nk_window_get_size(const struct nk_context *ctx) +{ + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + if (!ctx || !ctx->current) return nk_vec2(0,0); + return nk_vec2(ctx->current->bounds.w, ctx->current->bounds.h); +} +NK_API float +nk_window_get_width(const struct nk_context *ctx) +{ + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + if (!ctx || !ctx->current) return 0; + return ctx->current->bounds.w; +} +NK_API float +nk_window_get_height(const struct nk_context *ctx) +{ + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + if (!ctx || !ctx->current) return 0; + return ctx->current->bounds.h; +} +NK_API struct nk_rect +nk_window_get_content_region(struct nk_context *ctx) +{ + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + if (!ctx || !ctx->current) return nk_rect(0,0,0,0); + return ctx->current->layout->clip; +} +NK_API struct nk_vec2 +nk_window_get_content_region_min(struct nk_context *ctx) +{ + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current) return nk_vec2(0,0); + return nk_vec2(ctx->current->layout->clip.x, ctx->current->layout->clip.y); +} +NK_API struct nk_vec2 +nk_window_get_content_region_max(struct nk_context *ctx) +{ + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current) return nk_vec2(0,0); + return nk_vec2(ctx->current->layout->clip.x + ctx->current->layout->clip.w, + ctx->current->layout->clip.y + ctx->current->layout->clip.h); +} +NK_API struct nk_vec2 +nk_window_get_content_region_size(struct nk_context *ctx) +{ + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current) return nk_vec2(0,0); + return nk_vec2(ctx->current->layout->clip.w, ctx->current->layout->clip.h); +} +NK_API struct nk_command_buffer* +nk_window_get_canvas(struct nk_context *ctx) +{ + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current) return 0; + return &ctx->current->buffer; +} +NK_API struct nk_panel* +nk_window_get_panel(struct nk_context *ctx) +{ + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + if (!ctx || !ctx->current) return 0; + return ctx->current->layout; +} +NK_API void +nk_window_get_scroll(struct nk_context *ctx, nk_uint *offset_x, nk_uint *offset_y) +{ + struct nk_window *win; + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + if (!ctx || !ctx->current) + return ; + win = ctx->current; + if (offset_x) + *offset_x = win->scrollbar.x; + if (offset_y) + *offset_y = win->scrollbar.y; +} +NK_API nk_bool +nk_window_has_focus(const struct nk_context *ctx) +{ + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current) return 0; + return ctx->current == ctx->active; +} +NK_API nk_bool +nk_window_is_hovered(struct nk_context *ctx) +{ + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + if (!ctx || !ctx->current || (ctx->current->flags & NK_WINDOW_HIDDEN)) + return 0; + else { + struct nk_rect actual_bounds = ctx->current->bounds; + if (ctx->begin->flags & NK_WINDOW_MINIMIZED) { + actual_bounds.h = ctx->current->layout->header_height; + } + return nk_input_is_mouse_hovering_rect(&ctx->input, actual_bounds); + } +} +NK_API nk_bool +nk_window_is_any_hovered(struct nk_context *ctx) +{ + struct nk_window *iter; + NK_ASSERT(ctx); + if (!ctx) return 0; + iter = ctx->begin; + while (iter) { + /* check if window is being hovered */ + if(!(iter->flags & NK_WINDOW_HIDDEN)) { + /* check if window popup is being hovered */ + if (iter->popup.active && iter->popup.win && nk_input_is_mouse_hovering_rect(&ctx->input, iter->popup.win->bounds)) + return 1; + + if (iter->flags & NK_WINDOW_MINIMIZED) { + struct nk_rect header = iter->bounds; + header.h = ctx->style.font->height + 2 * ctx->style.window.header.padding.y; + if (nk_input_is_mouse_hovering_rect(&ctx->input, header)) + return 1; + } else if (nk_input_is_mouse_hovering_rect(&ctx->input, iter->bounds)) { + return 1; + } + } + iter = iter->next; + } + return 0; +} +NK_API nk_bool +nk_item_is_any_active(struct nk_context *ctx) +{ + int any_hovered = nk_window_is_any_hovered(ctx); + int any_active = (ctx->last_widget_state & NK_WIDGET_STATE_MODIFIED); + return any_hovered || any_active; +} +NK_API nk_bool +nk_window_is_collapsed(struct nk_context *ctx, const char *name) +{ + int title_len; + nk_hash title_hash; + struct nk_window *win; + NK_ASSERT(ctx); + if (!ctx) return 0; + + title_len = (int)nk_strlen(name); + title_hash = nk_murmur_hash(name, (int)title_len, NK_WINDOW_TITLE); + win = nk_find_window(ctx, title_hash, name); + if (!win) return 0; + return win->flags & NK_WINDOW_MINIMIZED; +} +NK_API nk_bool +nk_window_is_closed(struct nk_context *ctx, const char *name) +{ + int title_len; + nk_hash title_hash; + struct nk_window *win; + NK_ASSERT(ctx); + if (!ctx) return 1; + + title_len = (int)nk_strlen(name); + title_hash = nk_murmur_hash(name, (int)title_len, NK_WINDOW_TITLE); + win = nk_find_window(ctx, title_hash, name); + if (!win) return 1; + return (win->flags & NK_WINDOW_CLOSED); +} +NK_API nk_bool +nk_window_is_hidden(struct nk_context *ctx, const char *name) +{ + int title_len; + nk_hash title_hash; + struct nk_window *win; + NK_ASSERT(ctx); + if (!ctx) return 1; + + title_len = (int)nk_strlen(name); + title_hash = nk_murmur_hash(name, (int)title_len, NK_WINDOW_TITLE); + win = nk_find_window(ctx, title_hash, name); + if (!win) return 1; + return (win->flags & NK_WINDOW_HIDDEN); +} +NK_API nk_bool +nk_window_is_active(struct nk_context *ctx, const char *name) +{ + int title_len; + nk_hash title_hash; + struct nk_window *win; + NK_ASSERT(ctx); + if (!ctx) return 0; + + title_len = (int)nk_strlen(name); + title_hash = nk_murmur_hash(name, (int)title_len, NK_WINDOW_TITLE); + win = nk_find_window(ctx, title_hash, name); + if (!win) return 0; + return win == ctx->active; +} +NK_API struct nk_window* +nk_window_find(struct nk_context *ctx, const char *name) +{ + int title_len; + nk_hash title_hash; + title_len = (int)nk_strlen(name); + title_hash = nk_murmur_hash(name, (int)title_len, NK_WINDOW_TITLE); + return nk_find_window(ctx, title_hash, name); +} +NK_API void +nk_window_close(struct nk_context *ctx, const char *name) +{ + struct nk_window *win; + NK_ASSERT(ctx); + if (!ctx) return; + win = nk_window_find(ctx, name); + if (!win) return; + NK_ASSERT(ctx->current != win && "You cannot close a currently active window"); + if (ctx->current == win) return; + win->flags |= NK_WINDOW_HIDDEN; + win->flags |= NK_WINDOW_CLOSED; +} +NK_API void +nk_window_set_bounds(struct nk_context *ctx, + const char *name, struct nk_rect bounds) +{ + struct nk_window *win; + NK_ASSERT(ctx); + if (!ctx) return; + win = nk_window_find(ctx, name); + if (!win) return; + NK_ASSERT(ctx->current != win && "You cannot update a currently in procecss window"); + win->bounds = bounds; +} +NK_API void +nk_window_set_position(struct nk_context *ctx, + const char *name, struct nk_vec2 pos) +{ + struct nk_window *win = nk_window_find(ctx, name); + if (!win) return; + win->bounds.x = pos.x; + win->bounds.y = pos.y; +} +NK_API void +nk_window_set_size(struct nk_context *ctx, + const char *name, struct nk_vec2 size) +{ + struct nk_window *win = nk_window_find(ctx, name); + if (!win) return; + win->bounds.w = size.x; + win->bounds.h = size.y; +} +NK_API void +nk_window_set_scroll(struct nk_context *ctx, nk_uint offset_x, nk_uint offset_y) +{ + struct nk_window *win; + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + if (!ctx || !ctx->current) + return; + win = ctx->current; + win->scrollbar.x = offset_x; + win->scrollbar.y = offset_y; +} +NK_API void +nk_window_collapse(struct nk_context *ctx, const char *name, + enum nk_collapse_states c) +{ + int title_len; + nk_hash title_hash; + struct nk_window *win; + NK_ASSERT(ctx); + if (!ctx) return; + + title_len = (int)nk_strlen(name); + title_hash = nk_murmur_hash(name, (int)title_len, NK_WINDOW_TITLE); + win = nk_find_window(ctx, title_hash, name); + if (!win) return; + if (c == NK_MINIMIZED) + win->flags |= NK_WINDOW_MINIMIZED; + else win->flags &= ~(nk_flags)NK_WINDOW_MINIMIZED; +} +NK_API void +nk_window_collapse_if(struct nk_context *ctx, const char *name, + enum nk_collapse_states c, int cond) +{ + NK_ASSERT(ctx); + if (!ctx || !cond) return; + nk_window_collapse(ctx, name, c); +} +NK_API void +nk_window_show(struct nk_context *ctx, const char *name, enum nk_show_states s) +{ + int title_len; + nk_hash title_hash; + struct nk_window *win; + NK_ASSERT(ctx); + if (!ctx) return; + + title_len = (int)nk_strlen(name); + title_hash = nk_murmur_hash(name, (int)title_len, NK_WINDOW_TITLE); + win = nk_find_window(ctx, title_hash, name); + if (!win) return; + if (s == NK_HIDDEN) { + win->flags |= NK_WINDOW_HIDDEN; + } else win->flags &= ~(nk_flags)NK_WINDOW_HIDDEN; +} +NK_API void +nk_window_show_if(struct nk_context *ctx, const char *name, + enum nk_show_states s, int cond) +{ + NK_ASSERT(ctx); + if (!ctx || !cond) return; + nk_window_show(ctx, name, s); +} + +NK_API void +nk_window_set_focus(struct nk_context *ctx, const char *name) +{ + int title_len; + nk_hash title_hash; + struct nk_window *win; + NK_ASSERT(ctx); + if (!ctx) return; + + title_len = (int)nk_strlen(name); + title_hash = nk_murmur_hash(name, (int)title_len, NK_WINDOW_TITLE); + win = nk_find_window(ctx, title_hash, name); + if (win && ctx->end != win) { + nk_remove_window(ctx, win); + nk_insert_window(ctx, win, NK_INSERT_BACK); + } + ctx->active = win; +} + + + + +/* =============================================================== + * + * POPUP + * + * ===============================================================*/ +NK_API nk_bool +nk_popup_begin(struct nk_context *ctx, enum nk_popup_type type, + const char *title, nk_flags flags, struct nk_rect rect) +{ + struct nk_window *popup; + struct nk_window *win; + struct nk_panel *panel; + + int title_len; + nk_hash title_hash; + nk_size allocated; + + NK_ASSERT(ctx); + NK_ASSERT(title); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return 0; + + win = ctx->current; + panel = win->layout; + NK_ASSERT(!(panel->type & NK_PANEL_SET_POPUP) && "popups are not allowed to have popups"); + (void)panel; + title_len = (int)nk_strlen(title); + title_hash = nk_murmur_hash(title, (int)title_len, NK_PANEL_POPUP); + + popup = win->popup.win; + if (!popup) { + popup = (struct nk_window*)nk_create_window(ctx); + popup->parent = win; + win->popup.win = popup; + win->popup.active = 0; + win->popup.type = NK_PANEL_POPUP; + } + + /* make sure we have correct popup */ + if (win->popup.name != title_hash) { + if (!win->popup.active) { + nk_zero(popup, sizeof(*popup)); + win->popup.name = title_hash; + win->popup.active = 1; + win->popup.type = NK_PANEL_POPUP; + } else return 0; + } + + /* popup position is local to window */ + ctx->current = popup; + rect.x += win->layout->clip.x; + rect.y += win->layout->clip.y; + + /* setup popup data */ + popup->parent = win; + popup->bounds = rect; + popup->seq = ctx->seq; + popup->layout = (struct nk_panel*)nk_create_panel(ctx); + popup->flags = flags; + popup->flags |= NK_WINDOW_BORDER; + if (type == NK_POPUP_DYNAMIC) + popup->flags |= NK_WINDOW_DYNAMIC; + + popup->buffer = win->buffer; + nk_start_popup(ctx, win); + allocated = ctx->memory.allocated; + nk_push_scissor(&popup->buffer, nk_null_rect); + + if (nk_panel_begin(ctx, title, NK_PANEL_POPUP)) { + /* popup is running therefore invalidate parent panels */ + struct nk_panel *root; + root = win->layout; + while (root) { + root->flags |= NK_WINDOW_ROM; + root->flags &= ~(nk_flags)NK_WINDOW_REMOVE_ROM; + root = root->parent; + } + win->popup.active = 1; + popup->layout->offset_x = &popup->scrollbar.x; + popup->layout->offset_y = &popup->scrollbar.y; + popup->layout->parent = win->layout; + return 1; + } else { + /* popup was closed/is invalid so cleanup */ + struct nk_panel *root; + root = win->layout; + while (root) { + root->flags |= NK_WINDOW_REMOVE_ROM; + root = root->parent; + } + win->popup.buf.active = 0; + win->popup.active = 0; + ctx->memory.allocated = allocated; + ctx->current = win; + nk_free_panel(ctx, popup->layout); + popup->layout = 0; + return 0; + } +} +NK_LIB nk_bool +nk_nonblock_begin(struct nk_context *ctx, + nk_flags flags, struct nk_rect body, struct nk_rect header, + enum nk_panel_type panel_type) +{ + struct nk_window *popup; + struct nk_window *win; + struct nk_panel *panel; + int is_active = nk_true; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return 0; + + /* popups cannot have popups */ + win = ctx->current; + panel = win->layout; + NK_ASSERT(!(panel->type & NK_PANEL_SET_POPUP)); + (void)panel; + popup = win->popup.win; + if (!popup) { + /* create window for nonblocking popup */ + popup = (struct nk_window*)nk_create_window(ctx); + popup->parent = win; + win->popup.win = popup; + win->popup.type = panel_type; + nk_command_buffer_init(&popup->buffer, &ctx->memory, NK_CLIPPING_ON); + } else { + /* close the popup if user pressed outside or in the header */ + int pressed, in_body, in_header; +#ifdef NK_BUTTON_TRIGGER_ON_RELEASE + pressed = nk_input_is_mouse_released(&ctx->input, NK_BUTTON_LEFT); +#else + pressed = nk_input_is_mouse_pressed(&ctx->input, NK_BUTTON_LEFT); +#endif + in_body = nk_input_is_mouse_hovering_rect(&ctx->input, body); + in_header = nk_input_is_mouse_hovering_rect(&ctx->input, header); + if (pressed && (!in_body || in_header)) + is_active = nk_false; + } + win->popup.header = header; + + if (!is_active) { + /* remove read only mode from all parent panels */ + struct nk_panel *root = win->layout; + while (root) { + root->flags |= NK_WINDOW_REMOVE_ROM; + root = root->parent; + } + return is_active; + } + popup->bounds = body; + popup->parent = win; + popup->layout = (struct nk_panel*)nk_create_panel(ctx); + popup->flags = flags; + popup->flags |= NK_WINDOW_BORDER; + popup->flags |= NK_WINDOW_DYNAMIC; + popup->seq = ctx->seq; + win->popup.active = 1; + NK_ASSERT(popup->layout); + + nk_start_popup(ctx, win); + popup->buffer = win->buffer; + nk_push_scissor(&popup->buffer, nk_null_rect); + ctx->current = popup; + + nk_panel_begin(ctx, 0, panel_type); + win->buffer = popup->buffer; + popup->layout->parent = win->layout; + popup->layout->offset_x = &popup->scrollbar.x; + popup->layout->offset_y = &popup->scrollbar.y; + + /* set read only mode to all parent panels */ + {struct nk_panel *root; + root = win->layout; + while (root) { + root->flags |= NK_WINDOW_ROM; + root = root->parent; + }} + return is_active; +} +NK_API void +nk_popup_close(struct nk_context *ctx) +{ + struct nk_window *popup; + NK_ASSERT(ctx); + if (!ctx || !ctx->current) return; + + popup = ctx->current; + NK_ASSERT(popup->parent); + NK_ASSERT(popup->layout->type & NK_PANEL_SET_POPUP); + popup->flags |= NK_WINDOW_HIDDEN; +} +NK_API void +nk_popup_end(struct nk_context *ctx) +{ + struct nk_window *win; + struct nk_window *popup; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return; + + popup = ctx->current; + if (!popup->parent) return; + win = popup->parent; + if (popup->flags & NK_WINDOW_HIDDEN) { + struct nk_panel *root; + root = win->layout; + while (root) { + root->flags |= NK_WINDOW_REMOVE_ROM; + root = root->parent; + } + win->popup.active = 0; + } + nk_push_scissor(&popup->buffer, nk_null_rect); + nk_end(ctx); + + win->buffer = popup->buffer; + nk_finish_popup(ctx, win); + ctx->current = win; + nk_push_scissor(&win->buffer, win->layout->clip); +} +NK_API void +nk_popup_get_scroll(struct nk_context *ctx, nk_uint *offset_x, nk_uint *offset_y) +{ + struct nk_window *popup; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return; + + popup = ctx->current; + if (offset_x) + *offset_x = popup->scrollbar.x; + if (offset_y) + *offset_y = popup->scrollbar.y; +} +NK_API void +nk_popup_set_scroll(struct nk_context *ctx, nk_uint offset_x, nk_uint offset_y) +{ + struct nk_window *popup; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return; + + popup = ctx->current; + popup->scrollbar.x = offset_x; + popup->scrollbar.y = offset_y; +} + + + + +/* ============================================================== + * + * CONTEXTUAL + * + * ===============================================================*/ +NK_API nk_bool +nk_contextual_begin(struct nk_context *ctx, nk_flags flags, struct nk_vec2 size, + struct nk_rect trigger_bounds) +{ + struct nk_window *win; + struct nk_window *popup; + struct nk_rect body; + + NK_STORAGE const struct nk_rect null_rect = {-1,-1,0,0}; + int is_clicked = 0; + int is_open = 0; + int ret = 0; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return 0; + + win = ctx->current; + ++win->popup.con_count; + if (ctx->current != ctx->active) + return 0; + + /* check if currently active contextual is active */ + popup = win->popup.win; + is_open = (popup && win->popup.type == NK_PANEL_CONTEXTUAL); + is_clicked = nk_input_mouse_clicked(&ctx->input, NK_BUTTON_RIGHT, trigger_bounds); + if (win->popup.active_con && win->popup.con_count != win->popup.active_con) + return 0; + if (!is_open && win->popup.active_con) + win->popup.active_con = 0; + if ((!is_open && !is_clicked)) + return 0; + + /* calculate contextual position on click */ + win->popup.active_con = win->popup.con_count; + if (is_clicked) { + body.x = ctx->input.mouse.pos.x; + body.y = ctx->input.mouse.pos.y; + } else { + body.x = popup->bounds.x; + body.y = popup->bounds.y; + } + body.w = size.x; + body.h = size.y; + + /* start nonblocking contextual popup */ + ret = nk_nonblock_begin(ctx, flags|NK_WINDOW_NO_SCROLLBAR, body, + null_rect, NK_PANEL_CONTEXTUAL); + if (ret) win->popup.type = NK_PANEL_CONTEXTUAL; + else { + win->popup.active_con = 0; + win->popup.type = NK_PANEL_NONE; + if (win->popup.win) + win->popup.win->flags = 0; + } + return ret; +} +NK_API nk_bool +nk_contextual_item_text(struct nk_context *ctx, const char *text, int len, + nk_flags alignment) +{ + struct nk_window *win; + const struct nk_input *in; + const struct nk_style *style; + + struct nk_rect bounds; + enum nk_widget_layout_states state; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return 0; + + win = ctx->current; + style = &ctx->style; + state = nk_widget_fitting(&bounds, ctx, style->contextual_button.padding); + if (!state) return nk_false; + + in = (state == NK_WIDGET_ROM || win->layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + if (nk_do_button_text(&ctx->last_widget_state, &win->buffer, bounds, + text, len, alignment, NK_BUTTON_DEFAULT, &style->contextual_button, in, style->font)) { + nk_contextual_close(ctx); + return nk_true; + } + return nk_false; +} +NK_API nk_bool +nk_contextual_item_label(struct nk_context *ctx, const char *label, nk_flags align) +{ + return nk_contextual_item_text(ctx, label, nk_strlen(label), align); +} +NK_API nk_bool +nk_contextual_item_image_text(struct nk_context *ctx, struct nk_image img, + const char *text, int len, nk_flags align) +{ + struct nk_window *win; + const struct nk_input *in; + const struct nk_style *style; + + struct nk_rect bounds; + enum nk_widget_layout_states state; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return 0; + + win = ctx->current; + style = &ctx->style; + state = nk_widget_fitting(&bounds, ctx, style->contextual_button.padding); + if (!state) return nk_false; + + in = (state == NK_WIDGET_ROM || win->layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + if (nk_do_button_text_image(&ctx->last_widget_state, &win->buffer, bounds, + img, text, len, align, NK_BUTTON_DEFAULT, &style->contextual_button, style->font, in)){ + nk_contextual_close(ctx); + return nk_true; + } + return nk_false; +} +NK_API nk_bool +nk_contextual_item_image_label(struct nk_context *ctx, struct nk_image img, + const char *label, nk_flags align) +{ + return nk_contextual_item_image_text(ctx, img, label, nk_strlen(label), align); +} +NK_API nk_bool +nk_contextual_item_symbol_text(struct nk_context *ctx, enum nk_symbol_type symbol, + const char *text, int len, nk_flags align) +{ + struct nk_window *win; + const struct nk_input *in; + const struct nk_style *style; + + struct nk_rect bounds; + enum nk_widget_layout_states state; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return 0; + + win = ctx->current; + style = &ctx->style; + state = nk_widget_fitting(&bounds, ctx, style->contextual_button.padding); + if (!state) return nk_false; + + in = (state == NK_WIDGET_ROM || win->layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + if (nk_do_button_text_symbol(&ctx->last_widget_state, &win->buffer, bounds, + symbol, text, len, align, NK_BUTTON_DEFAULT, &style->contextual_button, style->font, in)) { + nk_contextual_close(ctx); + return nk_true; + } + return nk_false; +} +NK_API nk_bool +nk_contextual_item_symbol_label(struct nk_context *ctx, enum nk_symbol_type symbol, + const char *text, nk_flags align) +{ + return nk_contextual_item_symbol_text(ctx, symbol, text, nk_strlen(text), align); +} +NK_API void +nk_contextual_close(struct nk_context *ctx) +{ + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) return; + nk_popup_close(ctx); +} +NK_API void +nk_contextual_end(struct nk_context *ctx) +{ + struct nk_window *popup; + struct nk_panel *panel; + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + if (!ctx || !ctx->current) return; + + popup = ctx->current; + panel = popup->layout; + NK_ASSERT(popup->parent); + NK_ASSERT(panel->type & NK_PANEL_SET_POPUP); + if (panel->flags & NK_WINDOW_DYNAMIC) { + /* Close behavior + This is a bit of a hack solution since we do not know before we end our popup + how big it will be. We therefore do not directly know when a + click outside the non-blocking popup must close it at that direct frame. + Instead it will be closed in the next frame.*/ + struct nk_rect body = {0,0,0,0}; + if (panel->at_y < (panel->bounds.y + panel->bounds.h)) { + struct nk_vec2 padding = nk_panel_get_padding(&ctx->style, panel->type); + body = panel->bounds; + body.y = (panel->at_y + panel->footer_height + panel->border + padding.y + panel->row.height); + body.h = (panel->bounds.y + panel->bounds.h) - body.y; + } + {int pressed = nk_input_is_mouse_pressed(&ctx->input, NK_BUTTON_LEFT); + int in_body = nk_input_is_mouse_hovering_rect(&ctx->input, body); + if (pressed && in_body) + popup->flags |= NK_WINDOW_HIDDEN; + } + } + if (popup->flags & NK_WINDOW_HIDDEN) + popup->seq = 0; + nk_popup_end(ctx); + return; +} + + + + + +/* =============================================================== + * + * MENU + * + * ===============================================================*/ +NK_API void +nk_menubar_begin(struct nk_context *ctx) +{ + struct nk_panel *layout; + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return; + + layout = ctx->current->layout; + NK_ASSERT(layout->at_y == layout->bounds.y); + /* if this assert triggers you allocated space between nk_begin and nk_menubar_begin. + If you want a menubar the first nuklear function after `nk_begin` has to be a + `nk_menubar_begin` call. Inside the menubar you then have to allocate space for + widgets (also supports multiple rows). + Example: + if (nk_begin(...)) { + nk_menubar_begin(...); + nk_layout_xxxx(...); + nk_button(...); + nk_layout_xxxx(...); + nk_button(...); + nk_menubar_end(...); + } + nk_end(...); + */ + if (layout->flags & NK_WINDOW_HIDDEN || layout->flags & NK_WINDOW_MINIMIZED) + return; + + layout->menu.x = layout->at_x; + layout->menu.y = layout->at_y + layout->row.height; + layout->menu.w = layout->bounds.w; + layout->menu.offset.x = *layout->offset_x; + layout->menu.offset.y = *layout->offset_y; + *layout->offset_y = 0; +} +NK_API void +nk_menubar_end(struct nk_context *ctx) +{ + struct nk_window *win; + struct nk_panel *layout; + struct nk_command_buffer *out; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return; + + win = ctx->current; + out = &win->buffer; + layout = win->layout; + if (layout->flags & NK_WINDOW_HIDDEN || layout->flags & NK_WINDOW_MINIMIZED) + return; + + layout->menu.h = layout->at_y - layout->menu.y; + layout->menu.h += layout->row.height + ctx->style.window.spacing.y; + + layout->bounds.y += layout->menu.h; + layout->bounds.h -= layout->menu.h; + + *layout->offset_x = layout->menu.offset.x; + *layout->offset_y = layout->menu.offset.y; + layout->at_y = layout->bounds.y - layout->row.height; + + layout->clip.y = layout->bounds.y; + layout->clip.h = layout->bounds.h; + nk_push_scissor(out, layout->clip); +} +NK_INTERN int +nk_menu_begin(struct nk_context *ctx, struct nk_window *win, + const char *id, int is_clicked, struct nk_rect header, struct nk_vec2 size) +{ + int is_open = 0; + int is_active = 0; + struct nk_rect body; + struct nk_window *popup; + nk_hash hash = nk_murmur_hash(id, (int)nk_strlen(id), NK_PANEL_MENU); + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return 0; + + body.x = header.x; + body.w = size.x; + body.y = header.y + header.h; + body.h = size.y; + + popup = win->popup.win; + is_open = popup ? nk_true : nk_false; + is_active = (popup && (win->popup.name == hash) && win->popup.type == NK_PANEL_MENU); + if ((is_clicked && is_open && !is_active) || (is_open && !is_active) || + (!is_open && !is_active && !is_clicked)) return 0; + if (!nk_nonblock_begin(ctx, NK_WINDOW_NO_SCROLLBAR, body, header, NK_PANEL_MENU)) + return 0; + + win->popup.type = NK_PANEL_MENU; + win->popup.name = hash; + return 1; +} +NK_API nk_bool +nk_menu_begin_text(struct nk_context *ctx, const char *title, int len, + nk_flags align, struct nk_vec2 size) +{ + struct nk_window *win; + const struct nk_input *in; + struct nk_rect header; + int is_clicked = nk_false; + nk_flags state; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return 0; + + win = ctx->current; + state = nk_widget(&header, ctx); + if (!state) return 0; + in = (state == NK_WIDGET_ROM || win->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + if (nk_do_button_text(&ctx->last_widget_state, &win->buffer, header, + title, len, align, NK_BUTTON_DEFAULT, &ctx->style.menu_button, in, ctx->style.font)) + is_clicked = nk_true; + return nk_menu_begin(ctx, win, title, is_clicked, header, size); +} +NK_API nk_bool nk_menu_begin_label(struct nk_context *ctx, + const char *text, nk_flags align, struct nk_vec2 size) +{ + return nk_menu_begin_text(ctx, text, nk_strlen(text), align, size); +} +NK_API nk_bool +nk_menu_begin_image(struct nk_context *ctx, const char *id, struct nk_image img, + struct nk_vec2 size) +{ + struct nk_window *win; + struct nk_rect header; + const struct nk_input *in; + int is_clicked = nk_false; + nk_flags state; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return 0; + + win = ctx->current; + state = nk_widget(&header, ctx); + if (!state) return 0; + in = (state == NK_WIDGET_ROM || win->layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + if (nk_do_button_image(&ctx->last_widget_state, &win->buffer, header, + img, NK_BUTTON_DEFAULT, &ctx->style.menu_button, in)) + is_clicked = nk_true; + return nk_menu_begin(ctx, win, id, is_clicked, header, size); +} +NK_API nk_bool +nk_menu_begin_symbol(struct nk_context *ctx, const char *id, + enum nk_symbol_type sym, struct nk_vec2 size) +{ + struct nk_window *win; + const struct nk_input *in; + struct nk_rect header; + int is_clicked = nk_false; + nk_flags state; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return 0; + + win = ctx->current; + state = nk_widget(&header, ctx); + if (!state) return 0; + in = (state == NK_WIDGET_ROM || win->layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + if (nk_do_button_symbol(&ctx->last_widget_state, &win->buffer, header, + sym, NK_BUTTON_DEFAULT, &ctx->style.menu_button, in, ctx->style.font)) + is_clicked = nk_true; + return nk_menu_begin(ctx, win, id, is_clicked, header, size); +} +NK_API nk_bool +nk_menu_begin_image_text(struct nk_context *ctx, const char *title, int len, + nk_flags align, struct nk_image img, struct nk_vec2 size) +{ + struct nk_window *win; + struct nk_rect header; + const struct nk_input *in; + int is_clicked = nk_false; + nk_flags state; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return 0; + + win = ctx->current; + state = nk_widget(&header, ctx); + if (!state) return 0; + in = (state == NK_WIDGET_ROM || win->layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + if (nk_do_button_text_image(&ctx->last_widget_state, &win->buffer, + header, img, title, len, align, NK_BUTTON_DEFAULT, &ctx->style.menu_button, + ctx->style.font, in)) + is_clicked = nk_true; + return nk_menu_begin(ctx, win, title, is_clicked, header, size); +} +NK_API nk_bool +nk_menu_begin_image_label(struct nk_context *ctx, + const char *title, nk_flags align, struct nk_image img, struct nk_vec2 size) +{ + return nk_menu_begin_image_text(ctx, title, nk_strlen(title), align, img, size); +} +NK_API nk_bool +nk_menu_begin_symbol_text(struct nk_context *ctx, const char *title, int len, + nk_flags align, enum nk_symbol_type sym, struct nk_vec2 size) +{ + struct nk_window *win; + struct nk_rect header; + const struct nk_input *in; + int is_clicked = nk_false; + nk_flags state; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return 0; + + win = ctx->current; + state = nk_widget(&header, ctx); + if (!state) return 0; + + in = (state == NK_WIDGET_ROM || win->layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + if (nk_do_button_text_symbol(&ctx->last_widget_state, &win->buffer, + header, sym, title, len, align, NK_BUTTON_DEFAULT, &ctx->style.menu_button, + ctx->style.font, in)) is_clicked = nk_true; + return nk_menu_begin(ctx, win, title, is_clicked, header, size); +} +NK_API nk_bool +nk_menu_begin_symbol_label(struct nk_context *ctx, + const char *title, nk_flags align, enum nk_symbol_type sym, struct nk_vec2 size ) +{ + return nk_menu_begin_symbol_text(ctx, title, nk_strlen(title), align,sym,size); +} +NK_API nk_bool +nk_menu_item_text(struct nk_context *ctx, const char *title, int len, nk_flags align) +{ + return nk_contextual_item_text(ctx, title, len, align); +} +NK_API nk_bool +nk_menu_item_label(struct nk_context *ctx, const char *label, nk_flags align) +{ + return nk_contextual_item_label(ctx, label, align); +} +NK_API nk_bool +nk_menu_item_image_label(struct nk_context *ctx, struct nk_image img, + const char *label, nk_flags align) +{ + return nk_contextual_item_image_label(ctx, img, label, align); +} +NK_API nk_bool +nk_menu_item_image_text(struct nk_context *ctx, struct nk_image img, + const char *text, int len, nk_flags align) +{ + return nk_contextual_item_image_text(ctx, img, text, len, align); +} +NK_API nk_bool nk_menu_item_symbol_text(struct nk_context *ctx, enum nk_symbol_type sym, + const char *text, int len, nk_flags align) +{ + return nk_contextual_item_symbol_text(ctx, sym, text, len, align); +} +NK_API nk_bool nk_menu_item_symbol_label(struct nk_context *ctx, enum nk_symbol_type sym, + const char *label, nk_flags align) +{ + return nk_contextual_item_symbol_label(ctx, sym, label, align); +} +NK_API void nk_menu_close(struct nk_context *ctx) +{ + nk_contextual_close(ctx); +} +NK_API void +nk_menu_end(struct nk_context *ctx) +{ + nk_contextual_end(ctx); +} + + + + + +/* =============================================================== + * + * LAYOUT + * + * ===============================================================*/ +NK_API void +nk_layout_set_min_row_height(struct nk_context *ctx, float height) +{ + struct nk_window *win; + struct nk_panel *layout; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return; + + win = ctx->current; + layout = win->layout; + layout->row.min_height = height; +} +NK_API void +nk_layout_reset_min_row_height(struct nk_context *ctx) +{ + struct nk_window *win; + struct nk_panel *layout; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return; + + win = ctx->current; + layout = win->layout; + layout->row.min_height = ctx->style.font->height; + layout->row.min_height += ctx->style.text.padding.y*2; + layout->row.min_height += ctx->style.window.min_row_height_padding*2; +} +NK_LIB float +nk_layout_row_calculate_usable_space(const struct nk_style *style, enum nk_panel_type type, + float total_space, int columns) +{ + float panel_spacing; + float panel_space; + + struct nk_vec2 spacing; + + NK_UNUSED(type); + + spacing = style->window.spacing; + + /* calculate the usable panel space */ + panel_spacing = (float)NK_MAX(columns - 1, 0) * spacing.x; + panel_space = total_space - panel_spacing; + return panel_space; +} +NK_LIB void +nk_panel_layout(const struct nk_context *ctx, struct nk_window *win, + float height, int cols) +{ + struct nk_panel *layout; + const struct nk_style *style; + struct nk_command_buffer *out; + + struct nk_vec2 item_spacing; + struct nk_color color; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return; + + /* prefetch some configuration data */ + layout = win->layout; + style = &ctx->style; + out = &win->buffer; + color = style->window.background; + item_spacing = style->window.spacing; + + /* if one of these triggers you forgot to add an `if` condition around either + a window, group, popup, combobox or contextual menu `begin` and `end` block. + Example: + if (nk_begin(...) {...} nk_end(...); or + if (nk_group_begin(...) { nk_group_end(...);} */ + NK_ASSERT(!(layout->flags & NK_WINDOW_MINIMIZED)); + NK_ASSERT(!(layout->flags & NK_WINDOW_HIDDEN)); + NK_ASSERT(!(layout->flags & NK_WINDOW_CLOSED)); + + /* update the current row and set the current row layout */ + layout->row.index = 0; + layout->at_y += layout->row.height; + layout->row.columns = cols; + if (height == 0.0f) + layout->row.height = NK_MAX(height, layout->row.min_height) + item_spacing.y; + else layout->row.height = height + item_spacing.y; + + layout->row.item_offset = 0; + if (layout->flags & NK_WINDOW_DYNAMIC) { + /* draw background for dynamic panels */ + struct nk_rect background; + background.x = win->bounds.x; + background.w = win->bounds.w; + background.y = layout->at_y - 1.0f; + background.h = layout->row.height + 1.0f; + nk_fill_rect(out, background, 0, color); + } +} +NK_LIB void +nk_row_layout(struct nk_context *ctx, enum nk_layout_format fmt, + float height, int cols, int width) +{ + /* update the current row and set the current row layout */ + struct nk_window *win; + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return; + + win = ctx->current; + nk_panel_layout(ctx, win, height, cols); + if (fmt == NK_DYNAMIC) + win->layout->row.type = NK_LAYOUT_DYNAMIC_FIXED; + else win->layout->row.type = NK_LAYOUT_STATIC_FIXED; + + win->layout->row.ratio = 0; + win->layout->row.filled = 0; + win->layout->row.item_offset = 0; + win->layout->row.item_width = (float)width; +} +NK_API float +nk_layout_ratio_from_pixel(struct nk_context *ctx, float pixel_width) +{ + struct nk_window *win; + NK_ASSERT(ctx); + NK_ASSERT(pixel_width); + if (!ctx || !ctx->current || !ctx->current->layout) return 0; + win = ctx->current; + return NK_CLAMP(0.0f, pixel_width/win->bounds.x, 1.0f); +} +NK_API void +nk_layout_row_dynamic(struct nk_context *ctx, float height, int cols) +{ + nk_row_layout(ctx, NK_DYNAMIC, height, cols, 0); +} +NK_API void +nk_layout_row_static(struct nk_context *ctx, float height, int item_width, int cols) +{ + nk_row_layout(ctx, NK_STATIC, height, cols, item_width); +} +NK_API void +nk_layout_row_begin(struct nk_context *ctx, enum nk_layout_format fmt, + float row_height, int cols) +{ + struct nk_window *win; + struct nk_panel *layout; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return; + + win = ctx->current; + layout = win->layout; + nk_panel_layout(ctx, win, row_height, cols); + if (fmt == NK_DYNAMIC) + layout->row.type = NK_LAYOUT_DYNAMIC_ROW; + else layout->row.type = NK_LAYOUT_STATIC_ROW; + + layout->row.ratio = 0; + layout->row.filled = 0; + layout->row.item_width = 0; + layout->row.item_offset = 0; + layout->row.columns = cols; +} +NK_API void +nk_layout_row_push(struct nk_context *ctx, float ratio_or_width) +{ + struct nk_window *win; + struct nk_panel *layout; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return; + + win = ctx->current; + layout = win->layout; + NK_ASSERT(layout->row.type == NK_LAYOUT_STATIC_ROW || layout->row.type == NK_LAYOUT_DYNAMIC_ROW); + if (layout->row.type != NK_LAYOUT_STATIC_ROW && layout->row.type != NK_LAYOUT_DYNAMIC_ROW) + return; + + if (layout->row.type == NK_LAYOUT_DYNAMIC_ROW) { + float ratio = ratio_or_width; + if ((ratio + layout->row.filled) > 1.0f) return; + if (ratio > 0.0f) + layout->row.item_width = NK_SATURATE(ratio); + else layout->row.item_width = 1.0f - layout->row.filled; + } else layout->row.item_width = ratio_or_width; +} +NK_API void +nk_layout_row_end(struct nk_context *ctx) +{ + struct nk_window *win; + struct nk_panel *layout; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return; + + win = ctx->current; + layout = win->layout; + NK_ASSERT(layout->row.type == NK_LAYOUT_STATIC_ROW || layout->row.type == NK_LAYOUT_DYNAMIC_ROW); + if (layout->row.type != NK_LAYOUT_STATIC_ROW && layout->row.type != NK_LAYOUT_DYNAMIC_ROW) + return; + layout->row.item_width = 0; + layout->row.item_offset = 0; +} +NK_API void +nk_layout_row(struct nk_context *ctx, enum nk_layout_format fmt, + float height, int cols, const float *ratio) +{ + int i; + int n_undef = 0; + struct nk_window *win; + struct nk_panel *layout; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return; + + win = ctx->current; + layout = win->layout; + nk_panel_layout(ctx, win, height, cols); + if (fmt == NK_DYNAMIC) { + /* calculate width of undefined widget ratios */ + float r = 0; + layout->row.ratio = ratio; + for (i = 0; i < cols; ++i) { + if (ratio[i] < 0.0f) + n_undef++; + else r += ratio[i]; + } + r = NK_SATURATE(1.0f - r); + layout->row.type = NK_LAYOUT_DYNAMIC; + layout->row.item_width = (r > 0 && n_undef > 0) ? (r / (float)n_undef):0; + } else { + layout->row.ratio = ratio; + layout->row.type = NK_LAYOUT_STATIC; + layout->row.item_width = 0; + layout->row.item_offset = 0; + } + layout->row.item_offset = 0; + layout->row.filled = 0; +} +NK_API void +nk_layout_row_template_begin(struct nk_context *ctx, float height) +{ + struct nk_window *win; + struct nk_panel *layout; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return; + + win = ctx->current; + layout = win->layout; + nk_panel_layout(ctx, win, height, 1); + layout->row.type = NK_LAYOUT_TEMPLATE; + layout->row.columns = 0; + layout->row.ratio = 0; + layout->row.item_width = 0; + layout->row.item_height = 0; + layout->row.item_offset = 0; + layout->row.filled = 0; + layout->row.item.x = 0; + layout->row.item.y = 0; + layout->row.item.w = 0; + layout->row.item.h = 0; +} +NK_API void +nk_layout_row_template_push_dynamic(struct nk_context *ctx) +{ + struct nk_window *win; + struct nk_panel *layout; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return; + + win = ctx->current; + layout = win->layout; + NK_ASSERT(layout->row.type == NK_LAYOUT_TEMPLATE); + NK_ASSERT(layout->row.columns < NK_MAX_LAYOUT_ROW_TEMPLATE_COLUMNS); + if (layout->row.type != NK_LAYOUT_TEMPLATE) return; + if (layout->row.columns >= NK_MAX_LAYOUT_ROW_TEMPLATE_COLUMNS) return; + layout->row.templates[layout->row.columns++] = -1.0f; +} +NK_API void +nk_layout_row_template_push_variable(struct nk_context *ctx, float min_width) +{ + struct nk_window *win; + struct nk_panel *layout; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return; + + win = ctx->current; + layout = win->layout; + NK_ASSERT(layout->row.type == NK_LAYOUT_TEMPLATE); + NK_ASSERT(layout->row.columns < NK_MAX_LAYOUT_ROW_TEMPLATE_COLUMNS); + if (layout->row.type != NK_LAYOUT_TEMPLATE) return; + if (layout->row.columns >= NK_MAX_LAYOUT_ROW_TEMPLATE_COLUMNS) return; + layout->row.templates[layout->row.columns++] = -min_width; +} +NK_API void +nk_layout_row_template_push_static(struct nk_context *ctx, float width) +{ + struct nk_window *win; + struct nk_panel *layout; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return; + + win = ctx->current; + layout = win->layout; + NK_ASSERT(layout->row.type == NK_LAYOUT_TEMPLATE); + NK_ASSERT(layout->row.columns < NK_MAX_LAYOUT_ROW_TEMPLATE_COLUMNS); + if (layout->row.type != NK_LAYOUT_TEMPLATE) return; + if (layout->row.columns >= NK_MAX_LAYOUT_ROW_TEMPLATE_COLUMNS) return; + layout->row.templates[layout->row.columns++] = width; +} +NK_API void +nk_layout_row_template_end(struct nk_context *ctx) +{ + struct nk_window *win; + struct nk_panel *layout; + + int i = 0; + int variable_count = 0; + int min_variable_count = 0; + float min_fixed_width = 0.0f; + float total_fixed_width = 0.0f; + float max_variable_width = 0.0f; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return; + + win = ctx->current; + layout = win->layout; + NK_ASSERT(layout->row.type == NK_LAYOUT_TEMPLATE); + if (layout->row.type != NK_LAYOUT_TEMPLATE) return; + for (i = 0; i < layout->row.columns; ++i) { + float width = layout->row.templates[i]; + if (width >= 0.0f) { + total_fixed_width += width; + min_fixed_width += width; + } else if (width < -1.0f) { + width = -width; + total_fixed_width += width; + max_variable_width = NK_MAX(max_variable_width, width); + variable_count++; + } else { + min_variable_count++; + variable_count++; + } + } + if (variable_count) { + float space = nk_layout_row_calculate_usable_space(&ctx->style, layout->type, + layout->bounds.w, layout->row.columns); + float var_width = (NK_MAX(space-min_fixed_width,0.0f)) / (float)variable_count; + int enough_space = var_width >= max_variable_width; + if (!enough_space) + var_width = (NK_MAX(space-total_fixed_width,0)) / (float)min_variable_count; + for (i = 0; i < layout->row.columns; ++i) { + float *width = &layout->row.templates[i]; + *width = (*width >= 0.0f)? *width: (*width < -1.0f && !enough_space)? -(*width): var_width; + } + } +} +NK_API void +nk_layout_space_begin(struct nk_context *ctx, enum nk_layout_format fmt, + float height, int widget_count) +{ + struct nk_window *win; + struct nk_panel *layout; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return; + + win = ctx->current; + layout = win->layout; + nk_panel_layout(ctx, win, height, widget_count); + if (fmt == NK_STATIC) + layout->row.type = NK_LAYOUT_STATIC_FREE; + else layout->row.type = NK_LAYOUT_DYNAMIC_FREE; + + layout->row.ratio = 0; + layout->row.filled = 0; + layout->row.item_width = 0; + layout->row.item_offset = 0; +} +NK_API void +nk_layout_space_end(struct nk_context *ctx) +{ + struct nk_window *win; + struct nk_panel *layout; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return; + + win = ctx->current; + layout = win->layout; + layout->row.item_width = 0; + layout->row.item_height = 0; + layout->row.item_offset = 0; + nk_zero(&layout->row.item, sizeof(layout->row.item)); +} +NK_API void +nk_layout_space_push(struct nk_context *ctx, struct nk_rect rect) +{ + struct nk_window *win; + struct nk_panel *layout; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return; + + win = ctx->current; + layout = win->layout; + layout->row.item = rect; +} +NK_API struct nk_rect +nk_layout_space_bounds(struct nk_context *ctx) +{ + struct nk_rect ret; + struct nk_window *win; + struct nk_panel *layout; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + win = ctx->current; + layout = win->layout; + + ret.x = layout->clip.x; + ret.y = layout->clip.y; + ret.w = layout->clip.w; + ret.h = layout->row.height; + return ret; +} +NK_API struct nk_rect +nk_layout_widget_bounds(struct nk_context *ctx) +{ + struct nk_rect ret; + struct nk_window *win; + struct nk_panel *layout; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + win = ctx->current; + layout = win->layout; + + ret.x = layout->at_x; + ret.y = layout->at_y; + ret.w = layout->bounds.w - NK_MAX(layout->at_x - layout->bounds.x,0); + ret.h = layout->row.height; + return ret; +} +NK_API struct nk_vec2 +nk_layout_space_to_screen(struct nk_context *ctx, struct nk_vec2 ret) +{ + struct nk_window *win; + struct nk_panel *layout; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + win = ctx->current; + layout = win->layout; + + ret.x += layout->at_x - (float)*layout->offset_x; + ret.y += layout->at_y - (float)*layout->offset_y; + return ret; +} +NK_API struct nk_vec2 +nk_layout_space_to_local(struct nk_context *ctx, struct nk_vec2 ret) +{ + struct nk_window *win; + struct nk_panel *layout; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + win = ctx->current; + layout = win->layout; + + ret.x += -layout->at_x + (float)*layout->offset_x; + ret.y += -layout->at_y + (float)*layout->offset_y; + return ret; +} +NK_API struct nk_rect +nk_layout_space_rect_to_screen(struct nk_context *ctx, struct nk_rect ret) +{ + struct nk_window *win; + struct nk_panel *layout; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + win = ctx->current; + layout = win->layout; + + ret.x += layout->at_x - (float)*layout->offset_x; + ret.y += layout->at_y - (float)*layout->offset_y; + return ret; +} +NK_API struct nk_rect +nk_layout_space_rect_to_local(struct nk_context *ctx, struct nk_rect ret) +{ + struct nk_window *win; + struct nk_panel *layout; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + win = ctx->current; + layout = win->layout; + + ret.x += -layout->at_x + (float)*layout->offset_x; + ret.y += -layout->at_y + (float)*layout->offset_y; + return ret; +} +NK_LIB void +nk_panel_alloc_row(const struct nk_context *ctx, struct nk_window *win) +{ + struct nk_panel *layout = win->layout; + struct nk_vec2 spacing = ctx->style.window.spacing; + const float row_height = layout->row.height - spacing.y; + nk_panel_layout(ctx, win, row_height, layout->row.columns); +} +NK_LIB void +nk_layout_widget_space(struct nk_rect *bounds, const struct nk_context *ctx, + struct nk_window *win, int modify) +{ + struct nk_panel *layout; + const struct nk_style *style; + + struct nk_vec2 spacing; + + float item_offset = 0; + float item_width = 0; + float item_spacing = 0; + float panel_space = 0; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return; + + win = ctx->current; + layout = win->layout; + style = &ctx->style; + NK_ASSERT(bounds); + + spacing = style->window.spacing; + panel_space = nk_layout_row_calculate_usable_space(&ctx->style, layout->type, + layout->bounds.w, layout->row.columns); + + #define NK_FRAC(x) (x - (float)(int)x) /* will be used to remove fookin gaps */ + /* calculate the width of one item inside the current layout space */ + switch (layout->row.type) { + case NK_LAYOUT_DYNAMIC_FIXED: { + /* scaling fixed size widgets item width */ + float w = NK_MAX(1.0f,panel_space) / (float)layout->row.columns; + item_offset = (float)layout->row.index * w; + item_width = w + NK_FRAC(item_offset); + item_spacing = (float)layout->row.index * spacing.x; + } break; + case NK_LAYOUT_DYNAMIC_ROW: { + /* scaling single ratio widget width */ + float w = layout->row.item_width * panel_space; + item_offset = layout->row.item_offset; + item_width = w + NK_FRAC(item_offset); + item_spacing = 0; + + if (modify) { + layout->row.item_offset += w + spacing.x; + layout->row.filled += layout->row.item_width; + layout->row.index = 0; + } + } break; + case NK_LAYOUT_DYNAMIC_FREE: { + /* panel width depended free widget placing */ + bounds->x = layout->at_x + (layout->bounds.w * layout->row.item.x); + bounds->x -= (float)*layout->offset_x; + bounds->y = layout->at_y + (layout->row.height * layout->row.item.y); + bounds->y -= (float)*layout->offset_y; + bounds->w = layout->bounds.w * layout->row.item.w + NK_FRAC(bounds->x); + bounds->h = layout->row.height * layout->row.item.h + NK_FRAC(bounds->y); + return; + } + case NK_LAYOUT_DYNAMIC: { + /* scaling arrays of panel width ratios for every widget */ + float ratio, w; + NK_ASSERT(layout->row.ratio); + ratio = (layout->row.ratio[layout->row.index] < 0) ? + layout->row.item_width : layout->row.ratio[layout->row.index]; + + w = (ratio * panel_space); + item_spacing = (float)layout->row.index * spacing.x; + item_offset = layout->row.item_offset; + item_width = w + NK_FRAC(item_offset); + + if (modify) { + layout->row.item_offset += w; + layout->row.filled += ratio; + } + } break; + case NK_LAYOUT_STATIC_FIXED: { + /* non-scaling fixed widgets item width */ + item_width = layout->row.item_width; + item_offset = (float)layout->row.index * item_width; + item_spacing = (float)layout->row.index * spacing.x; + } break; + case NK_LAYOUT_STATIC_ROW: { + /* scaling single ratio widget width */ + item_width = layout->row.item_width; + item_offset = layout->row.item_offset; + item_spacing = (float)layout->row.index * spacing.x; + if (modify) layout->row.item_offset += item_width; + } break; + case NK_LAYOUT_STATIC_FREE: { + /* free widget placing */ + bounds->x = layout->at_x + layout->row.item.x; + bounds->w = layout->row.item.w; + if (((bounds->x + bounds->w) > layout->max_x) && modify) + layout->max_x = (bounds->x + bounds->w); + bounds->x -= (float)*layout->offset_x; + bounds->y = layout->at_y + layout->row.item.y; + bounds->y -= (float)*layout->offset_y; + bounds->h = layout->row.item.h; + return; + } + case NK_LAYOUT_STATIC: { + /* non-scaling array of panel pixel width for every widget */ + item_spacing = (float)layout->row.index * spacing.x; + item_width = layout->row.ratio[layout->row.index]; + item_offset = layout->row.item_offset; + if (modify) layout->row.item_offset += item_width; + } break; + case NK_LAYOUT_TEMPLATE: { + /* stretchy row layout with combined dynamic/static widget width*/ + float w; + NK_ASSERT(layout->row.index < layout->row.columns); + NK_ASSERT(layout->row.index < NK_MAX_LAYOUT_ROW_TEMPLATE_COLUMNS); + w = layout->row.templates[layout->row.index]; + item_offset = layout->row.item_offset; + item_width = w + NK_FRAC(item_offset); + item_spacing = (float)layout->row.index * spacing.x; + if (modify) layout->row.item_offset += w; + } break; + #undef NK_FRAC + default: NK_ASSERT(0); break; + }; + + /* set the bounds of the newly allocated widget */ + bounds->w = item_width; + bounds->h = layout->row.height - spacing.y; + bounds->y = layout->at_y - (float)*layout->offset_y; + bounds->x = layout->at_x + item_offset + item_spacing; + if (((bounds->x + bounds->w) > layout->max_x) && modify) + layout->max_x = bounds->x + bounds->w; + bounds->x -= (float)*layout->offset_x; +} +NK_LIB void +nk_panel_alloc_space(struct nk_rect *bounds, const struct nk_context *ctx) +{ + struct nk_window *win; + struct nk_panel *layout; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return; + + /* check if the end of the row has been hit and begin new row if so */ + win = ctx->current; + layout = win->layout; + if (layout->row.index >= layout->row.columns) + nk_panel_alloc_row(ctx, win); + + /* calculate widget position and size */ + nk_layout_widget_space(bounds, ctx, win, nk_true); + layout->row.index++; +} +NK_LIB void +nk_layout_peek(struct nk_rect *bounds, struct nk_context *ctx) +{ + float y; + int index; + struct nk_window *win; + struct nk_panel *layout; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) { + *bounds = nk_rect(0,0,0,0); + return; + } + + win = ctx->current; + layout = win->layout; + y = layout->at_y; + index = layout->row.index; + if (layout->row.index >= layout->row.columns) { + layout->at_y += layout->row.height; + layout->row.index = 0; + } + nk_layout_widget_space(bounds, ctx, win, nk_false); + if (!layout->row.index) { + bounds->x -= layout->row.item_offset; + } + layout->at_y = y; + layout->row.index = index; +} +NK_API void +nk_spacer(struct nk_context *ctx ) +{ + struct nk_rect dummy_rect = { 0, 0, 0, 0 }; + nk_panel_alloc_space( &dummy_rect, ctx ); +} + + + + +/* =============================================================== + * + * TREE + * + * ===============================================================*/ +NK_INTERN int +nk_tree_state_base(struct nk_context *ctx, enum nk_tree_type type, + struct nk_image *img, const char *title, enum nk_collapse_states *state) +{ + struct nk_window *win; + struct nk_panel *layout; + const struct nk_style *style; + struct nk_command_buffer *out; + const struct nk_input *in; + const struct nk_style_button *button; + enum nk_symbol_type symbol; + float row_height; + + struct nk_vec2 item_spacing; + struct nk_rect header = {0,0,0,0}; + struct nk_rect sym = {0,0,0,0}; + struct nk_text text; + + nk_flags ws = 0; + enum nk_widget_layout_states widget_state; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return 0; + + /* cache some data */ + win = ctx->current; + layout = win->layout; + out = &win->buffer; + style = &ctx->style; + item_spacing = style->window.spacing; + + /* calculate header bounds and draw background */ + row_height = style->font->height + 2 * style->tab.padding.y; + nk_layout_set_min_row_height(ctx, row_height); + nk_layout_row_dynamic(ctx, row_height, 1); + nk_layout_reset_min_row_height(ctx); + + widget_state = nk_widget(&header, ctx); + if (type == NK_TREE_TAB) { + const struct nk_style_item *background = &style->tab.background; + + switch(background->type) { + case NK_STYLE_ITEM_IMAGE: + nk_draw_image(out, header, &background->data.image, nk_white); + break; + case NK_STYLE_ITEM_NINE_SLICE: + nk_draw_nine_slice(out, header, &background->data.slice, nk_white); + break; + case NK_STYLE_ITEM_COLOR: + nk_fill_rect(out, header, 0, style->tab.border_color); + nk_fill_rect(out, nk_shrink_rect(header, style->tab.border), + style->tab.rounding, background->data.color); + break; + } + } else text.background = style->window.background; + + /* update node state */ + in = (!(layout->flags & NK_WINDOW_ROM)) ? &ctx->input: 0; + in = (in && widget_state == NK_WIDGET_VALID) ? &ctx->input : 0; + if (nk_button_behavior(&ws, header, in, NK_BUTTON_DEFAULT)) + *state = (*state == NK_MAXIMIZED) ? NK_MINIMIZED : NK_MAXIMIZED; + + /* select correct button style */ + if (*state == NK_MAXIMIZED) { + symbol = style->tab.sym_maximize; + if (type == NK_TREE_TAB) + button = &style->tab.tab_maximize_button; + else button = &style->tab.node_maximize_button; + } else { + symbol = style->tab.sym_minimize; + if (type == NK_TREE_TAB) + button = &style->tab.tab_minimize_button; + else button = &style->tab.node_minimize_button; + } + + {/* draw triangle button */ + sym.w = sym.h = style->font->height; + sym.y = header.y + style->tab.padding.y; + sym.x = header.x + style->tab.padding.x; + nk_do_button_symbol(&ws, &win->buffer, sym, symbol, NK_BUTTON_DEFAULT, + button, 0, style->font); + + if (img) { + /* draw optional image icon */ + sym.x = sym.x + sym.w + 4 * item_spacing.x; + nk_draw_image(&win->buffer, sym, img, nk_white); + sym.w = style->font->height + style->tab.spacing.x;} + } + + {/* draw label */ + struct nk_rect label; + header.w = NK_MAX(header.w, sym.w + item_spacing.x); + label.x = sym.x + sym.w + item_spacing.x; + label.y = sym.y; + label.w = header.w - (sym.w + item_spacing.y + style->tab.indent); + label.h = style->font->height; + text.text = style->tab.text; + text.padding = nk_vec2(0,0); + nk_widget_text(out, label, title, nk_strlen(title), &text, + NK_TEXT_LEFT, style->font);} + + /* increase x-axis cursor widget position pointer */ + if (*state == NK_MAXIMIZED) { + layout->at_x = header.x + (float)*layout->offset_x + style->tab.indent; + layout->bounds.w = NK_MAX(layout->bounds.w, style->tab.indent); + layout->bounds.w -= (style->tab.indent + style->window.padding.x); + layout->row.tree_depth++; + return nk_true; + } else return nk_false; +} +NK_INTERN int +nk_tree_base(struct nk_context *ctx, enum nk_tree_type type, + struct nk_image *img, const char *title, enum nk_collapse_states initial_state, + const char *hash, int len, int line) +{ + struct nk_window *win = ctx->current; + int title_len = 0; + nk_hash tree_hash = 0; + nk_uint *state = 0; + + /* retrieve tree state from internal widget state tables */ + if (!hash) { + title_len = (int)nk_strlen(title); + tree_hash = nk_murmur_hash(title, (int)title_len, (nk_hash)line); + } else tree_hash = nk_murmur_hash(hash, len, (nk_hash)line); + state = nk_find_value(win, tree_hash); + if (!state) { + state = nk_add_value(ctx, win, tree_hash, 0); + *state = initial_state; + } + return nk_tree_state_base(ctx, type, img, title, (enum nk_collapse_states*)state); +} +NK_API nk_bool +nk_tree_state_push(struct nk_context *ctx, enum nk_tree_type type, + const char *title, enum nk_collapse_states *state) +{ + return nk_tree_state_base(ctx, type, 0, title, state); +} +NK_API nk_bool +nk_tree_state_image_push(struct nk_context *ctx, enum nk_tree_type type, + struct nk_image img, const char *title, enum nk_collapse_states *state) +{ + return nk_tree_state_base(ctx, type, &img, title, state); +} +NK_API void +nk_tree_state_pop(struct nk_context *ctx) +{ + struct nk_window *win = 0; + struct nk_panel *layout = 0; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return; + + win = ctx->current; + layout = win->layout; + layout->at_x -= ctx->style.tab.indent + (float)*layout->offset_x; + layout->bounds.w += ctx->style.tab.indent + ctx->style.window.padding.x; + NK_ASSERT(layout->row.tree_depth); + layout->row.tree_depth--; +} +NK_API nk_bool +nk_tree_push_hashed(struct nk_context *ctx, enum nk_tree_type type, + const char *title, enum nk_collapse_states initial_state, + const char *hash, int len, int line) +{ + return nk_tree_base(ctx, type, 0, title, initial_state, hash, len, line); +} +NK_API nk_bool +nk_tree_image_push_hashed(struct nk_context *ctx, enum nk_tree_type type, + struct nk_image img, const char *title, enum nk_collapse_states initial_state, + const char *hash, int len,int seed) +{ + return nk_tree_base(ctx, type, &img, title, initial_state, hash, len, seed); +} +NK_API void +nk_tree_pop(struct nk_context *ctx) +{ + nk_tree_state_pop(ctx); +} +NK_INTERN int +nk_tree_element_image_push_hashed_base(struct nk_context *ctx, enum nk_tree_type type, + struct nk_image *img, const char *title, int title_len, + enum nk_collapse_states *state, nk_bool *selected) +{ + struct nk_window *win; + struct nk_panel *layout; + const struct nk_style *style; + struct nk_command_buffer *out; + const struct nk_input *in; + const struct nk_style_button *button; + enum nk_symbol_type symbol; + float row_height; + struct nk_vec2 padding; + + int text_len; + float text_width; + + struct nk_vec2 item_spacing; + struct nk_rect header = {0,0,0,0}; + struct nk_rect sym = {0,0,0,0}; + + nk_flags ws = 0; + enum nk_widget_layout_states widget_state; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return 0; + + /* cache some data */ + win = ctx->current; + layout = win->layout; + out = &win->buffer; + style = &ctx->style; + item_spacing = style->window.spacing; + padding = style->selectable.padding; + + /* calculate header bounds and draw background */ + row_height = style->font->height + 2 * style->tab.padding.y; + nk_layout_set_min_row_height(ctx, row_height); + nk_layout_row_dynamic(ctx, row_height, 1); + nk_layout_reset_min_row_height(ctx); + + widget_state = nk_widget(&header, ctx); + if (type == NK_TREE_TAB) { + const struct nk_style_item *background = &style->tab.background; + + switch (background->type) { + case NK_STYLE_ITEM_IMAGE: + nk_draw_image(out, header, &background->data.image, nk_white); + break; + case NK_STYLE_ITEM_NINE_SLICE: + nk_draw_nine_slice(out, header, &background->data.slice, nk_white); + break; + case NK_STYLE_ITEM_COLOR: + nk_fill_rect(out, header, 0, style->tab.border_color); + nk_fill_rect(out, nk_shrink_rect(header, style->tab.border), + style->tab.rounding, background->data.color); + break; + } + } + + in = (!(layout->flags & NK_WINDOW_ROM)) ? &ctx->input: 0; + in = (in && widget_state == NK_WIDGET_VALID) ? &ctx->input : 0; + + /* select correct button style */ + if (*state == NK_MAXIMIZED) { + symbol = style->tab.sym_maximize; + if (type == NK_TREE_TAB) + button = &style->tab.tab_maximize_button; + else button = &style->tab.node_maximize_button; + } else { + symbol = style->tab.sym_minimize; + if (type == NK_TREE_TAB) + button = &style->tab.tab_minimize_button; + else button = &style->tab.node_minimize_button; + } + {/* draw triangle button */ + sym.w = sym.h = style->font->height; + sym.y = header.y + style->tab.padding.y; + sym.x = header.x + style->tab.padding.x; + if (nk_do_button_symbol(&ws, &win->buffer, sym, symbol, NK_BUTTON_DEFAULT, button, in, style->font)) + *state = (*state == NK_MAXIMIZED) ? NK_MINIMIZED : NK_MAXIMIZED;} + + /* draw label */ + {nk_flags dummy = 0; + struct nk_rect label; + /* calculate size of the text and tooltip */ + text_len = nk_strlen(title); + text_width = style->font->width(style->font->userdata, style->font->height, title, text_len); + text_width += (4 * padding.x); + + header.w = NK_MAX(header.w, sym.w + item_spacing.x); + label.x = sym.x + sym.w + item_spacing.x; + label.y = sym.y; + label.w = NK_MIN(header.w - (sym.w + item_spacing.y + style->tab.indent), text_width); + label.h = style->font->height; + + if (img) { + nk_do_selectable_image(&dummy, &win->buffer, label, title, title_len, NK_TEXT_LEFT, + selected, img, &style->selectable, in, style->font); + } else nk_do_selectable(&dummy, &win->buffer, label, title, title_len, NK_TEXT_LEFT, + selected, &style->selectable, in, style->font); + } + /* increase x-axis cursor widget position pointer */ + if (*state == NK_MAXIMIZED) { + layout->at_x = header.x + (float)*layout->offset_x + style->tab.indent; + layout->bounds.w = NK_MAX(layout->bounds.w, style->tab.indent); + layout->bounds.w -= (style->tab.indent + style->window.padding.x); + layout->row.tree_depth++; + return nk_true; + } else return nk_false; +} +NK_INTERN int +nk_tree_element_base(struct nk_context *ctx, enum nk_tree_type type, + struct nk_image *img, const char *title, enum nk_collapse_states initial_state, + nk_bool *selected, const char *hash, int len, int line) +{ + struct nk_window *win = ctx->current; + int title_len = 0; + nk_hash tree_hash = 0; + nk_uint *state = 0; + + /* retrieve tree state from internal widget state tables */ + if (!hash) { + title_len = (int)nk_strlen(title); + tree_hash = nk_murmur_hash(title, (int)title_len, (nk_hash)line); + } else tree_hash = nk_murmur_hash(hash, len, (nk_hash)line); + state = nk_find_value(win, tree_hash); + if (!state) { + state = nk_add_value(ctx, win, tree_hash, 0); + *state = initial_state; + } return nk_tree_element_image_push_hashed_base(ctx, type, img, title, + nk_strlen(title), (enum nk_collapse_states*)state, selected); +} +NK_API nk_bool +nk_tree_element_push_hashed(struct nk_context *ctx, enum nk_tree_type type, + const char *title, enum nk_collapse_states initial_state, + nk_bool *selected, const char *hash, int len, int seed) +{ + return nk_tree_element_base(ctx, type, 0, title, initial_state, selected, hash, len, seed); +} +NK_API nk_bool +nk_tree_element_image_push_hashed(struct nk_context *ctx, enum nk_tree_type type, + struct nk_image img, const char *title, enum nk_collapse_states initial_state, + nk_bool *selected, const char *hash, int len,int seed) +{ + return nk_tree_element_base(ctx, type, &img, title, initial_state, selected, hash, len, seed); +} +NK_API void +nk_tree_element_pop(struct nk_context *ctx) +{ + nk_tree_state_pop(ctx); +} + + + + + +/* =============================================================== + * + * GROUP + * + * ===============================================================*/ +NK_API nk_bool +nk_group_scrolled_offset_begin(struct nk_context *ctx, + nk_uint *x_offset, nk_uint *y_offset, const char *title, nk_flags flags) +{ + struct nk_rect bounds; + struct nk_window panel; + struct nk_window *win; + + win = ctx->current; + nk_panel_alloc_space(&bounds, ctx); + {const struct nk_rect *c = &win->layout->clip; + if (!NK_INTERSECT(c->x, c->y, c->w, c->h, bounds.x, bounds.y, bounds.w, bounds.h) && + !(flags & NK_WINDOW_MOVABLE)) { + return 0; + }} + if (win->flags & NK_WINDOW_ROM) + flags |= NK_WINDOW_ROM; + + /* initialize a fake window to create the panel from */ + nk_zero(&panel, sizeof(panel)); + panel.bounds = bounds; + panel.flags = flags; + panel.scrollbar.x = *x_offset; + panel.scrollbar.y = *y_offset; + panel.buffer = win->buffer; + panel.layout = (struct nk_panel*)nk_create_panel(ctx); + ctx->current = &panel; + nk_panel_begin(ctx, (flags & NK_WINDOW_TITLE) ? title: 0, NK_PANEL_GROUP); + + win->buffer = panel.buffer; + win->buffer.clip = panel.layout->clip; + panel.layout->offset_x = x_offset; + panel.layout->offset_y = y_offset; + panel.layout->parent = win->layout; + win->layout = panel.layout; + + ctx->current = win; + if ((panel.layout->flags & NK_WINDOW_CLOSED) || + (panel.layout->flags & NK_WINDOW_MINIMIZED)) + { + nk_flags f = panel.layout->flags; + nk_group_scrolled_end(ctx); + if (f & NK_WINDOW_CLOSED) + return NK_WINDOW_CLOSED; + if (f & NK_WINDOW_MINIMIZED) + return NK_WINDOW_MINIMIZED; + } + return 1; +} +NK_API void +nk_group_scrolled_end(struct nk_context *ctx) +{ + struct nk_window *win; + struct nk_panel *parent; + struct nk_panel *g; + + struct nk_rect clip; + struct nk_window pan; + struct nk_vec2 panel_padding; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + if (!ctx || !ctx->current) + return; + + /* make sure nk_group_begin was called correctly */ + NK_ASSERT(ctx->current); + win = ctx->current; + NK_ASSERT(win->layout); + g = win->layout; + NK_ASSERT(g->parent); + parent = g->parent; + + /* dummy window */ + nk_zero_struct(pan); + panel_padding = nk_panel_get_padding(&ctx->style, NK_PANEL_GROUP); + pan.bounds.y = g->bounds.y - (g->header_height + g->menu.h); + pan.bounds.x = g->bounds.x - panel_padding.x; + pan.bounds.w = g->bounds.w + 2 * panel_padding.x; + pan.bounds.h = g->bounds.h + g->header_height + g->menu.h; + if (g->flags & NK_WINDOW_BORDER) { + pan.bounds.x -= g->border; + pan.bounds.y -= g->border; + pan.bounds.w += 2*g->border; + pan.bounds.h += 2*g->border; + } + if (!(g->flags & NK_WINDOW_NO_SCROLLBAR)) { + pan.bounds.w += ctx->style.window.scrollbar_size.x; + pan.bounds.h += ctx->style.window.scrollbar_size.y; + } + pan.scrollbar.x = *g->offset_x; + pan.scrollbar.y = *g->offset_y; + pan.flags = g->flags; + pan.buffer = win->buffer; + pan.layout = g; + pan.parent = win; + ctx->current = &pan; + + /* make sure group has correct clipping rectangle */ + nk_unify(&clip, &parent->clip, pan.bounds.x, pan.bounds.y, + pan.bounds.x + pan.bounds.w, pan.bounds.y + pan.bounds.h + panel_padding.x); + nk_push_scissor(&pan.buffer, clip); + nk_end(ctx); + + win->buffer = pan.buffer; + nk_push_scissor(&win->buffer, parent->clip); + ctx->current = win; + win->layout = parent; + g->bounds = pan.bounds; + return; +} +NK_API nk_bool +nk_group_scrolled_begin(struct nk_context *ctx, + struct nk_scroll *scroll, const char *title, nk_flags flags) +{ + return nk_group_scrolled_offset_begin(ctx, &scroll->x, &scroll->y, title, flags); +} +NK_API nk_bool +nk_group_begin_titled(struct nk_context *ctx, const char *id, + const char *title, nk_flags flags) +{ + int id_len; + nk_hash id_hash; + struct nk_window *win; + nk_uint *x_offset; + nk_uint *y_offset; + + NK_ASSERT(ctx); + NK_ASSERT(id); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout || !id) + return 0; + + /* find persistent group scrollbar value */ + win = ctx->current; + id_len = (int)nk_strlen(id); + id_hash = nk_murmur_hash(id, (int)id_len, NK_PANEL_GROUP); + x_offset = nk_find_value(win, id_hash); + if (!x_offset) { + x_offset = nk_add_value(ctx, win, id_hash, 0); + y_offset = nk_add_value(ctx, win, id_hash+1, 0); + + NK_ASSERT(x_offset); + NK_ASSERT(y_offset); + if (!x_offset || !y_offset) return 0; + *x_offset = *y_offset = 0; + } else y_offset = nk_find_value(win, id_hash+1); + return nk_group_scrolled_offset_begin(ctx, x_offset, y_offset, title, flags); +} +NK_API nk_bool +nk_group_begin(struct nk_context *ctx, const char *title, nk_flags flags) +{ + return nk_group_begin_titled(ctx, title, title, flags); +} +NK_API void +nk_group_end(struct nk_context *ctx) +{ + nk_group_scrolled_end(ctx); +} +NK_API void +nk_group_get_scroll(struct nk_context *ctx, const char *id, nk_uint *x_offset, nk_uint *y_offset) +{ + int id_len; + nk_hash id_hash; + struct nk_window *win; + nk_uint *x_offset_ptr; + nk_uint *y_offset_ptr; + + NK_ASSERT(ctx); + NK_ASSERT(id); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout || !id) + return; + + /* find persistent group scrollbar value */ + win = ctx->current; + id_len = (int)nk_strlen(id); + id_hash = nk_murmur_hash(id, (int)id_len, NK_PANEL_GROUP); + x_offset_ptr = nk_find_value(win, id_hash); + if (!x_offset_ptr) { + x_offset_ptr = nk_add_value(ctx, win, id_hash, 0); + y_offset_ptr = nk_add_value(ctx, win, id_hash+1, 0); + + NK_ASSERT(x_offset_ptr); + NK_ASSERT(y_offset_ptr); + if (!x_offset_ptr || !y_offset_ptr) return; + *x_offset_ptr = *y_offset_ptr = 0; + } else y_offset_ptr = nk_find_value(win, id_hash+1); + if (x_offset) + *x_offset = *x_offset_ptr; + if (y_offset) + *y_offset = *y_offset_ptr; +} +NK_API void +nk_group_set_scroll(struct nk_context *ctx, const char *id, nk_uint x_offset, nk_uint y_offset) +{ + int id_len; + nk_hash id_hash; + struct nk_window *win; + nk_uint *x_offset_ptr; + nk_uint *y_offset_ptr; + + NK_ASSERT(ctx); + NK_ASSERT(id); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout || !id) + return; + + /* find persistent group scrollbar value */ + win = ctx->current; + id_len = (int)nk_strlen(id); + id_hash = nk_murmur_hash(id, (int)id_len, NK_PANEL_GROUP); + x_offset_ptr = nk_find_value(win, id_hash); + if (!x_offset_ptr) { + x_offset_ptr = nk_add_value(ctx, win, id_hash, 0); + y_offset_ptr = nk_add_value(ctx, win, id_hash+1, 0); + + NK_ASSERT(x_offset_ptr); + NK_ASSERT(y_offset_ptr); + if (!x_offset_ptr || !y_offset_ptr) return; + *x_offset_ptr = *y_offset_ptr = 0; + } else y_offset_ptr = nk_find_value(win, id_hash+1); + *x_offset_ptr = x_offset; + *y_offset_ptr = y_offset; +} + + + + +/* =============================================================== + * + * LIST VIEW + * + * ===============================================================*/ +NK_API nk_bool +nk_list_view_begin(struct nk_context *ctx, struct nk_list_view *view, + const char *title, nk_flags flags, int row_height, int row_count) +{ + int title_len; + nk_hash title_hash; + nk_uint *x_offset; + nk_uint *y_offset; + + int result; + struct nk_window *win; + struct nk_panel *layout; + const struct nk_style *style; + struct nk_vec2 item_spacing; + + NK_ASSERT(ctx); + NK_ASSERT(view); + NK_ASSERT(title); + if (!ctx || !view || !title) return 0; + + win = ctx->current; + style = &ctx->style; + item_spacing = style->window.spacing; + row_height += NK_MAX(0, (int)item_spacing.y); + + /* find persistent list view scrollbar offset */ + title_len = (int)nk_strlen(title); + title_hash = nk_murmur_hash(title, (int)title_len, NK_PANEL_GROUP); + x_offset = nk_find_value(win, title_hash); + if (!x_offset) { + x_offset = nk_add_value(ctx, win, title_hash, 0); + y_offset = nk_add_value(ctx, win, title_hash+1, 0); + + NK_ASSERT(x_offset); + NK_ASSERT(y_offset); + if (!x_offset || !y_offset) return 0; + *x_offset = *y_offset = 0; + } else y_offset = nk_find_value(win, title_hash+1); + view->scroll_value = *y_offset; + view->scroll_pointer = y_offset; + + *y_offset = 0; + result = nk_group_scrolled_offset_begin(ctx, x_offset, y_offset, title, flags); + win = ctx->current; + layout = win->layout; + + view->total_height = row_height * NK_MAX(row_count,1); + view->begin = (int)NK_MAX(((float)view->scroll_value / (float)row_height), 0.0f); + view->count = (int)NK_MAX(nk_iceilf((layout->clip.h)/(float)row_height),0); + view->count = NK_MIN(view->count, row_count - view->begin); + view->end = view->begin + view->count; + view->ctx = ctx; + return result; +} +NK_API void +nk_list_view_end(struct nk_list_view *view) +{ + struct nk_context *ctx; + struct nk_window *win; + struct nk_panel *layout; + + NK_ASSERT(view); + NK_ASSERT(view->ctx); + NK_ASSERT(view->scroll_pointer); + if (!view || !view->ctx) return; + + ctx = view->ctx; + win = ctx->current; + layout = win->layout; + layout->at_y = layout->bounds.y + (float)view->total_height; + *view->scroll_pointer = *view->scroll_pointer + view->scroll_value; + nk_group_end(view->ctx); +} + + + + + +/* =============================================================== + * + * WIDGET + * + * ===============================================================*/ +NK_API struct nk_rect +nk_widget_bounds(struct nk_context *ctx) +{ + struct nk_rect bounds; + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + if (!ctx || !ctx->current) + return nk_rect(0,0,0,0); + nk_layout_peek(&bounds, ctx); + return bounds; +} +NK_API struct nk_vec2 +nk_widget_position(struct nk_context *ctx) +{ + struct nk_rect bounds; + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + if (!ctx || !ctx->current) + return nk_vec2(0,0); + + nk_layout_peek(&bounds, ctx); + return nk_vec2(bounds.x, bounds.y); +} +NK_API struct nk_vec2 +nk_widget_size(struct nk_context *ctx) +{ + struct nk_rect bounds; + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + if (!ctx || !ctx->current) + return nk_vec2(0,0); + + nk_layout_peek(&bounds, ctx); + return nk_vec2(bounds.w, bounds.h); +} +NK_API float +nk_widget_width(struct nk_context *ctx) +{ + struct nk_rect bounds; + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + if (!ctx || !ctx->current) + return 0; + + nk_layout_peek(&bounds, ctx); + return bounds.w; +} +NK_API float +nk_widget_height(struct nk_context *ctx) +{ + struct nk_rect bounds; + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + if (!ctx || !ctx->current) + return 0; + + nk_layout_peek(&bounds, ctx); + return bounds.h; +} +NK_API nk_bool +nk_widget_is_hovered(struct nk_context *ctx) +{ + struct nk_rect c, v; + struct nk_rect bounds; + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + if (!ctx || !ctx->current || ctx->active != ctx->current) + return 0; + + c = ctx->current->layout->clip; + c.x = (float)((int)c.x); + c.y = (float)((int)c.y); + c.w = (float)((int)c.w); + c.h = (float)((int)c.h); + + nk_layout_peek(&bounds, ctx); + nk_unify(&v, &c, bounds.x, bounds.y, bounds.x + bounds.w, bounds.y + bounds.h); + if (!NK_INTERSECT(c.x, c.y, c.w, c.h, bounds.x, bounds.y, bounds.w, bounds.h)) + return 0; + return nk_input_is_mouse_hovering_rect(&ctx->input, bounds); +} +NK_API nk_bool +nk_widget_is_mouse_clicked(struct nk_context *ctx, enum nk_buttons btn) +{ + struct nk_rect c, v; + struct nk_rect bounds; + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + if (!ctx || !ctx->current || ctx->active != ctx->current) + return 0; + + c = ctx->current->layout->clip; + c.x = (float)((int)c.x); + c.y = (float)((int)c.y); + c.w = (float)((int)c.w); + c.h = (float)((int)c.h); + + nk_layout_peek(&bounds, ctx); + nk_unify(&v, &c, bounds.x, bounds.y, bounds.x + bounds.w, bounds.y + bounds.h); + if (!NK_INTERSECT(c.x, c.y, c.w, c.h, bounds.x, bounds.y, bounds.w, bounds.h)) + return 0; + return nk_input_mouse_clicked(&ctx->input, btn, bounds); +} +NK_API nk_bool +nk_widget_has_mouse_click_down(struct nk_context *ctx, enum nk_buttons btn, nk_bool down) +{ + struct nk_rect c, v; + struct nk_rect bounds; + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + if (!ctx || !ctx->current || ctx->active != ctx->current) + return 0; + + c = ctx->current->layout->clip; + c.x = (float)((int)c.x); + c.y = (float)((int)c.y); + c.w = (float)((int)c.w); + c.h = (float)((int)c.h); + + nk_layout_peek(&bounds, ctx); + nk_unify(&v, &c, bounds.x, bounds.y, bounds.x + bounds.w, bounds.y + bounds.h); + if (!NK_INTERSECT(c.x, c.y, c.w, c.h, bounds.x, bounds.y, bounds.w, bounds.h)) + return 0; + return nk_input_has_mouse_click_down_in_rect(&ctx->input, btn, bounds, down); +} +NK_API enum nk_widget_layout_states +nk_widget(struct nk_rect *bounds, const struct nk_context *ctx) +{ + struct nk_rect c, v; + struct nk_window *win; + struct nk_panel *layout; + const struct nk_input *in; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return NK_WIDGET_INVALID; + + /* allocate space and check if the widget needs to be updated and drawn */ + nk_panel_alloc_space(bounds, ctx); + win = ctx->current; + layout = win->layout; + in = &ctx->input; + c = layout->clip; + + /* if one of these triggers you forgot to add an `if` condition around either + a window, group, popup, combobox or contextual menu `begin` and `end` block. + Example: + if (nk_begin(...) {...} nk_end(...); or + if (nk_group_begin(...) { nk_group_end(...);} */ + NK_ASSERT(!(layout->flags & NK_WINDOW_MINIMIZED)); + NK_ASSERT(!(layout->flags & NK_WINDOW_HIDDEN)); + NK_ASSERT(!(layout->flags & NK_WINDOW_CLOSED)); + + /* need to convert to int here to remove floating point errors */ + bounds->x = (float)((int)bounds->x); + bounds->y = (float)((int)bounds->y); + bounds->w = (float)((int)bounds->w); + bounds->h = (float)((int)bounds->h); + + c.x = (float)((int)c.x); + c.y = (float)((int)c.y); + c.w = (float)((int)c.w); + c.h = (float)((int)c.h); + + nk_unify(&v, &c, bounds->x, bounds->y, bounds->x + bounds->w, bounds->y + bounds->h); + if (!NK_INTERSECT(c.x, c.y, c.w, c.h, bounds->x, bounds->y, bounds->w, bounds->h)) + return NK_WIDGET_INVALID; + if (!NK_INBOX(in->mouse.pos.x, in->mouse.pos.y, v.x, v.y, v.w, v.h)) + return NK_WIDGET_ROM; + return NK_WIDGET_VALID; +} +NK_API enum nk_widget_layout_states +nk_widget_fitting(struct nk_rect *bounds, struct nk_context *ctx, + struct nk_vec2 item_padding) +{ + /* update the bounds to stand without padding */ + enum nk_widget_layout_states state; + NK_UNUSED(item_padding); + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return NK_WIDGET_INVALID; + + state = nk_widget(bounds, ctx); + return state; +} +NK_API void +nk_spacing(struct nk_context *ctx, int cols) +{ + struct nk_window *win; + struct nk_panel *layout; + struct nk_rect none; + int i, index, rows; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return; + + /* spacing over row boundaries */ + win = ctx->current; + layout = win->layout; + index = (layout->row.index + cols) % layout->row.columns; + rows = (layout->row.index + cols) / layout->row.columns; + if (rows) { + for (i = 0; i < rows; ++i) + nk_panel_alloc_row(ctx, win); + cols = index; + } + /* non table layout need to allocate space */ + if (layout->row.type != NK_LAYOUT_DYNAMIC_FIXED && + layout->row.type != NK_LAYOUT_STATIC_FIXED) { + for (i = 0; i < cols; ++i) + nk_panel_alloc_space(&none, ctx); + } layout->row.index = index; +} + + + + + +/* =============================================================== + * + * TEXT + * + * ===============================================================*/ +NK_LIB void +nk_widget_text(struct nk_command_buffer *o, struct nk_rect b, + const char *string, int len, const struct nk_text *t, + nk_flags a, const struct nk_user_font *f) +{ + struct nk_rect label; + float text_width; + + NK_ASSERT(o); + NK_ASSERT(t); + if (!o || !t) return; + + b.h = NK_MAX(b.h, 2 * t->padding.y); + label.x = 0; label.w = 0; + label.y = b.y + t->padding.y; + label.h = NK_MIN(f->height, b.h - 2 * t->padding.y); + + text_width = f->width(f->userdata, f->height, (const char*)string, len); + text_width += (2.0f * t->padding.x); + + /* align in x-axis */ + if (a & NK_TEXT_ALIGN_LEFT) { + label.x = b.x + t->padding.x; + label.w = NK_MAX(0, b.w - 2 * t->padding.x); + } else if (a & NK_TEXT_ALIGN_CENTERED) { + label.w = NK_MAX(1, 2 * t->padding.x + (float)text_width); + label.x = (b.x + t->padding.x + ((b.w - 2 * t->padding.x) - label.w) / 2); + label.x = NK_MAX(b.x + t->padding.x, label.x); + label.w = NK_MIN(b.x + b.w, label.x + label.w); + if (label.w >= label.x) label.w -= label.x; + } else if (a & NK_TEXT_ALIGN_RIGHT) { + label.x = NK_MAX(b.x + t->padding.x, (b.x + b.w) - (2 * t->padding.x + (float)text_width)); + label.w = (float)text_width + 2 * t->padding.x; + } else return; + + /* align in y-axis */ + if (a & NK_TEXT_ALIGN_MIDDLE) { + label.y = b.y + b.h/2.0f - (float)f->height/2.0f; + label.h = NK_MAX(b.h/2.0f, b.h - (b.h/2.0f + f->height/2.0f)); + } else if (a & NK_TEXT_ALIGN_BOTTOM) { + label.y = b.y + b.h - f->height; + label.h = f->height; + } + nk_draw_text(o, label, (const char*)string, len, f, t->background, t->text); +} +NK_LIB void +nk_widget_text_wrap(struct nk_command_buffer *o, struct nk_rect b, + const char *string, int len, const struct nk_text *t, + const struct nk_user_font *f) +{ + float width; + int glyphs = 0; + int fitting = 0; + int done = 0; + struct nk_rect line; + struct nk_text text; + NK_INTERN nk_rune seperator[] = {' '}; + + NK_ASSERT(o); + NK_ASSERT(t); + if (!o || !t) return; + + text.padding = nk_vec2(0,0); + text.background = t->background; + text.text = t->text; + + b.w = NK_MAX(b.w, 2 * t->padding.x); + b.h = NK_MAX(b.h, 2 * t->padding.y); + b.h = b.h - 2 * t->padding.y; + + line.x = b.x + t->padding.x; + line.y = b.y + t->padding.y; + line.w = b.w - 2 * t->padding.x; + line.h = 2 * t->padding.y + f->height; + + fitting = nk_text_clamp(f, string, len, line.w, &glyphs, &width, seperator,NK_LEN(seperator)); + while (done < len) { + if (!fitting || line.y + line.h >= (b.y + b.h)) break; + nk_widget_text(o, line, &string[done], fitting, &text, NK_TEXT_LEFT, f); + done += fitting; + line.y += f->height + 2 * t->padding.y; + fitting = nk_text_clamp(f, &string[done], len - done, line.w, &glyphs, &width, seperator,NK_LEN(seperator)); + } +} +NK_API void +nk_text_colored(struct nk_context *ctx, const char *str, int len, + nk_flags alignment, struct nk_color color) +{ + struct nk_window *win; + const struct nk_style *style; + + struct nk_vec2 item_padding; + struct nk_rect bounds; + struct nk_text text; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) return; + + win = ctx->current; + style = &ctx->style; + nk_panel_alloc_space(&bounds, ctx); + item_padding = style->text.padding; + + text.padding.x = item_padding.x; + text.padding.y = item_padding.y; + text.background = style->window.background; + text.text = color; + nk_widget_text(&win->buffer, bounds, str, len, &text, alignment, style->font); +} +NK_API void +nk_text_wrap_colored(struct nk_context *ctx, const char *str, + int len, struct nk_color color) +{ + struct nk_window *win; + const struct nk_style *style; + + struct nk_vec2 item_padding; + struct nk_rect bounds; + struct nk_text text; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) return; + + win = ctx->current; + style = &ctx->style; + nk_panel_alloc_space(&bounds, ctx); + item_padding = style->text.padding; + + text.padding.x = item_padding.x; + text.padding.y = item_padding.y; + text.background = style->window.background; + text.text = color; + nk_widget_text_wrap(&win->buffer, bounds, str, len, &text, style->font); +} +#ifdef NK_INCLUDE_STANDARD_VARARGS +NK_API void +nk_labelf_colored(struct nk_context *ctx, nk_flags flags, + struct nk_color color, const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + nk_labelfv_colored(ctx, flags, color, fmt, args); + va_end(args); +} +NK_API void +nk_labelf_colored_wrap(struct nk_context *ctx, struct nk_color color, + const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + nk_labelfv_colored_wrap(ctx, color, fmt, args); + va_end(args); +} +NK_API void +nk_labelf(struct nk_context *ctx, nk_flags flags, const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + nk_labelfv(ctx, flags, fmt, args); + va_end(args); +} +NK_API void +nk_labelf_wrap(struct nk_context *ctx, const char *fmt,...) +{ + va_list args; + va_start(args, fmt); + nk_labelfv_wrap(ctx, fmt, args); + va_end(args); +} +NK_API void +nk_labelfv_colored(struct nk_context *ctx, nk_flags flags, + struct nk_color color, const char *fmt, va_list args) +{ + char buf[256]; + nk_strfmt(buf, NK_LEN(buf), fmt, args); + nk_label_colored(ctx, buf, flags, color); +} + +NK_API void +nk_labelfv_colored_wrap(struct nk_context *ctx, struct nk_color color, + const char *fmt, va_list args) +{ + char buf[256]; + nk_strfmt(buf, NK_LEN(buf), fmt, args); + nk_label_colored_wrap(ctx, buf, color); +} + +NK_API void +nk_labelfv(struct nk_context *ctx, nk_flags flags, const char *fmt, va_list args) +{ + char buf[256]; + nk_strfmt(buf, NK_LEN(buf), fmt, args); + nk_label(ctx, buf, flags); +} + +NK_API void +nk_labelfv_wrap(struct nk_context *ctx, const char *fmt, va_list args) +{ + char buf[256]; + nk_strfmt(buf, NK_LEN(buf), fmt, args); + nk_label_wrap(ctx, buf); +} + +NK_API void +nk_value_bool(struct nk_context *ctx, const char *prefix, int value) +{ + nk_labelf(ctx, NK_TEXT_LEFT, "%s: %s", prefix, ((value) ? "true": "false")); +} +NK_API void +nk_value_int(struct nk_context *ctx, const char *prefix, int value) +{ + nk_labelf(ctx, NK_TEXT_LEFT, "%s: %d", prefix, value); +} +NK_API void +nk_value_uint(struct nk_context *ctx, const char *prefix, unsigned int value) +{ + nk_labelf(ctx, NK_TEXT_LEFT, "%s: %u", prefix, value); +} +NK_API void +nk_value_float(struct nk_context *ctx, const char *prefix, float value) +{ + double double_value = (double)value; + nk_labelf(ctx, NK_TEXT_LEFT, "%s: %.3f", prefix, double_value); +} +NK_API void +nk_value_color_byte(struct nk_context *ctx, const char *p, struct nk_color c) +{ + nk_labelf(ctx, NK_TEXT_LEFT, "%s: (%d, %d, %d, %d)", p, c.r, c.g, c.b, c.a); +} +NK_API void +nk_value_color_float(struct nk_context *ctx, const char *p, struct nk_color color) +{ + double c[4]; nk_color_dv(c, color); + nk_labelf(ctx, NK_TEXT_LEFT, "%s: (%.2f, %.2f, %.2f, %.2f)", + p, c[0], c[1], c[2], c[3]); +} +NK_API void +nk_value_color_hex(struct nk_context *ctx, const char *prefix, struct nk_color color) +{ + char hex[16]; + nk_color_hex_rgba(hex, color); + nk_labelf(ctx, NK_TEXT_LEFT, "%s: %s", prefix, hex); +} +#endif +NK_API void +nk_text(struct nk_context *ctx, const char *str, int len, nk_flags alignment) +{ + NK_ASSERT(ctx); + if (!ctx) return; + nk_text_colored(ctx, str, len, alignment, ctx->style.text.color); +} +NK_API void +nk_text_wrap(struct nk_context *ctx, const char *str, int len) +{ + NK_ASSERT(ctx); + if (!ctx) return; + nk_text_wrap_colored(ctx, str, len, ctx->style.text.color); +} +NK_API void +nk_label(struct nk_context *ctx, const char *str, nk_flags alignment) +{ + nk_text(ctx, str, nk_strlen(str), alignment); +} +NK_API void +nk_label_colored(struct nk_context *ctx, const char *str, nk_flags align, + struct nk_color color) +{ + nk_text_colored(ctx, str, nk_strlen(str), align, color); +} +NK_API void +nk_label_wrap(struct nk_context *ctx, const char *str) +{ + nk_text_wrap(ctx, str, nk_strlen(str)); +} +NK_API void +nk_label_colored_wrap(struct nk_context *ctx, const char *str, struct nk_color color) +{ + nk_text_wrap_colored(ctx, str, nk_strlen(str), color); +} + + + + + +/* =============================================================== + * + * IMAGE + * + * ===============================================================*/ +NK_API nk_handle +nk_handle_ptr(void *ptr) +{ + nk_handle handle = {0}; + handle.ptr = ptr; + return handle; +} +NK_API nk_handle +nk_handle_id(int id) +{ + nk_handle handle; + nk_zero_struct(handle); + handle.id = id; + return handle; +} +NK_API struct nk_image +nk_subimage_ptr(void *ptr, nk_ushort w, nk_ushort h, struct nk_rect r) +{ + struct nk_image s; + nk_zero(&s, sizeof(s)); + s.handle.ptr = ptr; + s.w = w; s.h = h; + s.region[0] = (nk_ushort)r.x; + s.region[1] = (nk_ushort)r.y; + s.region[2] = (nk_ushort)r.w; + s.region[3] = (nk_ushort)r.h; + return s; +} +NK_API struct nk_image +nk_subimage_id(int id, nk_ushort w, nk_ushort h, struct nk_rect r) +{ + struct nk_image s; + nk_zero(&s, sizeof(s)); + s.handle.id = id; + s.w = w; s.h = h; + s.region[0] = (nk_ushort)r.x; + s.region[1] = (nk_ushort)r.y; + s.region[2] = (nk_ushort)r.w; + s.region[3] = (nk_ushort)r.h; + return s; +} +NK_API struct nk_image +nk_subimage_handle(nk_handle handle, nk_ushort w, nk_ushort h, struct nk_rect r) +{ + struct nk_image s; + nk_zero(&s, sizeof(s)); + s.handle = handle; + s.w = w; s.h = h; + s.region[0] = (nk_ushort)r.x; + s.region[1] = (nk_ushort)r.y; + s.region[2] = (nk_ushort)r.w; + s.region[3] = (nk_ushort)r.h; + return s; +} +NK_API struct nk_image +nk_image_handle(nk_handle handle) +{ + struct nk_image s; + nk_zero(&s, sizeof(s)); + s.handle = handle; + s.w = 0; s.h = 0; + s.region[0] = 0; + s.region[1] = 0; + s.region[2] = 0; + s.region[3] = 0; + return s; +} +NK_API struct nk_image +nk_image_ptr(void *ptr) +{ + struct nk_image s; + nk_zero(&s, sizeof(s)); + NK_ASSERT(ptr); + s.handle.ptr = ptr; + s.w = 0; s.h = 0; + s.region[0] = 0; + s.region[1] = 0; + s.region[2] = 0; + s.region[3] = 0; + return s; +} +NK_API struct nk_image +nk_image_id(int id) +{ + struct nk_image s; + nk_zero(&s, sizeof(s)); + s.handle.id = id; + s.w = 0; s.h = 0; + s.region[0] = 0; + s.region[1] = 0; + s.region[2] = 0; + s.region[3] = 0; + return s; +} +NK_API nk_bool +nk_image_is_subimage(const struct nk_image* img) +{ + NK_ASSERT(img); + return !(img->w == 0 && img->h == 0); +} +NK_API void +nk_image(struct nk_context *ctx, struct nk_image img) +{ + struct nk_window *win; + struct nk_rect bounds; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) return; + + win = ctx->current; + if (!nk_widget(&bounds, ctx)) return; + nk_draw_image(&win->buffer, bounds, &img, nk_white); +} +NK_API void +nk_image_color(struct nk_context *ctx, struct nk_image img, struct nk_color col) +{ + struct nk_window *win; + struct nk_rect bounds; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) return; + + win = ctx->current; + if (!nk_widget(&bounds, ctx)) return; + nk_draw_image(&win->buffer, bounds, &img, col); +} + + + + + +/* =============================================================== + * + * 9-SLICE + * + * ===============================================================*/ +NK_API struct nk_nine_slice +nk_sub9slice_ptr(void *ptr, nk_ushort w, nk_ushort h, struct nk_rect rgn, nk_ushort l, nk_ushort t, nk_ushort r, nk_ushort b) +{ + struct nk_nine_slice s; + struct nk_image *i = &s.img; + nk_zero(&s, sizeof(s)); + i->handle.ptr = ptr; + i->w = w; i->h = h; + i->region[0] = (nk_ushort)rgn.x; + i->region[1] = (nk_ushort)rgn.y; + i->region[2] = (nk_ushort)rgn.w; + i->region[3] = (nk_ushort)rgn.h; + s.l = l; s.t = t; s.r = r; s.b = b; + return s; +} +NK_API struct nk_nine_slice +nk_sub9slice_id(int id, nk_ushort w, nk_ushort h, struct nk_rect rgn, nk_ushort l, nk_ushort t, nk_ushort r, nk_ushort b) +{ + struct nk_nine_slice s; + struct nk_image *i = &s.img; + nk_zero(&s, sizeof(s)); + i->handle.id = id; + i->w = w; i->h = h; + i->region[0] = (nk_ushort)rgn.x; + i->region[1] = (nk_ushort)rgn.y; + i->region[2] = (nk_ushort)rgn.w; + i->region[3] = (nk_ushort)rgn.h; + s.l = l; s.t = t; s.r = r; s.b = b; + return s; +} +NK_API struct nk_nine_slice +nk_sub9slice_handle(nk_handle handle, nk_ushort w, nk_ushort h, struct nk_rect rgn, nk_ushort l, nk_ushort t, nk_ushort r, nk_ushort b) +{ + struct nk_nine_slice s; + struct nk_image *i = &s.img; + nk_zero(&s, sizeof(s)); + i->handle = handle; + i->w = w; i->h = h; + i->region[0] = (nk_ushort)rgn.x; + i->region[1] = (nk_ushort)rgn.y; + i->region[2] = (nk_ushort)rgn.w; + i->region[3] = (nk_ushort)rgn.h; + s.l = l; s.t = t; s.r = r; s.b = b; + return s; +} +NK_API struct nk_nine_slice +nk_nine_slice_handle(nk_handle handle, nk_ushort l, nk_ushort t, nk_ushort r, nk_ushort b) +{ + struct nk_nine_slice s; + struct nk_image *i = &s.img; + nk_zero(&s, sizeof(s)); + i->handle = handle; + i->w = 0; i->h = 0; + i->region[0] = 0; + i->region[1] = 0; + i->region[2] = 0; + i->region[3] = 0; + s.l = l; s.t = t; s.r = r; s.b = b; + return s; +} +NK_API struct nk_nine_slice +nk_nine_slice_ptr(void *ptr, nk_ushort l, nk_ushort t, nk_ushort r, nk_ushort b) +{ + struct nk_nine_slice s; + struct nk_image *i = &s.img; + nk_zero(&s, sizeof(s)); + NK_ASSERT(ptr); + i->handle.ptr = ptr; + i->w = 0; i->h = 0; + i->region[0] = 0; + i->region[1] = 0; + i->region[2] = 0; + i->region[3] = 0; + s.l = l; s.t = t; s.r = r; s.b = b; + return s; +} +NK_API struct nk_nine_slice +nk_nine_slice_id(int id, nk_ushort l, nk_ushort t, nk_ushort r, nk_ushort b) +{ + struct nk_nine_slice s; + struct nk_image *i = &s.img; + nk_zero(&s, sizeof(s)); + i->handle.id = id; + i->w = 0; i->h = 0; + i->region[0] = 0; + i->region[1] = 0; + i->region[2] = 0; + i->region[3] = 0; + s.l = l; s.t = t; s.r = r; s.b = b; + return s; +} +NK_API int +nk_nine_slice_is_sub9slice(const struct nk_nine_slice* slice) +{ + NK_ASSERT(slice); + return !(slice->img.w == 0 && slice->img.h == 0); +} + + + + + +/* ============================================================== + * + * BUTTON + * + * ===============================================================*/ +NK_LIB void +nk_draw_symbol(struct nk_command_buffer *out, enum nk_symbol_type type, + struct nk_rect content, struct nk_color background, struct nk_color foreground, + float border_width, const struct nk_user_font *font) +{ + switch (type) { + case NK_SYMBOL_X: + case NK_SYMBOL_UNDERSCORE: + case NK_SYMBOL_PLUS: + case NK_SYMBOL_MINUS: { + /* single character text symbol */ + const char *X = (type == NK_SYMBOL_X) ? "x": + (type == NK_SYMBOL_UNDERSCORE) ? "_": + (type == NK_SYMBOL_PLUS) ? "+": "-"; + struct nk_text text; + text.padding = nk_vec2(0,0); + text.background = background; + text.text = foreground; + nk_widget_text(out, content, X, 1, &text, NK_TEXT_CENTERED, font); + } break; + case NK_SYMBOL_CIRCLE_SOLID: + case NK_SYMBOL_CIRCLE_OUTLINE: + case NK_SYMBOL_RECT_SOLID: + case NK_SYMBOL_RECT_OUTLINE: { + /* simple empty/filled shapes */ + if (type == NK_SYMBOL_RECT_SOLID || type == NK_SYMBOL_RECT_OUTLINE) { + nk_fill_rect(out, content, 0, foreground); + if (type == NK_SYMBOL_RECT_OUTLINE) + nk_fill_rect(out, nk_shrink_rect(content, border_width), 0, background); + } else { + nk_fill_circle(out, content, foreground); + if (type == NK_SYMBOL_CIRCLE_OUTLINE) + nk_fill_circle(out, nk_shrink_rect(content, 1), background); + } + } break; + case NK_SYMBOL_TRIANGLE_UP: + case NK_SYMBOL_TRIANGLE_DOWN: + case NK_SYMBOL_TRIANGLE_LEFT: + case NK_SYMBOL_TRIANGLE_RIGHT: { + enum nk_heading heading; + struct nk_vec2 points[3]; + heading = (type == NK_SYMBOL_TRIANGLE_RIGHT) ? NK_RIGHT : + (type == NK_SYMBOL_TRIANGLE_LEFT) ? NK_LEFT: + (type == NK_SYMBOL_TRIANGLE_UP) ? NK_UP: NK_DOWN; + nk_triangle_from_direction(points, content, 0, 0, heading); + nk_fill_triangle(out, points[0].x, points[0].y, points[1].x, points[1].y, + points[2].x, points[2].y, foreground); + } break; + default: + case NK_SYMBOL_NONE: + case NK_SYMBOL_MAX: break; + } +} +NK_LIB nk_bool +nk_button_behavior(nk_flags *state, struct nk_rect r, + const struct nk_input *i, enum nk_button_behavior behavior) +{ + int ret = 0; + nk_widget_state_reset(state); + if (!i) return 0; + if (nk_input_is_mouse_hovering_rect(i, r)) { + *state = NK_WIDGET_STATE_HOVERED; + if (nk_input_is_mouse_down(i, NK_BUTTON_LEFT)) + *state = NK_WIDGET_STATE_ACTIVE; + if (nk_input_has_mouse_click_in_button_rect(i, NK_BUTTON_LEFT, r)) { + ret = (behavior != NK_BUTTON_DEFAULT) ? + nk_input_is_mouse_down(i, NK_BUTTON_LEFT): +#ifdef NK_BUTTON_TRIGGER_ON_RELEASE + nk_input_is_mouse_released(i, NK_BUTTON_LEFT); +#else + nk_input_is_mouse_pressed(i, NK_BUTTON_LEFT); +#endif + } + } + if (*state & NK_WIDGET_STATE_HOVER && !nk_input_is_mouse_prev_hovering_rect(i, r)) + *state |= NK_WIDGET_STATE_ENTERED; + else if (nk_input_is_mouse_prev_hovering_rect(i, r)) + *state |= NK_WIDGET_STATE_LEFT; + return ret; +} +NK_LIB const struct nk_style_item* +nk_draw_button(struct nk_command_buffer *out, + const struct nk_rect *bounds, nk_flags state, + const struct nk_style_button *style) +{ + const struct nk_style_item *background; + if (state & NK_WIDGET_STATE_HOVER) + background = &style->hover; + else if (state & NK_WIDGET_STATE_ACTIVED) + background = &style->active; + else background = &style->normal; + + switch(background->type) { + case NK_STYLE_ITEM_IMAGE: + nk_draw_image(out, *bounds, &background->data.image, nk_white); + break; + case NK_STYLE_ITEM_NINE_SLICE: + nk_draw_nine_slice(out, *bounds, &background->data.slice, nk_white); + break; + case NK_STYLE_ITEM_COLOR: + nk_fill_rect(out, *bounds, style->rounding, background->data.color); + nk_stroke_rect(out, *bounds, style->rounding, style->border, style->border_color); + break; + } + return background; +} +NK_LIB nk_bool +nk_do_button(nk_flags *state, struct nk_command_buffer *out, struct nk_rect r, + const struct nk_style_button *style, const struct nk_input *in, + enum nk_button_behavior behavior, struct nk_rect *content) +{ + struct nk_rect bounds; + NK_ASSERT(style); + NK_ASSERT(state); + NK_ASSERT(out); + if (!out || !style) + return nk_false; + + /* calculate button content space */ + content->x = r.x + style->padding.x + style->border + style->rounding; + content->y = r.y + style->padding.y + style->border + style->rounding; + content->w = r.w - (2 * style->padding.x + style->border + style->rounding*2); + content->h = r.h - (2 * style->padding.y + style->border + style->rounding*2); + + /* execute button behavior */ + bounds.x = r.x - style->touch_padding.x; + bounds.y = r.y - style->touch_padding.y; + bounds.w = r.w + 2 * style->touch_padding.x; + bounds.h = r.h + 2 * style->touch_padding.y; + return nk_button_behavior(state, bounds, in, behavior); +} +NK_LIB void +nk_draw_button_text(struct nk_command_buffer *out, + const struct nk_rect *bounds, const struct nk_rect *content, nk_flags state, + const struct nk_style_button *style, const char *txt, int len, + nk_flags text_alignment, const struct nk_user_font *font) +{ + struct nk_text text; + const struct nk_style_item *background; + background = nk_draw_button(out, bounds, state, style); + + /* select correct colors/images */ + if (background->type == NK_STYLE_ITEM_COLOR) + text.background = background->data.color; + else text.background = style->text_background; + if (state & NK_WIDGET_STATE_HOVER) + text.text = style->text_hover; + else if (state & NK_WIDGET_STATE_ACTIVED) + text.text = style->text_active; + else text.text = style->text_normal; + + text.padding = nk_vec2(0,0); + nk_widget_text(out, *content, txt, len, &text, text_alignment, font); +} +NK_LIB nk_bool +nk_do_button_text(nk_flags *state, + struct nk_command_buffer *out, struct nk_rect bounds, + const char *string, int len, nk_flags align, enum nk_button_behavior behavior, + const struct nk_style_button *style, const struct nk_input *in, + const struct nk_user_font *font) +{ + struct nk_rect content; + int ret = nk_false; + + NK_ASSERT(state); + NK_ASSERT(style); + NK_ASSERT(out); + NK_ASSERT(string); + NK_ASSERT(font); + if (!out || !style || !font || !string) + return nk_false; + + ret = nk_do_button(state, out, bounds, style, in, behavior, &content); + if (style->draw_begin) style->draw_begin(out, style->userdata); + nk_draw_button_text(out, &bounds, &content, *state, style, string, len, align, font); + if (style->draw_end) style->draw_end(out, style->userdata); + return ret; +} +NK_LIB void +nk_draw_button_symbol(struct nk_command_buffer *out, + const struct nk_rect *bounds, const struct nk_rect *content, + nk_flags state, const struct nk_style_button *style, + enum nk_symbol_type type, const struct nk_user_font *font) +{ + struct nk_color sym, bg; + const struct nk_style_item *background; + + /* select correct colors/images */ + background = nk_draw_button(out, bounds, state, style); + if (background->type == NK_STYLE_ITEM_COLOR) + bg = background->data.color; + else bg = style->text_background; + + if (state & NK_WIDGET_STATE_HOVER) + sym = style->text_hover; + else if (state & NK_WIDGET_STATE_ACTIVED) + sym = style->text_active; + else sym = style->text_normal; + nk_draw_symbol(out, type, *content, bg, sym, 1, font); +} +NK_LIB nk_bool +nk_do_button_symbol(nk_flags *state, + struct nk_command_buffer *out, struct nk_rect bounds, + enum nk_symbol_type symbol, enum nk_button_behavior behavior, + const struct nk_style_button *style, const struct nk_input *in, + const struct nk_user_font *font) +{ + int ret; + struct nk_rect content; + + NK_ASSERT(state); + NK_ASSERT(style); + NK_ASSERT(font); + NK_ASSERT(out); + if (!out || !style || !font || !state) + return nk_false; + + ret = nk_do_button(state, out, bounds, style, in, behavior, &content); + if (style->draw_begin) style->draw_begin(out, style->userdata); + nk_draw_button_symbol(out, &bounds, &content, *state, style, symbol, font); + if (style->draw_end) style->draw_end(out, style->userdata); + return ret; +} +NK_LIB void +nk_draw_button_image(struct nk_command_buffer *out, + const struct nk_rect *bounds, const struct nk_rect *content, + nk_flags state, const struct nk_style_button *style, const struct nk_image *img) +{ + nk_draw_button(out, bounds, state, style); + nk_draw_image(out, *content, img, nk_white); +} +NK_LIB nk_bool +nk_do_button_image(nk_flags *state, + struct nk_command_buffer *out, struct nk_rect bounds, + struct nk_image img, enum nk_button_behavior b, + const struct nk_style_button *style, const struct nk_input *in) +{ + int ret; + struct nk_rect content; + + NK_ASSERT(state); + NK_ASSERT(style); + NK_ASSERT(out); + if (!out || !style || !state) + return nk_false; + + ret = nk_do_button(state, out, bounds, style, in, b, &content); + content.x += style->image_padding.x; + content.y += style->image_padding.y; + content.w -= 2 * style->image_padding.x; + content.h -= 2 * style->image_padding.y; + + if (style->draw_begin) style->draw_begin(out, style->userdata); + nk_draw_button_image(out, &bounds, &content, *state, style, &img); + if (style->draw_end) style->draw_end(out, style->userdata); + return ret; +} +NK_LIB void +nk_draw_button_text_symbol(struct nk_command_buffer *out, + const struct nk_rect *bounds, const struct nk_rect *label, + const struct nk_rect *symbol, nk_flags state, const struct nk_style_button *style, + const char *str, int len, enum nk_symbol_type type, + const struct nk_user_font *font) +{ + struct nk_color sym; + struct nk_text text; + const struct nk_style_item *background; + + /* select correct background colors/images */ + background = nk_draw_button(out, bounds, state, style); + if (background->type == NK_STYLE_ITEM_COLOR) + text.background = background->data.color; + else text.background = style->text_background; + + /* select correct text colors */ + if (state & NK_WIDGET_STATE_HOVER) { + sym = style->text_hover; + text.text = style->text_hover; + } else if (state & NK_WIDGET_STATE_ACTIVED) { + sym = style->text_active; + text.text = style->text_active; + } else { + sym = style->text_normal; + text.text = style->text_normal; + } + + text.padding = nk_vec2(0,0); + nk_draw_symbol(out, type, *symbol, style->text_background, sym, 0, font); + nk_widget_text(out, *label, str, len, &text, NK_TEXT_CENTERED, font); +} +NK_LIB nk_bool +nk_do_button_text_symbol(nk_flags *state, + struct nk_command_buffer *out, struct nk_rect bounds, + enum nk_symbol_type symbol, const char *str, int len, nk_flags align, + enum nk_button_behavior behavior, const struct nk_style_button *style, + const struct nk_user_font *font, const struct nk_input *in) +{ + int ret; + struct nk_rect tri = {0,0,0,0}; + struct nk_rect content; + + NK_ASSERT(style); + NK_ASSERT(out); + NK_ASSERT(font); + if (!out || !style || !font) + return nk_false; + + ret = nk_do_button(state, out, bounds, style, in, behavior, &content); + tri.y = content.y + (content.h/2) - font->height/2; + tri.w = font->height; tri.h = font->height; + if (align & NK_TEXT_ALIGN_LEFT) { + tri.x = (content.x + content.w) - (2 * style->padding.x + tri.w); + tri.x = NK_MAX(tri.x, 0); + } else tri.x = content.x + 2 * style->padding.x; + + /* draw button */ + if (style->draw_begin) style->draw_begin(out, style->userdata); + nk_draw_button_text_symbol(out, &bounds, &content, &tri, + *state, style, str, len, symbol, font); + if (style->draw_end) style->draw_end(out, style->userdata); + return ret; +} +NK_LIB void +nk_draw_button_text_image(struct nk_command_buffer *out, + const struct nk_rect *bounds, const struct nk_rect *label, + const struct nk_rect *image, nk_flags state, const struct nk_style_button *style, + const char *str, int len, const struct nk_user_font *font, + const struct nk_image *img) +{ + struct nk_text text; + const struct nk_style_item *background; + background = nk_draw_button(out, bounds, state, style); + + /* select correct colors */ + if (background->type == NK_STYLE_ITEM_COLOR) + text.background = background->data.color; + else text.background = style->text_background; + if (state & NK_WIDGET_STATE_HOVER) + text.text = style->text_hover; + else if (state & NK_WIDGET_STATE_ACTIVED) + text.text = style->text_active; + else text.text = style->text_normal; + + text.padding = nk_vec2(0,0); + nk_widget_text(out, *label, str, len, &text, NK_TEXT_CENTERED, font); + nk_draw_image(out, *image, img, nk_white); +} +NK_LIB nk_bool +nk_do_button_text_image(nk_flags *state, + struct nk_command_buffer *out, struct nk_rect bounds, + struct nk_image img, const char* str, int len, nk_flags align, + enum nk_button_behavior behavior, const struct nk_style_button *style, + const struct nk_user_font *font, const struct nk_input *in) +{ + int ret; + struct nk_rect icon; + struct nk_rect content; + + NK_ASSERT(style); + NK_ASSERT(state); + NK_ASSERT(font); + NK_ASSERT(out); + if (!out || !font || !style || !str) + return nk_false; + + ret = nk_do_button(state, out, bounds, style, in, behavior, &content); + icon.y = bounds.y + style->padding.y; + icon.w = icon.h = bounds.h - 2 * style->padding.y; + if (align & NK_TEXT_ALIGN_LEFT) { + icon.x = (bounds.x + bounds.w) - (2 * style->padding.x + icon.w); + icon.x = NK_MAX(icon.x, 0); + } else icon.x = bounds.x + 2 * style->padding.x; + + icon.x += style->image_padding.x; + icon.y += style->image_padding.y; + icon.w -= 2 * style->image_padding.x; + icon.h -= 2 * style->image_padding.y; + + if (style->draw_begin) style->draw_begin(out, style->userdata); + nk_draw_button_text_image(out, &bounds, &content, &icon, *state, style, str, len, font, &img); + if (style->draw_end) style->draw_end(out, style->userdata); + return ret; +} +NK_API void +nk_button_set_behavior(struct nk_context *ctx, enum nk_button_behavior behavior) +{ + NK_ASSERT(ctx); + if (!ctx) return; + ctx->button_behavior = behavior; +} +NK_API nk_bool +nk_button_push_behavior(struct nk_context *ctx, enum nk_button_behavior behavior) +{ + struct nk_config_stack_button_behavior *button_stack; + struct nk_config_stack_button_behavior_element *element; + + NK_ASSERT(ctx); + if (!ctx) return 0; + + button_stack = &ctx->stacks.button_behaviors; + NK_ASSERT(button_stack->head < (int)NK_LEN(button_stack->elements)); + if (button_stack->head >= (int)NK_LEN(button_stack->elements)) + return 0; + + element = &button_stack->elements[button_stack->head++]; + element->address = &ctx->button_behavior; + element->old_value = ctx->button_behavior; + ctx->button_behavior = behavior; + return 1; +} +NK_API nk_bool +nk_button_pop_behavior(struct nk_context *ctx) +{ + struct nk_config_stack_button_behavior *button_stack; + struct nk_config_stack_button_behavior_element *element; + + NK_ASSERT(ctx); + if (!ctx) return 0; + + button_stack = &ctx->stacks.button_behaviors; + NK_ASSERT(button_stack->head > 0); + if (button_stack->head < 1) + return 0; + + element = &button_stack->elements[--button_stack->head]; + *element->address = element->old_value; + return 1; +} +NK_API nk_bool +nk_button_text_styled(struct nk_context *ctx, + const struct nk_style_button *style, const char *title, int len) +{ + struct nk_window *win; + struct nk_panel *layout; + const struct nk_input *in; + + struct nk_rect bounds; + enum nk_widget_layout_states state; + + NK_ASSERT(ctx); + NK_ASSERT(style); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!style || !ctx || !ctx->current || !ctx->current->layout) return 0; + + win = ctx->current; + layout = win->layout; + state = nk_widget(&bounds, ctx); + + if (!state) return 0; + in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + return nk_do_button_text(&ctx->last_widget_state, &win->buffer, bounds, + title, len, style->text_alignment, ctx->button_behavior, + style, in, ctx->style.font); +} +NK_API nk_bool +nk_button_text(struct nk_context *ctx, const char *title, int len) +{ + NK_ASSERT(ctx); + if (!ctx) return 0; + return nk_button_text_styled(ctx, &ctx->style.button, title, len); +} +NK_API nk_bool nk_button_label_styled(struct nk_context *ctx, + const struct nk_style_button *style, const char *title) +{ + return nk_button_text_styled(ctx, style, title, nk_strlen(title)); +} +NK_API nk_bool nk_button_label(struct nk_context *ctx, const char *title) +{ + return nk_button_text(ctx, title, nk_strlen(title)); +} +NK_API nk_bool +nk_button_color(struct nk_context *ctx, struct nk_color color) +{ + struct nk_window *win; + struct nk_panel *layout; + const struct nk_input *in; + struct nk_style_button button; + + int ret = 0; + struct nk_rect bounds; + struct nk_rect content; + enum nk_widget_layout_states state; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return 0; + + win = ctx->current; + layout = win->layout; + + state = nk_widget(&bounds, ctx); + if (!state) return 0; + in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + + button = ctx->style.button; + button.normal = nk_style_item_color(color); + button.hover = nk_style_item_color(color); + button.active = nk_style_item_color(color); + ret = nk_do_button(&ctx->last_widget_state, &win->buffer, bounds, + &button, in, ctx->button_behavior, &content); + nk_draw_button(&win->buffer, &bounds, ctx->last_widget_state, &button); + return ret; +} +NK_API nk_bool +nk_button_symbol_styled(struct nk_context *ctx, + const struct nk_style_button *style, enum nk_symbol_type symbol) +{ + struct nk_window *win; + struct nk_panel *layout; + const struct nk_input *in; + + struct nk_rect bounds; + enum nk_widget_layout_states state; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return 0; + + win = ctx->current; + layout = win->layout; + state = nk_widget(&bounds, ctx); + if (!state) return 0; + in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + return nk_do_button_symbol(&ctx->last_widget_state, &win->buffer, bounds, + symbol, ctx->button_behavior, style, in, ctx->style.font); +} +NK_API nk_bool +nk_button_symbol(struct nk_context *ctx, enum nk_symbol_type symbol) +{ + NK_ASSERT(ctx); + if (!ctx) return 0; + return nk_button_symbol_styled(ctx, &ctx->style.button, symbol); +} +NK_API nk_bool +nk_button_image_styled(struct nk_context *ctx, const struct nk_style_button *style, + struct nk_image img) +{ + struct nk_window *win; + struct nk_panel *layout; + const struct nk_input *in; + + struct nk_rect bounds; + enum nk_widget_layout_states state; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return 0; + + win = ctx->current; + layout = win->layout; + + state = nk_widget(&bounds, ctx); + if (!state) return 0; + in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + return nk_do_button_image(&ctx->last_widget_state, &win->buffer, bounds, + img, ctx->button_behavior, style, in); +} +NK_API nk_bool +nk_button_image(struct nk_context *ctx, struct nk_image img) +{ + NK_ASSERT(ctx); + if (!ctx) return 0; + return nk_button_image_styled(ctx, &ctx->style.button, img); +} +NK_API nk_bool +nk_button_symbol_text_styled(struct nk_context *ctx, + const struct nk_style_button *style, enum nk_symbol_type symbol, + const char *text, int len, nk_flags align) +{ + struct nk_window *win; + struct nk_panel *layout; + const struct nk_input *in; + + struct nk_rect bounds; + enum nk_widget_layout_states state; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return 0; + + win = ctx->current; + layout = win->layout; + + state = nk_widget(&bounds, ctx); + if (!state) return 0; + in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + return nk_do_button_text_symbol(&ctx->last_widget_state, &win->buffer, bounds, + symbol, text, len, align, ctx->button_behavior, + style, ctx->style.font, in); +} +NK_API nk_bool +nk_button_symbol_text(struct nk_context *ctx, enum nk_symbol_type symbol, + const char* text, int len, nk_flags align) +{ + NK_ASSERT(ctx); + if (!ctx) return 0; + return nk_button_symbol_text_styled(ctx, &ctx->style.button, symbol, text, len, align); +} +NK_API nk_bool nk_button_symbol_label(struct nk_context *ctx, enum nk_symbol_type symbol, + const char *label, nk_flags align) +{ + return nk_button_symbol_text(ctx, symbol, label, nk_strlen(label), align); +} +NK_API nk_bool nk_button_symbol_label_styled(struct nk_context *ctx, + const struct nk_style_button *style, enum nk_symbol_type symbol, + const char *title, nk_flags align) +{ + return nk_button_symbol_text_styled(ctx, style, symbol, title, nk_strlen(title), align); +} +NK_API nk_bool +nk_button_image_text_styled(struct nk_context *ctx, + const struct nk_style_button *style, struct nk_image img, const char *text, + int len, nk_flags align) +{ + struct nk_window *win; + struct nk_panel *layout; + const struct nk_input *in; + + struct nk_rect bounds; + enum nk_widget_layout_states state; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return 0; + + win = ctx->current; + layout = win->layout; + + state = nk_widget(&bounds, ctx); + if (!state) return 0; + in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + return nk_do_button_text_image(&ctx->last_widget_state, &win->buffer, + bounds, img, text, len, align, ctx->button_behavior, + style, ctx->style.font, in); +} +NK_API nk_bool +nk_button_image_text(struct nk_context *ctx, struct nk_image img, + const char *text, int len, nk_flags align) +{ + return nk_button_image_text_styled(ctx, &ctx->style.button,img, text, len, align); +} +NK_API nk_bool nk_button_image_label(struct nk_context *ctx, struct nk_image img, + const char *label, nk_flags align) +{ + return nk_button_image_text(ctx, img, label, nk_strlen(label), align); +} +NK_API nk_bool nk_button_image_label_styled(struct nk_context *ctx, + const struct nk_style_button *style, struct nk_image img, + const char *label, nk_flags text_alignment) +{ + return nk_button_image_text_styled(ctx, style, img, label, nk_strlen(label), text_alignment); +} + + + + + +/* =============================================================== + * + * TOGGLE + * + * ===============================================================*/ +NK_LIB nk_bool +nk_toggle_behavior(const struct nk_input *in, struct nk_rect select, + nk_flags *state, nk_bool active) +{ + nk_widget_state_reset(state); + if (nk_button_behavior(state, select, in, NK_BUTTON_DEFAULT)) { + *state = NK_WIDGET_STATE_ACTIVE; + active = !active; + } + if (*state & NK_WIDGET_STATE_HOVER && !nk_input_is_mouse_prev_hovering_rect(in, select)) + *state |= NK_WIDGET_STATE_ENTERED; + else if (nk_input_is_mouse_prev_hovering_rect(in, select)) + *state |= NK_WIDGET_STATE_LEFT; + return active; +} +NK_LIB void +nk_draw_checkbox(struct nk_command_buffer *out, + nk_flags state, const struct nk_style_toggle *style, nk_bool active, + const struct nk_rect *label, const struct nk_rect *selector, + const struct nk_rect *cursors, const char *string, int len, + const struct nk_user_font *font) +{ + const struct nk_style_item *background; + const struct nk_style_item *cursor; + struct nk_text text; + + /* select correct colors/images */ + if (state & NK_WIDGET_STATE_HOVER) { + background = &style->hover; + cursor = &style->cursor_hover; + text.text = style->text_hover; + } else if (state & NK_WIDGET_STATE_ACTIVED) { + background = &style->hover; + cursor = &style->cursor_hover; + text.text = style->text_active; + } else { + background = &style->normal; + cursor = &style->cursor_normal; + text.text = style->text_normal; + } + + /* draw background and cursor */ + if (background->type == NK_STYLE_ITEM_COLOR) { + nk_fill_rect(out, *selector, 0, style->border_color); + nk_fill_rect(out, nk_shrink_rect(*selector, style->border), 0, background->data.color); + } else nk_draw_image(out, *selector, &background->data.image, nk_white); + if (active) { + if (cursor->type == NK_STYLE_ITEM_IMAGE) + nk_draw_image(out, *cursors, &cursor->data.image, nk_white); + else nk_fill_rect(out, *cursors, 0, cursor->data.color); + } + + text.padding.x = 0; + text.padding.y = 0; + text.background = style->text_background; + nk_widget_text(out, *label, string, len, &text, NK_TEXT_LEFT, font); +} +NK_LIB void +nk_draw_option(struct nk_command_buffer *out, + nk_flags state, const struct nk_style_toggle *style, nk_bool active, + const struct nk_rect *label, const struct nk_rect *selector, + const struct nk_rect *cursors, const char *string, int len, + const struct nk_user_font *font) +{ + const struct nk_style_item *background; + const struct nk_style_item *cursor; + struct nk_text text; + + /* select correct colors/images */ + if (state & NK_WIDGET_STATE_HOVER) { + background = &style->hover; + cursor = &style->cursor_hover; + text.text = style->text_hover; + } else if (state & NK_WIDGET_STATE_ACTIVED) { + background = &style->hover; + cursor = &style->cursor_hover; + text.text = style->text_active; + } else { + background = &style->normal; + cursor = &style->cursor_normal; + text.text = style->text_normal; + } + + /* draw background and cursor */ + if (background->type == NK_STYLE_ITEM_COLOR) { + nk_fill_circle(out, *selector, style->border_color); + nk_fill_circle(out, nk_shrink_rect(*selector, style->border), background->data.color); + } else nk_draw_image(out, *selector, &background->data.image, nk_white); + if (active) { + if (cursor->type == NK_STYLE_ITEM_IMAGE) + nk_draw_image(out, *cursors, &cursor->data.image, nk_white); + else nk_fill_circle(out, *cursors, cursor->data.color); + } + + text.padding.x = 0; + text.padding.y = 0; + text.background = style->text_background; + nk_widget_text(out, *label, string, len, &text, NK_TEXT_LEFT, font); +} +NK_LIB nk_bool +nk_do_toggle(nk_flags *state, + struct nk_command_buffer *out, struct nk_rect r, + nk_bool *active, const char *str, int len, enum nk_toggle_type type, + const struct nk_style_toggle *style, const struct nk_input *in, + const struct nk_user_font *font) +{ + int was_active; + struct nk_rect bounds; + struct nk_rect select; + struct nk_rect cursor; + struct nk_rect label; + + NK_ASSERT(style); + NK_ASSERT(out); + NK_ASSERT(font); + if (!out || !style || !font || !active) + return 0; + + r.w = NK_MAX(r.w, font->height + 2 * style->padding.x); + r.h = NK_MAX(r.h, font->height + 2 * style->padding.y); + + /* add additional touch padding for touch screen devices */ + bounds.x = r.x - style->touch_padding.x; + bounds.y = r.y - style->touch_padding.y; + bounds.w = r.w + 2 * style->touch_padding.x; + bounds.h = r.h + 2 * style->touch_padding.y; + + /* calculate the selector space */ + select.w = font->height; + select.h = select.w; + select.y = r.y + r.h/2.0f - select.h/2.0f; + select.x = r.x; + + /* calculate the bounds of the cursor inside the selector */ + cursor.x = select.x + style->padding.x + style->border; + cursor.y = select.y + style->padding.y + style->border; + cursor.w = select.w - (2 * style->padding.x + 2 * style->border); + cursor.h = select.h - (2 * style->padding.y + 2 * style->border); + + /* label behind the selector */ + label.x = select.x + select.w + style->spacing; + label.y = select.y; + label.w = NK_MAX(r.x + r.w, label.x) - label.x; + label.h = select.w; + + /* update selector */ + was_active = *active; + *active = nk_toggle_behavior(in, bounds, state, *active); + + /* draw selector */ + if (style->draw_begin) + style->draw_begin(out, style->userdata); + if (type == NK_TOGGLE_CHECK) { + nk_draw_checkbox(out, *state, style, *active, &label, &select, &cursor, str, len, font); + } else { + nk_draw_option(out, *state, style, *active, &label, &select, &cursor, str, len, font); + } + if (style->draw_end) + style->draw_end(out, style->userdata); + return (was_active != *active); +} +/*---------------------------------------------------------------- + * + * CHECKBOX + * + * --------------------------------------------------------------*/ +NK_API nk_bool +nk_check_text(struct nk_context *ctx, const char *text, int len, nk_bool active) +{ + struct nk_window *win; + struct nk_panel *layout; + const struct nk_input *in; + const struct nk_style *style; + + struct nk_rect bounds; + enum nk_widget_layout_states state; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return active; + + win = ctx->current; + style = &ctx->style; + layout = win->layout; + + state = nk_widget(&bounds, ctx); + if (!state) return active; + in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + nk_do_toggle(&ctx->last_widget_state, &win->buffer, bounds, &active, + text, len, NK_TOGGLE_CHECK, &style->checkbox, in, style->font); + return active; +} +NK_API unsigned int +nk_check_flags_text(struct nk_context *ctx, const char *text, int len, + unsigned int flags, unsigned int value) +{ + int old_active; + NK_ASSERT(ctx); + NK_ASSERT(text); + if (!ctx || !text) return flags; + old_active = (int)((flags & value) & value); + if (nk_check_text(ctx, text, len, old_active)) + flags |= value; + else flags &= ~value; + return flags; +} +NK_API nk_bool +nk_checkbox_text(struct nk_context *ctx, const char *text, int len, nk_bool *active) +{ + int old_val; + NK_ASSERT(ctx); + NK_ASSERT(text); + NK_ASSERT(active); + if (!ctx || !text || !active) return 0; + old_val = *active; + *active = nk_check_text(ctx, text, len, *active); + return old_val != *active; +} +NK_API nk_bool +nk_checkbox_flags_text(struct nk_context *ctx, const char *text, int len, + unsigned int *flags, unsigned int value) +{ + nk_bool active; + NK_ASSERT(ctx); + NK_ASSERT(text); + NK_ASSERT(flags); + if (!ctx || !text || !flags) return 0; + + active = (int)((*flags & value) & value); + if (nk_checkbox_text(ctx, text, len, &active)) { + if (active) *flags |= value; + else *flags &= ~value; + return 1; + } + return 0; +} +NK_API nk_bool nk_check_label(struct nk_context *ctx, const char *label, nk_bool active) +{ + return nk_check_text(ctx, label, nk_strlen(label), active); +} +NK_API unsigned int nk_check_flags_label(struct nk_context *ctx, const char *label, + unsigned int flags, unsigned int value) +{ + return nk_check_flags_text(ctx, label, nk_strlen(label), flags, value); +} +NK_API nk_bool nk_checkbox_label(struct nk_context *ctx, const char *label, nk_bool *active) +{ + return nk_checkbox_text(ctx, label, nk_strlen(label), active); +} +NK_API nk_bool nk_checkbox_flags_label(struct nk_context *ctx, const char *label, + unsigned int *flags, unsigned int value) +{ + return nk_checkbox_flags_text(ctx, label, nk_strlen(label), flags, value); +} +/*---------------------------------------------------------------- + * + * OPTION + * + * --------------------------------------------------------------*/ +NK_API nk_bool +nk_option_text(struct nk_context *ctx, const char *text, int len, nk_bool is_active) +{ + struct nk_window *win; + struct nk_panel *layout; + const struct nk_input *in; + const struct nk_style *style; + + struct nk_rect bounds; + enum nk_widget_layout_states state; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return is_active; + + win = ctx->current; + style = &ctx->style; + layout = win->layout; + + state = nk_widget(&bounds, ctx); + if (!state) return (int)state; + in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + nk_do_toggle(&ctx->last_widget_state, &win->buffer, bounds, &is_active, + text, len, NK_TOGGLE_OPTION, &style->option, in, style->font); + return is_active; +} +NK_API nk_bool +nk_radio_text(struct nk_context *ctx, const char *text, int len, nk_bool *active) +{ + int old_value; + NK_ASSERT(ctx); + NK_ASSERT(text); + NK_ASSERT(active); + if (!ctx || !text || !active) return 0; + old_value = *active; + *active = nk_option_text(ctx, text, len, old_value); + return old_value != *active; +} +NK_API nk_bool +nk_option_label(struct nk_context *ctx, const char *label, nk_bool active) +{ + return nk_option_text(ctx, label, nk_strlen(label), active); +} +NK_API nk_bool +nk_radio_label(struct nk_context *ctx, const char *label, nk_bool *active) +{ + return nk_radio_text(ctx, label, nk_strlen(label), active); +} + + + + + +/* =============================================================== + * + * SELECTABLE + * + * ===============================================================*/ +NK_LIB void +nk_draw_selectable(struct nk_command_buffer *out, + nk_flags state, const struct nk_style_selectable *style, nk_bool active, + const struct nk_rect *bounds, + const struct nk_rect *icon, const struct nk_image *img, enum nk_symbol_type sym, + const char *string, int len, nk_flags align, const struct nk_user_font *font) +{ + const struct nk_style_item *background; + struct nk_text text; + text.padding = style->padding; + + /* select correct colors/images */ + if (!active) { + if (state & NK_WIDGET_STATE_ACTIVED) { + background = &style->pressed; + text.text = style->text_pressed; + } else if (state & NK_WIDGET_STATE_HOVER) { + background = &style->hover; + text.text = style->text_hover; + } else { + background = &style->normal; + text.text = style->text_normal; + } + } else { + if (state & NK_WIDGET_STATE_ACTIVED) { + background = &style->pressed_active; + text.text = style->text_pressed_active; + } else if (state & NK_WIDGET_STATE_HOVER) { + background = &style->hover_active; + text.text = style->text_hover_active; + } else { + background = &style->normal_active; + text.text = style->text_normal_active; + } + } + /* draw selectable background and text */ + switch (background->type) { + case NK_STYLE_ITEM_IMAGE: + text.background = nk_rgba(0, 0, 0, 0); + nk_draw_image(out, *bounds, &background->data.image, nk_white); + break; + case NK_STYLE_ITEM_NINE_SLICE: + text.background = nk_rgba(0, 0, 0, 0); + nk_draw_nine_slice(out, *bounds, &background->data.slice, nk_white); + break; + case NK_STYLE_ITEM_COLOR: + text.background = background->data.color; + nk_fill_rect(out, *bounds, style->rounding, background->data.color); + break; + } + if (icon) { + if (img) nk_draw_image(out, *icon, img, nk_white); + else nk_draw_symbol(out, sym, *icon, text.background, text.text, 1, font); + } + nk_widget_text(out, *bounds, string, len, &text, align, font); +} +NK_LIB nk_bool +nk_do_selectable(nk_flags *state, struct nk_command_buffer *out, + struct nk_rect bounds, const char *str, int len, nk_flags align, nk_bool *value, + const struct nk_style_selectable *style, const struct nk_input *in, + const struct nk_user_font *font) +{ + int old_value; + struct nk_rect touch; + + NK_ASSERT(state); + NK_ASSERT(out); + NK_ASSERT(str); + NK_ASSERT(len); + NK_ASSERT(value); + NK_ASSERT(style); + NK_ASSERT(font); + + if (!state || !out || !str || !len || !value || !style || !font) return 0; + old_value = *value; + + /* remove padding */ + touch.x = bounds.x - style->touch_padding.x; + touch.y = bounds.y - style->touch_padding.y; + touch.w = bounds.w + style->touch_padding.x * 2; + touch.h = bounds.h + style->touch_padding.y * 2; + + /* update button */ + if (nk_button_behavior(state, touch, in, NK_BUTTON_DEFAULT)) + *value = !(*value); + + /* draw selectable */ + if (style->draw_begin) style->draw_begin(out, style->userdata); + nk_draw_selectable(out, *state, style, *value, &bounds, 0,0,NK_SYMBOL_NONE, str, len, align, font); + if (style->draw_end) style->draw_end(out, style->userdata); + return old_value != *value; +} +NK_LIB nk_bool +nk_do_selectable_image(nk_flags *state, struct nk_command_buffer *out, + struct nk_rect bounds, const char *str, int len, nk_flags align, nk_bool *value, + const struct nk_image *img, const struct nk_style_selectable *style, + const struct nk_input *in, const struct nk_user_font *font) +{ + nk_bool old_value; + struct nk_rect touch; + struct nk_rect icon; + + NK_ASSERT(state); + NK_ASSERT(out); + NK_ASSERT(str); + NK_ASSERT(len); + NK_ASSERT(value); + NK_ASSERT(style); + NK_ASSERT(font); + + if (!state || !out || !str || !len || !value || !style || !font) return 0; + old_value = *value; + + /* toggle behavior */ + touch.x = bounds.x - style->touch_padding.x; + touch.y = bounds.y - style->touch_padding.y; + touch.w = bounds.w + style->touch_padding.x * 2; + touch.h = bounds.h + style->touch_padding.y * 2; + if (nk_button_behavior(state, touch, in, NK_BUTTON_DEFAULT)) + *value = !(*value); + + icon.y = bounds.y + style->padding.y; + icon.w = icon.h = bounds.h - 2 * style->padding.y; + if (align & NK_TEXT_ALIGN_LEFT) { + icon.x = (bounds.x + bounds.w) - (2 * style->padding.x + icon.w); + icon.x = NK_MAX(icon.x, 0); + } else icon.x = bounds.x + 2 * style->padding.x; + + icon.x += style->image_padding.x; + icon.y += style->image_padding.y; + icon.w -= 2 * style->image_padding.x; + icon.h -= 2 * style->image_padding.y; + + /* draw selectable */ + if (style->draw_begin) style->draw_begin(out, style->userdata); + nk_draw_selectable(out, *state, style, *value, &bounds, &icon, img, NK_SYMBOL_NONE, str, len, align, font); + if (style->draw_end) style->draw_end(out, style->userdata); + return old_value != *value; +} +NK_LIB nk_bool +nk_do_selectable_symbol(nk_flags *state, struct nk_command_buffer *out, + struct nk_rect bounds, const char *str, int len, nk_flags align, nk_bool *value, + enum nk_symbol_type sym, const struct nk_style_selectable *style, + const struct nk_input *in, const struct nk_user_font *font) +{ + int old_value; + struct nk_rect touch; + struct nk_rect icon; + + NK_ASSERT(state); + NK_ASSERT(out); + NK_ASSERT(str); + NK_ASSERT(len); + NK_ASSERT(value); + NK_ASSERT(style); + NK_ASSERT(font); + + if (!state || !out || !str || !len || !value || !style || !font) return 0; + old_value = *value; + + /* toggle behavior */ + touch.x = bounds.x - style->touch_padding.x; + touch.y = bounds.y - style->touch_padding.y; + touch.w = bounds.w + style->touch_padding.x * 2; + touch.h = bounds.h + style->touch_padding.y * 2; + if (nk_button_behavior(state, touch, in, NK_BUTTON_DEFAULT)) + *value = !(*value); + + icon.y = bounds.y + style->padding.y; + icon.w = icon.h = bounds.h - 2 * style->padding.y; + if (align & NK_TEXT_ALIGN_LEFT) { + icon.x = (bounds.x + bounds.w) - (2 * style->padding.x + icon.w); + icon.x = NK_MAX(icon.x, 0); + } else icon.x = bounds.x + 2 * style->padding.x; + + icon.x += style->image_padding.x; + icon.y += style->image_padding.y; + icon.w -= 2 * style->image_padding.x; + icon.h -= 2 * style->image_padding.y; + + /* draw selectable */ + if (style->draw_begin) style->draw_begin(out, style->userdata); + nk_draw_selectable(out, *state, style, *value, &bounds, &icon, 0, sym, str, len, align, font); + if (style->draw_end) style->draw_end(out, style->userdata); + return old_value != *value; +} + +NK_API nk_bool +nk_selectable_text(struct nk_context *ctx, const char *str, int len, + nk_flags align, nk_bool *value) +{ + struct nk_window *win; + struct nk_panel *layout; + const struct nk_input *in; + const struct nk_style *style; + + enum nk_widget_layout_states state; + struct nk_rect bounds; + + NK_ASSERT(ctx); + NK_ASSERT(value); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout || !value) + return 0; + + win = ctx->current; + layout = win->layout; + style = &ctx->style; + + state = nk_widget(&bounds, ctx); + if (!state) return 0; + in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + return nk_do_selectable(&ctx->last_widget_state, &win->buffer, bounds, + str, len, align, value, &style->selectable, in, style->font); +} +NK_API nk_bool +nk_selectable_image_text(struct nk_context *ctx, struct nk_image img, + const char *str, int len, nk_flags align, nk_bool *value) +{ + struct nk_window *win; + struct nk_panel *layout; + const struct nk_input *in; + const struct nk_style *style; + + enum nk_widget_layout_states state; + struct nk_rect bounds; + + NK_ASSERT(ctx); + NK_ASSERT(value); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout || !value) + return 0; + + win = ctx->current; + layout = win->layout; + style = &ctx->style; + + state = nk_widget(&bounds, ctx); + if (!state) return 0; + in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + return nk_do_selectable_image(&ctx->last_widget_state, &win->buffer, bounds, + str, len, align, value, &img, &style->selectable, in, style->font); +} +NK_API nk_bool +nk_selectable_symbol_text(struct nk_context *ctx, enum nk_symbol_type sym, + const char *str, int len, nk_flags align, nk_bool *value) +{ + struct nk_window *win; + struct nk_panel *layout; + const struct nk_input *in; + const struct nk_style *style; + + enum nk_widget_layout_states state; + struct nk_rect bounds; + + NK_ASSERT(ctx); + NK_ASSERT(value); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout || !value) + return 0; + + win = ctx->current; + layout = win->layout; + style = &ctx->style; + + state = nk_widget(&bounds, ctx); + if (!state) return 0; + in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + return nk_do_selectable_symbol(&ctx->last_widget_state, &win->buffer, bounds, + str, len, align, value, sym, &style->selectable, in, style->font); +} +NK_API nk_bool +nk_selectable_symbol_label(struct nk_context *ctx, enum nk_symbol_type sym, + const char *title, nk_flags align, nk_bool *value) +{ + return nk_selectable_symbol_text(ctx, sym, title, nk_strlen(title), align, value); +} +NK_API nk_bool nk_select_text(struct nk_context *ctx, const char *str, int len, + nk_flags align, nk_bool value) +{ + nk_selectable_text(ctx, str, len, align, &value);return value; +} +NK_API nk_bool nk_selectable_label(struct nk_context *ctx, const char *str, nk_flags align, nk_bool *value) +{ + return nk_selectable_text(ctx, str, nk_strlen(str), align, value); +} +NK_API nk_bool nk_selectable_image_label(struct nk_context *ctx,struct nk_image img, + const char *str, nk_flags align, nk_bool *value) +{ + return nk_selectable_image_text(ctx, img, str, nk_strlen(str), align, value); +} +NK_API nk_bool nk_select_label(struct nk_context *ctx, const char *str, nk_flags align, nk_bool value) +{ + nk_selectable_text(ctx, str, nk_strlen(str), align, &value);return value; +} +NK_API nk_bool nk_select_image_label(struct nk_context *ctx, struct nk_image img, + const char *str, nk_flags align, nk_bool value) +{ + nk_selectable_image_text(ctx, img, str, nk_strlen(str), align, &value);return value; +} +NK_API nk_bool nk_select_image_text(struct nk_context *ctx, struct nk_image img, + const char *str, int len, nk_flags align, nk_bool value) +{ + nk_selectable_image_text(ctx, img, str, len, align, &value);return value; +} +NK_API nk_bool +nk_select_symbol_text(struct nk_context *ctx, enum nk_symbol_type sym, + const char *title, int title_len, nk_flags align, nk_bool value) +{ + nk_selectable_symbol_text(ctx, sym, title, title_len, align, &value);return value; +} +NK_API nk_bool +nk_select_symbol_label(struct nk_context *ctx, enum nk_symbol_type sym, + const char *title, nk_flags align, nk_bool value) +{ + return nk_select_symbol_text(ctx, sym, title, nk_strlen(title), align, value); +} + + + + + +/* =============================================================== + * + * SLIDER + * + * ===============================================================*/ +NK_LIB float +nk_slider_behavior(nk_flags *state, struct nk_rect *logical_cursor, + struct nk_rect *visual_cursor, struct nk_input *in, + struct nk_rect bounds, float slider_min, float slider_max, float slider_value, + float slider_step, float slider_steps) +{ + int left_mouse_down; + int left_mouse_click_in_cursor; + + /* check if visual cursor is being dragged */ + nk_widget_state_reset(state); + left_mouse_down = in && in->mouse.buttons[NK_BUTTON_LEFT].down; + left_mouse_click_in_cursor = in && nk_input_has_mouse_click_down_in_rect(in, + NK_BUTTON_LEFT, *visual_cursor, nk_true); + + if (left_mouse_down && left_mouse_click_in_cursor) { + float ratio = 0; + const float d = in->mouse.pos.x - (visual_cursor->x+visual_cursor->w*0.5f); + const float pxstep = bounds.w / slider_steps; + + /* only update value if the next slider step is reached */ + *state = NK_WIDGET_STATE_ACTIVE; + if (NK_ABS(d) >= pxstep) { + const float steps = (float)((int)(NK_ABS(d) / pxstep)); + slider_value += (d > 0) ? (slider_step*steps) : -(slider_step*steps); + slider_value = NK_CLAMP(slider_min, slider_value, slider_max); + ratio = (slider_value - slider_min)/slider_step; + logical_cursor->x = bounds.x + (logical_cursor->w * ratio); + in->mouse.buttons[NK_BUTTON_LEFT].clicked_pos.x = logical_cursor->x; + } + } + + /* slider widget state */ + if (nk_input_is_mouse_hovering_rect(in, bounds)) + *state = NK_WIDGET_STATE_HOVERED; + if (*state & NK_WIDGET_STATE_HOVER && + !nk_input_is_mouse_prev_hovering_rect(in, bounds)) + *state |= NK_WIDGET_STATE_ENTERED; + else if (nk_input_is_mouse_prev_hovering_rect(in, bounds)) + *state |= NK_WIDGET_STATE_LEFT; + return slider_value; +} +NK_LIB void +nk_draw_slider(struct nk_command_buffer *out, nk_flags state, + const struct nk_style_slider *style, const struct nk_rect *bounds, + const struct nk_rect *visual_cursor, float min, float value, float max) +{ + struct nk_rect fill; + struct nk_rect bar; + const struct nk_style_item *background; + + /* select correct slider images/colors */ + struct nk_color bar_color; + const struct nk_style_item *cursor; + + NK_UNUSED(min); + NK_UNUSED(max); + NK_UNUSED(value); + + if (state & NK_WIDGET_STATE_ACTIVED) { + background = &style->active; + bar_color = style->bar_active; + cursor = &style->cursor_active; + } else if (state & NK_WIDGET_STATE_HOVER) { + background = &style->hover; + bar_color = style->bar_hover; + cursor = &style->cursor_hover; + } else { + background = &style->normal; + bar_color = style->bar_normal; + cursor = &style->cursor_normal; + } + /* calculate slider background bar */ + bar.x = bounds->x; + bar.y = (visual_cursor->y + visual_cursor->h/2) - bounds->h/12; + bar.w = bounds->w; + bar.h = bounds->h/6; + + /* filled background bar style */ + fill.w = (visual_cursor->x + (visual_cursor->w/2.0f)) - bar.x; + fill.x = bar.x; + fill.y = bar.y; + fill.h = bar.h; + + /* draw background */ + switch(background->type) { + case NK_STYLE_ITEM_IMAGE: + nk_draw_image(out, *bounds, &background->data.image, nk_white); + break; + case NK_STYLE_ITEM_NINE_SLICE: + nk_draw_nine_slice(out, *bounds, &background->data.slice, nk_white); + break; + case NK_STYLE_ITEM_COLOR: + nk_fill_rect(out, *bounds, style->rounding, background->data.color); + nk_stroke_rect(out, *bounds, style->rounding, style->border, style->border_color); + break; + } + + /* draw slider bar */ + nk_fill_rect(out, bar, style->rounding, bar_color); + nk_fill_rect(out, fill, style->rounding, style->bar_filled); + + /* draw cursor */ + if (cursor->type == NK_STYLE_ITEM_IMAGE) + nk_draw_image(out, *visual_cursor, &cursor->data.image, nk_white); + else + nk_fill_circle(out, *visual_cursor, cursor->data.color); +} +NK_LIB float +nk_do_slider(nk_flags *state, + struct nk_command_buffer *out, struct nk_rect bounds, + float min, float val, float max, float step, + const struct nk_style_slider *style, struct nk_input *in, + const struct nk_user_font *font) +{ + float slider_range; + float slider_min; + float slider_max; + float slider_value; + float slider_steps; + float cursor_offset; + + struct nk_rect visual_cursor; + struct nk_rect logical_cursor; + + NK_ASSERT(style); + NK_ASSERT(out); + if (!out || !style) + return 0; + + /* remove padding from slider bounds */ + bounds.x = bounds.x + style->padding.x; + bounds.y = bounds.y + style->padding.y; + bounds.h = NK_MAX(bounds.h, 2*style->padding.y); + bounds.w = NK_MAX(bounds.w, 2*style->padding.x + style->cursor_size.x); + bounds.w -= 2 * style->padding.x; + bounds.h -= 2 * style->padding.y; + + /* optional buttons */ + if (style->show_buttons) { + nk_flags ws; + struct nk_rect button; + button.y = bounds.y; + button.w = bounds.h; + button.h = bounds.h; + + /* decrement button */ + button.x = bounds.x; + if (nk_do_button_symbol(&ws, out, button, style->dec_symbol, NK_BUTTON_DEFAULT, + &style->dec_button, in, font)) + val -= step; + + /* increment button */ + button.x = (bounds.x + bounds.w) - button.w; + if (nk_do_button_symbol(&ws, out, button, style->inc_symbol, NK_BUTTON_DEFAULT, + &style->inc_button, in, font)) + val += step; + + bounds.x = bounds.x + button.w + style->spacing.x; + bounds.w = bounds.w - (2*button.w + 2*style->spacing.x); + } + + /* remove one cursor size to support visual cursor */ + bounds.x += style->cursor_size.x*0.5f; + bounds.w -= style->cursor_size.x; + + /* make sure the provided values are correct */ + slider_max = NK_MAX(min, max); + slider_min = NK_MIN(min, max); + slider_value = NK_CLAMP(slider_min, val, slider_max); + slider_range = slider_max - slider_min; + slider_steps = slider_range / step; + cursor_offset = (slider_value - slider_min) / step; + + /* calculate cursor + Basically you have two cursors. One for visual representation and interaction + and one for updating the actual cursor value. */ + logical_cursor.h = bounds.h; + logical_cursor.w = bounds.w / slider_steps; + logical_cursor.x = bounds.x + (logical_cursor.w * cursor_offset); + logical_cursor.y = bounds.y; + + visual_cursor.h = style->cursor_size.y; + visual_cursor.w = style->cursor_size.x; + visual_cursor.y = (bounds.y + bounds.h*0.5f) - visual_cursor.h*0.5f; + visual_cursor.x = logical_cursor.x - visual_cursor.w*0.5f; + + slider_value = nk_slider_behavior(state, &logical_cursor, &visual_cursor, + in, bounds, slider_min, slider_max, slider_value, step, slider_steps); + visual_cursor.x = logical_cursor.x - visual_cursor.w*0.5f; + + /* draw slider */ + if (style->draw_begin) style->draw_begin(out, style->userdata); + nk_draw_slider(out, *state, style, &bounds, &visual_cursor, slider_min, slider_value, slider_max); + if (style->draw_end) style->draw_end(out, style->userdata); + return slider_value; +} +NK_API nk_bool +nk_slider_float(struct nk_context *ctx, float min_value, float *value, float max_value, + float value_step) +{ + struct nk_window *win; + struct nk_panel *layout; + struct nk_input *in; + const struct nk_style *style; + + int ret = 0; + float old_value; + struct nk_rect bounds; + enum nk_widget_layout_states state; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + NK_ASSERT(value); + if (!ctx || !ctx->current || !ctx->current->layout || !value) + return ret; + + win = ctx->current; + style = &ctx->style; + layout = win->layout; + + state = nk_widget(&bounds, ctx); + if (!state) return ret; + in = (/*state == NK_WIDGET_ROM || */ layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + + old_value = *value; + *value = nk_do_slider(&ctx->last_widget_state, &win->buffer, bounds, min_value, + old_value, max_value, value_step, &style->slider, in, style->font); + return (old_value > *value || old_value < *value); +} +NK_API float +nk_slide_float(struct nk_context *ctx, float min, float val, float max, float step) +{ + nk_slider_float(ctx, min, &val, max, step); return val; +} +NK_API int +nk_slide_int(struct nk_context *ctx, int min, int val, int max, int step) +{ + float value = (float)val; + nk_slider_float(ctx, (float)min, &value, (float)max, (float)step); + return (int)value; +} +NK_API nk_bool +nk_slider_int(struct nk_context *ctx, int min, int *val, int max, int step) +{ + int ret; + float value = (float)*val; + ret = nk_slider_float(ctx, (float)min, &value, (float)max, (float)step); + *val = (int)value; + return ret; +} + + + + + +/* =============================================================== + * + * PROGRESS + * + * ===============================================================*/ +NK_LIB nk_size +nk_progress_behavior(nk_flags *state, struct nk_input *in, + struct nk_rect r, struct nk_rect cursor, nk_size max, nk_size value, nk_bool modifiable) +{ + int left_mouse_down = 0; + int left_mouse_click_in_cursor = 0; + + nk_widget_state_reset(state); + if (!in || !modifiable) return value; + left_mouse_down = in && in->mouse.buttons[NK_BUTTON_LEFT].down; + left_mouse_click_in_cursor = in && nk_input_has_mouse_click_down_in_rect(in, + NK_BUTTON_LEFT, cursor, nk_true); + if (nk_input_is_mouse_hovering_rect(in, r)) + *state = NK_WIDGET_STATE_HOVERED; + + if (in && left_mouse_down && left_mouse_click_in_cursor) { + if (left_mouse_down && left_mouse_click_in_cursor) { + float ratio = NK_MAX(0, (float)(in->mouse.pos.x - cursor.x)) / (float)cursor.w; + value = (nk_size)NK_CLAMP(0, (float)max * ratio, (float)max); + in->mouse.buttons[NK_BUTTON_LEFT].clicked_pos.x = cursor.x + cursor.w/2.0f; + *state |= NK_WIDGET_STATE_ACTIVE; + } + } + /* set progressbar widget state */ + if (*state & NK_WIDGET_STATE_HOVER && !nk_input_is_mouse_prev_hovering_rect(in, r)) + *state |= NK_WIDGET_STATE_ENTERED; + else if (nk_input_is_mouse_prev_hovering_rect(in, r)) + *state |= NK_WIDGET_STATE_LEFT; + return value; +} +NK_LIB void +nk_draw_progress(struct nk_command_buffer *out, nk_flags state, + const struct nk_style_progress *style, const struct nk_rect *bounds, + const struct nk_rect *scursor, nk_size value, nk_size max) +{ + const struct nk_style_item *background; + const struct nk_style_item *cursor; + + NK_UNUSED(max); + NK_UNUSED(value); + + /* select correct colors/images to draw */ + if (state & NK_WIDGET_STATE_ACTIVED) { + background = &style->active; + cursor = &style->cursor_active; + } else if (state & NK_WIDGET_STATE_HOVER){ + background = &style->hover; + cursor = &style->cursor_hover; + } else { + background = &style->normal; + cursor = &style->cursor_normal; + } + + /* draw background */ + switch(background->type) { + case NK_STYLE_ITEM_IMAGE: + nk_draw_image(out, *bounds, &background->data.image, nk_white); + break; + case NK_STYLE_ITEM_NINE_SLICE: + nk_draw_nine_slice(out, *bounds, &background->data.slice, nk_white); + break; + case NK_STYLE_ITEM_COLOR: + nk_fill_rect(out, *bounds, style->rounding, background->data.color); + nk_stroke_rect(out, *bounds, style->rounding, style->border, style->border_color); + break; + } + + /* draw cursor */ + switch(cursor->type) { + case NK_STYLE_ITEM_IMAGE: + nk_draw_image(out, *scursor, &cursor->data.image, nk_white); + break; + case NK_STYLE_ITEM_NINE_SLICE: + nk_draw_nine_slice(out, *scursor, &cursor->data.slice, nk_white); + break; + case NK_STYLE_ITEM_COLOR: + nk_fill_rect(out, *scursor, style->rounding, cursor->data.color); + nk_stroke_rect(out, *scursor, style->rounding, style->border, style->border_color); + break; + } +} +NK_LIB nk_size +nk_do_progress(nk_flags *state, + struct nk_command_buffer *out, struct nk_rect bounds, + nk_size value, nk_size max, nk_bool modifiable, + const struct nk_style_progress *style, struct nk_input *in) +{ + float prog_scale; + nk_size prog_value; + struct nk_rect cursor; + + NK_ASSERT(style); + NK_ASSERT(out); + if (!out || !style) return 0; + + /* calculate progressbar cursor */ + cursor.w = NK_MAX(bounds.w, 2 * style->padding.x + 2 * style->border); + cursor.h = NK_MAX(bounds.h, 2 * style->padding.y + 2 * style->border); + cursor = nk_pad_rect(bounds, nk_vec2(style->padding.x + style->border, style->padding.y + style->border)); + prog_scale = (float)value / (float)max; + + /* update progressbar */ + prog_value = NK_MIN(value, max); + prog_value = nk_progress_behavior(state, in, bounds, cursor,max, prog_value, modifiable); + cursor.w = cursor.w * prog_scale; + + /* draw progressbar */ + if (style->draw_begin) style->draw_begin(out, style->userdata); + nk_draw_progress(out, *state, style, &bounds, &cursor, value, max); + if (style->draw_end) style->draw_end(out, style->userdata); + return prog_value; +} +NK_API nk_bool +nk_progress(struct nk_context *ctx, nk_size *cur, nk_size max, nk_bool is_modifyable) +{ + struct nk_window *win; + struct nk_panel *layout; + const struct nk_style *style; + struct nk_input *in; + + struct nk_rect bounds; + enum nk_widget_layout_states state; + nk_size old_value; + + NK_ASSERT(ctx); + NK_ASSERT(cur); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout || !cur) + return 0; + + win = ctx->current; + style = &ctx->style; + layout = win->layout; + state = nk_widget(&bounds, ctx); + if (!state) return 0; + + in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + old_value = *cur; + *cur = nk_do_progress(&ctx->last_widget_state, &win->buffer, bounds, + *cur, max, is_modifyable, &style->progress, in); + return (*cur != old_value); +} +NK_API nk_size +nk_prog(struct nk_context *ctx, nk_size cur, nk_size max, nk_bool modifyable) +{ + nk_progress(ctx, &cur, max, modifyable); + return cur; +} + + + + + +/* =============================================================== + * + * SCROLLBAR + * + * ===============================================================*/ +NK_LIB float +nk_scrollbar_behavior(nk_flags *state, struct nk_input *in, + int has_scrolling, const struct nk_rect *scroll, + const struct nk_rect *cursor, const struct nk_rect *empty0, + const struct nk_rect *empty1, float scroll_offset, + float target, float scroll_step, enum nk_orientation o) +{ + nk_flags ws = 0; + int left_mouse_down; + unsigned int left_mouse_clicked; + int left_mouse_click_in_cursor; + float scroll_delta; + + nk_widget_state_reset(state); + if (!in) return scroll_offset; + + left_mouse_down = in->mouse.buttons[NK_BUTTON_LEFT].down; + left_mouse_clicked = in->mouse.buttons[NK_BUTTON_LEFT].clicked; + left_mouse_click_in_cursor = nk_input_has_mouse_click_down_in_rect(in, + NK_BUTTON_LEFT, *cursor, nk_true); + if (nk_input_is_mouse_hovering_rect(in, *scroll)) + *state = NK_WIDGET_STATE_HOVERED; + + scroll_delta = (o == NK_VERTICAL) ? in->mouse.scroll_delta.y: in->mouse.scroll_delta.x; + if (left_mouse_down && left_mouse_click_in_cursor && !left_mouse_clicked) { + /* update cursor by mouse dragging */ + float pixel, delta; + *state = NK_WIDGET_STATE_ACTIVE; + if (o == NK_VERTICAL) { + float cursor_y; + pixel = in->mouse.delta.y; + delta = (pixel / scroll->h) * target; + scroll_offset = NK_CLAMP(0, scroll_offset + delta, target - scroll->h); + cursor_y = scroll->y + ((scroll_offset/target) * scroll->h); + in->mouse.buttons[NK_BUTTON_LEFT].clicked_pos.y = cursor_y + cursor->h/2.0f; + } else { + float cursor_x; + pixel = in->mouse.delta.x; + delta = (pixel / scroll->w) * target; + scroll_offset = NK_CLAMP(0, scroll_offset + delta, target - scroll->w); + cursor_x = scroll->x + ((scroll_offset/target) * scroll->w); + in->mouse.buttons[NK_BUTTON_LEFT].clicked_pos.x = cursor_x + cursor->w/2.0f; + } + } else if ((nk_input_is_key_pressed(in, NK_KEY_SCROLL_UP) && o == NK_VERTICAL && has_scrolling)|| + nk_button_behavior(&ws, *empty0, in, NK_BUTTON_DEFAULT)) { + /* scroll page up by click on empty space or shortcut */ + if (o == NK_VERTICAL) + scroll_offset = NK_MAX(0, scroll_offset - scroll->h); + else scroll_offset = NK_MAX(0, scroll_offset - scroll->w); + } else if ((nk_input_is_key_pressed(in, NK_KEY_SCROLL_DOWN) && o == NK_VERTICAL && has_scrolling) || + nk_button_behavior(&ws, *empty1, in, NK_BUTTON_DEFAULT)) { + /* scroll page down by click on empty space or shortcut */ + if (o == NK_VERTICAL) + scroll_offset = NK_MIN(scroll_offset + scroll->h, target - scroll->h); + else scroll_offset = NK_MIN(scroll_offset + scroll->w, target - scroll->w); + } else if (has_scrolling) { + if ((scroll_delta < 0 || (scroll_delta > 0))) { + /* update cursor by mouse scrolling */ + scroll_offset = scroll_offset + scroll_step * (-scroll_delta); + if (o == NK_VERTICAL) + scroll_offset = NK_CLAMP(0, scroll_offset, target - scroll->h); + else scroll_offset = NK_CLAMP(0, scroll_offset, target - scroll->w); + } else if (nk_input_is_key_pressed(in, NK_KEY_SCROLL_START)) { + /* update cursor to the beginning */ + if (o == NK_VERTICAL) scroll_offset = 0; + } else if (nk_input_is_key_pressed(in, NK_KEY_SCROLL_END)) { + /* update cursor to the end */ + if (o == NK_VERTICAL) scroll_offset = target - scroll->h; + } + } + if (*state & NK_WIDGET_STATE_HOVER && !nk_input_is_mouse_prev_hovering_rect(in, *scroll)) + *state |= NK_WIDGET_STATE_ENTERED; + else if (nk_input_is_mouse_prev_hovering_rect(in, *scroll)) + *state |= NK_WIDGET_STATE_LEFT; + return scroll_offset; +} +NK_LIB void +nk_draw_scrollbar(struct nk_command_buffer *out, nk_flags state, + const struct nk_style_scrollbar *style, const struct nk_rect *bounds, + const struct nk_rect *scroll) +{ + const struct nk_style_item *background; + const struct nk_style_item *cursor; + + /* select correct colors/images to draw */ + if (state & NK_WIDGET_STATE_ACTIVED) { + background = &style->active; + cursor = &style->cursor_active; + } else if (state & NK_WIDGET_STATE_HOVER) { + background = &style->hover; + cursor = &style->cursor_hover; + } else { + background = &style->normal; + cursor = &style->cursor_normal; + } + + /* draw background */ + switch (background->type) { + case NK_STYLE_ITEM_IMAGE: + nk_draw_image(out, *bounds, &background->data.image, nk_white); + break; + case NK_STYLE_ITEM_NINE_SLICE: + nk_draw_nine_slice(out, *bounds, &background->data.slice, nk_white); + break; + case NK_STYLE_ITEM_COLOR: + nk_fill_rect(out, *bounds, style->rounding, background->data.color); + nk_stroke_rect(out, *bounds, style->rounding, style->border, style->border_color); + break; + } + + /* draw cursor */ + switch (cursor->type) { + case NK_STYLE_ITEM_IMAGE: + nk_draw_image(out, *scroll, &cursor->data.image, nk_white); + break; + case NK_STYLE_ITEM_NINE_SLICE: + nk_draw_nine_slice(out, *scroll, &cursor->data.slice, nk_white); + break; + case NK_STYLE_ITEM_COLOR: + nk_fill_rect(out, *scroll, style->rounding_cursor, cursor->data.color); + nk_stroke_rect(out, *scroll, style->rounding_cursor, style->border_cursor, style->cursor_border_color); + break; + } +} +NK_LIB float +nk_do_scrollbarv(nk_flags *state, + struct nk_command_buffer *out, struct nk_rect scroll, int has_scrolling, + float offset, float target, float step, float button_pixel_inc, + const struct nk_style_scrollbar *style, struct nk_input *in, + const struct nk_user_font *font) +{ + struct nk_rect empty_north; + struct nk_rect empty_south; + struct nk_rect cursor; + + float scroll_step; + float scroll_offset; + float scroll_off; + float scroll_ratio; + + NK_ASSERT(out); + NK_ASSERT(style); + NK_ASSERT(state); + if (!out || !style) return 0; + + scroll.w = NK_MAX(scroll.w, 1); + scroll.h = NK_MAX(scroll.h, 0); + if (target <= scroll.h) return 0; + + /* optional scrollbar buttons */ + if (style->show_buttons) { + nk_flags ws; + float scroll_h; + struct nk_rect button; + + button.x = scroll.x; + button.w = scroll.w; + button.h = scroll.w; + + scroll_h = NK_MAX(scroll.h - 2 * button.h,0); + scroll_step = NK_MIN(step, button_pixel_inc); + + /* decrement button */ + button.y = scroll.y; + if (nk_do_button_symbol(&ws, out, button, style->dec_symbol, + NK_BUTTON_REPEATER, &style->dec_button, in, font)) + offset = offset - scroll_step; + + /* increment button */ + button.y = scroll.y + scroll.h - button.h; + if (nk_do_button_symbol(&ws, out, button, style->inc_symbol, + NK_BUTTON_REPEATER, &style->inc_button, in, font)) + offset = offset + scroll_step; + + scroll.y = scroll.y + button.h; + scroll.h = scroll_h; + } + + /* calculate scrollbar constants */ + scroll_step = NK_MIN(step, scroll.h); + scroll_offset = NK_CLAMP(0, offset, target - scroll.h); + scroll_ratio = scroll.h / target; + scroll_off = scroll_offset / target; + + /* calculate scrollbar cursor bounds */ + cursor.h = NK_MAX((scroll_ratio * scroll.h) - (2*style->border + 2*style->padding.y), 0); + cursor.y = scroll.y + (scroll_off * scroll.h) + style->border + style->padding.y; + cursor.w = scroll.w - (2 * style->border + 2 * style->padding.x); + cursor.x = scroll.x + style->border + style->padding.x; + + /* calculate empty space around cursor */ + empty_north.x = scroll.x; + empty_north.y = scroll.y; + empty_north.w = scroll.w; + empty_north.h = NK_MAX(cursor.y - scroll.y, 0); + + empty_south.x = scroll.x; + empty_south.y = cursor.y + cursor.h; + empty_south.w = scroll.w; + empty_south.h = NK_MAX((scroll.y + scroll.h) - (cursor.y + cursor.h), 0); + + /* update scrollbar */ + scroll_offset = nk_scrollbar_behavior(state, in, has_scrolling, &scroll, &cursor, + &empty_north, &empty_south, scroll_offset, target, scroll_step, NK_VERTICAL); + scroll_off = scroll_offset / target; + cursor.y = scroll.y + (scroll_off * scroll.h) + style->border_cursor + style->padding.y; + + /* draw scrollbar */ + if (style->draw_begin) style->draw_begin(out, style->userdata); + nk_draw_scrollbar(out, *state, style, &scroll, &cursor); + if (style->draw_end) style->draw_end(out, style->userdata); + return scroll_offset; +} +NK_LIB float +nk_do_scrollbarh(nk_flags *state, + struct nk_command_buffer *out, struct nk_rect scroll, int has_scrolling, + float offset, float target, float step, float button_pixel_inc, + const struct nk_style_scrollbar *style, struct nk_input *in, + const struct nk_user_font *font) +{ + struct nk_rect cursor; + struct nk_rect empty_west; + struct nk_rect empty_east; + + float scroll_step; + float scroll_offset; + float scroll_off; + float scroll_ratio; + + NK_ASSERT(out); + NK_ASSERT(style); + if (!out || !style) return 0; + + /* scrollbar background */ + scroll.h = NK_MAX(scroll.h, 1); + scroll.w = NK_MAX(scroll.w, 2 * scroll.h); + if (target <= scroll.w) return 0; + + /* optional scrollbar buttons */ + if (style->show_buttons) { + nk_flags ws; + float scroll_w; + struct nk_rect button; + button.y = scroll.y; + button.w = scroll.h; + button.h = scroll.h; + + scroll_w = scroll.w - 2 * button.w; + scroll_step = NK_MIN(step, button_pixel_inc); + + /* decrement button */ + button.x = scroll.x; + if (nk_do_button_symbol(&ws, out, button, style->dec_symbol, + NK_BUTTON_REPEATER, &style->dec_button, in, font)) + offset = offset - scroll_step; + + /* increment button */ + button.x = scroll.x + scroll.w - button.w; + if (nk_do_button_symbol(&ws, out, button, style->inc_symbol, + NK_BUTTON_REPEATER, &style->inc_button, in, font)) + offset = offset + scroll_step; + + scroll.x = scroll.x + button.w; + scroll.w = scroll_w; + } + + /* calculate scrollbar constants */ + scroll_step = NK_MIN(step, scroll.w); + scroll_offset = NK_CLAMP(0, offset, target - scroll.w); + scroll_ratio = scroll.w / target; + scroll_off = scroll_offset / target; + + /* calculate cursor bounds */ + cursor.w = (scroll_ratio * scroll.w) - (2*style->border + 2*style->padding.x); + cursor.x = scroll.x + (scroll_off * scroll.w) + style->border + style->padding.x; + cursor.h = scroll.h - (2 * style->border + 2 * style->padding.y); + cursor.y = scroll.y + style->border + style->padding.y; + + /* calculate empty space around cursor */ + empty_west.x = scroll.x; + empty_west.y = scroll.y; + empty_west.w = cursor.x - scroll.x; + empty_west.h = scroll.h; + + empty_east.x = cursor.x + cursor.w; + empty_east.y = scroll.y; + empty_east.w = (scroll.x + scroll.w) - (cursor.x + cursor.w); + empty_east.h = scroll.h; + + /* update scrollbar */ + scroll_offset = nk_scrollbar_behavior(state, in, has_scrolling, &scroll, &cursor, + &empty_west, &empty_east, scroll_offset, target, scroll_step, NK_HORIZONTAL); + scroll_off = scroll_offset / target; + cursor.x = scroll.x + (scroll_off * scroll.w); + + /* draw scrollbar */ + if (style->draw_begin) style->draw_begin(out, style->userdata); + nk_draw_scrollbar(out, *state, style, &scroll, &cursor); + if (style->draw_end) style->draw_end(out, style->userdata); + return scroll_offset; +} + + + + + +/* =============================================================== + * + * TEXT EDITOR + * + * ===============================================================*/ +/* stb_textedit.h - v1.8 - public domain - Sean Barrett */ +struct nk_text_find { + float x,y; /* position of n'th character */ + float height; /* height of line */ + int first_char, length; /* first char of row, and length */ + int prev_first; /*_ first char of previous row */ +}; + +struct nk_text_edit_row { + float x0,x1; + /* starting x location, end x location (allows for align=right, etc) */ + float baseline_y_delta; + /* position of baseline relative to previous row's baseline*/ + float ymin,ymax; + /* height of row above and below baseline */ + int num_chars; +}; + +/* forward declarations */ +NK_INTERN void nk_textedit_makeundo_delete(struct nk_text_edit*, int, int); +NK_INTERN void nk_textedit_makeundo_insert(struct nk_text_edit*, int, int); +NK_INTERN void nk_textedit_makeundo_replace(struct nk_text_edit*, int, int, int); +#define NK_TEXT_HAS_SELECTION(s) ((s)->select_start != (s)->select_end) + +NK_INTERN float +nk_textedit_get_width(const struct nk_text_edit *edit, int line_start, int char_id, + const struct nk_user_font *font) +{ + int len = 0; + nk_rune unicode = 0; + const char *str = nk_str_at_const(&edit->string, line_start + char_id, &unicode, &len); + return font->width(font->userdata, font->height, str, len); +} +NK_INTERN void +nk_textedit_layout_row(struct nk_text_edit_row *r, struct nk_text_edit *edit, + int line_start_id, float row_height, const struct nk_user_font *font) +{ + int l; + int glyphs = 0; + nk_rune unicode; + const char *remaining; + int len = nk_str_len_char(&edit->string); + const char *end = nk_str_get_const(&edit->string) + len; + const char *text = nk_str_at_const(&edit->string, line_start_id, &unicode, &l); + const struct nk_vec2 size = nk_text_calculate_text_bounds(font, + text, (int)(end - text), row_height, &remaining, 0, &glyphs, NK_STOP_ON_NEW_LINE); + + r->x0 = 0.0f; + r->x1 = size.x; + r->baseline_y_delta = size.y; + r->ymin = 0.0f; + r->ymax = size.y; + r->num_chars = glyphs; +} +NK_INTERN int +nk_textedit_locate_coord(struct nk_text_edit *edit, float x, float y, + const struct nk_user_font *font, float row_height) +{ + struct nk_text_edit_row r; + int n = edit->string.len; + float base_y = 0, prev_x; + int i=0, k; + + r.x0 = r.x1 = 0; + r.ymin = r.ymax = 0; + r.num_chars = 0; + + /* search rows to find one that straddles 'y' */ + while (i < n) { + nk_textedit_layout_row(&r, edit, i, row_height, font); + if (r.num_chars <= 0) + return n; + + if (i==0 && y < base_y + r.ymin) + return 0; + + if (y < base_y + r.ymax) + break; + + i += r.num_chars; + base_y += r.baseline_y_delta; + } + + /* below all text, return 'after' last character */ + if (i >= n) + return n; + + /* check if it's before the beginning of the line */ + if (x < r.x0) + return i; + + /* check if it's before the end of the line */ + if (x < r.x1) { + /* search characters in row for one that straddles 'x' */ + k = i; + prev_x = r.x0; + for (i=0; i < r.num_chars; ++i) { + float w = nk_textedit_get_width(edit, k, i, font); + if (x < prev_x+w) { + if (x < prev_x+w/2) + return k+i; + else return k+i+1; + } + prev_x += w; + } + /* shouldn't happen, but if it does, fall through to end-of-line case */ + } + + /* if the last character is a newline, return that. + * otherwise return 'after' the last character */ + if (nk_str_rune_at(&edit->string, i+r.num_chars-1) == '\n') + return i+r.num_chars-1; + else return i+r.num_chars; +} +NK_LIB void +nk_textedit_click(struct nk_text_edit *state, float x, float y, + const struct nk_user_font *font, float row_height) +{ + /* API click: on mouse down, move the cursor to the clicked location, + * and reset the selection */ + state->cursor = nk_textedit_locate_coord(state, x, y, font, row_height); + state->select_start = state->cursor; + state->select_end = state->cursor; + state->has_preferred_x = 0; +} +NK_LIB void +nk_textedit_drag(struct nk_text_edit *state, float x, float y, + const struct nk_user_font *font, float row_height) +{ + /* API drag: on mouse drag, move the cursor and selection endpoint + * to the clicked location */ + int p = nk_textedit_locate_coord(state, x, y, font, row_height); + if (state->select_start == state->select_end) + state->select_start = state->cursor; + state->cursor = state->select_end = p; +} +NK_INTERN void +nk_textedit_find_charpos(struct nk_text_find *find, struct nk_text_edit *state, + int n, int single_line, const struct nk_user_font *font, float row_height) +{ + /* find the x/y location of a character, and remember info about the previous + * row in case we get a move-up event (for page up, we'll have to rescan) */ + struct nk_text_edit_row r; + int prev_start = 0; + int z = state->string.len; + int i=0, first; + + nk_zero_struct(r); + if (n == z) { + /* if it's at the end, then find the last line -- simpler than trying to + explicitly handle this case in the regular code */ + nk_textedit_layout_row(&r, state, 0, row_height, font); + if (single_line) { + find->first_char = 0; + find->length = z; + } else { + while (i < z) { + prev_start = i; + i += r.num_chars; + nk_textedit_layout_row(&r, state, i, row_height, font); + } + + find->first_char = i; + find->length = r.num_chars; + } + find->x = r.x1; + find->y = r.ymin; + find->height = r.ymax - r.ymin; + find->prev_first = prev_start; + return; + } + + /* search rows to find the one that straddles character n */ + find->y = 0; + + for(;;) { + nk_textedit_layout_row(&r, state, i, row_height, font); + if (n < i + r.num_chars) break; + prev_start = i; + i += r.num_chars; + find->y += r.baseline_y_delta; + } + + find->first_char = first = i; + find->length = r.num_chars; + find->height = r.ymax - r.ymin; + find->prev_first = prev_start; + + /* now scan to find xpos */ + find->x = r.x0; + for (i=0; first+i < n; ++i) + find->x += nk_textedit_get_width(state, first, i, font); +} +NK_INTERN void +nk_textedit_clamp(struct nk_text_edit *state) +{ + /* make the selection/cursor state valid if client altered the string */ + int n = state->string.len; + if (NK_TEXT_HAS_SELECTION(state)) { + if (state->select_start > n) state->select_start = n; + if (state->select_end > n) state->select_end = n; + /* if clamping forced them to be equal, move the cursor to match */ + if (state->select_start == state->select_end) + state->cursor = state->select_start; + } + if (state->cursor > n) state->cursor = n; +} +NK_API void +nk_textedit_delete(struct nk_text_edit *state, int where, int len) +{ + /* delete characters while updating undo */ + nk_textedit_makeundo_delete(state, where, len); + nk_str_delete_runes(&state->string, where, len); + state->has_preferred_x = 0; +} +NK_API void +nk_textedit_delete_selection(struct nk_text_edit *state) +{ + /* delete the section */ + nk_textedit_clamp(state); + if (NK_TEXT_HAS_SELECTION(state)) { + if (state->select_start < state->select_end) { + nk_textedit_delete(state, state->select_start, + state->select_end - state->select_start); + state->select_end = state->cursor = state->select_start; + } else { + nk_textedit_delete(state, state->select_end, + state->select_start - state->select_end); + state->select_start = state->cursor = state->select_end; + } + state->has_preferred_x = 0; + } +} +NK_INTERN void +nk_textedit_sortselection(struct nk_text_edit *state) +{ + /* canonicalize the selection so start <= end */ + if (state->select_end < state->select_start) { + int temp = state->select_end; + state->select_end = state->select_start; + state->select_start = temp; + } +} +NK_INTERN void +nk_textedit_move_to_first(struct nk_text_edit *state) +{ + /* move cursor to first character of selection */ + if (NK_TEXT_HAS_SELECTION(state)) { + nk_textedit_sortselection(state); + state->cursor = state->select_start; + state->select_end = state->select_start; + state->has_preferred_x = 0; + } +} +NK_INTERN void +nk_textedit_move_to_last(struct nk_text_edit *state) +{ + /* move cursor to last character of selection */ + if (NK_TEXT_HAS_SELECTION(state)) { + nk_textedit_sortselection(state); + nk_textedit_clamp(state); + state->cursor = state->select_end; + state->select_start = state->select_end; + state->has_preferred_x = 0; + } +} +NK_INTERN int +nk_is_word_boundary( struct nk_text_edit *state, int idx) +{ + int len; + nk_rune c; + if (idx <= 0) return 1; + if (!nk_str_at_rune(&state->string, idx, &c, &len)) return 1; + return (c == ' ' || c == '\t' ||c == 0x3000 || c == ',' || c == ';' || + c == '(' || c == ')' || c == '{' || c == '}' || c == '[' || c == ']' || + c == '|'); +} +NK_INTERN int +nk_textedit_move_to_word_previous(struct nk_text_edit *state) +{ + int c = state->cursor - 1; + while( c >= 0 && !nk_is_word_boundary(state, c)) + --c; + + if( c < 0 ) + c = 0; + + return c; +} +NK_INTERN int +nk_textedit_move_to_word_next(struct nk_text_edit *state) +{ + const int len = state->string.len; + int c = state->cursor+1; + while( c < len && !nk_is_word_boundary(state, c)) + ++c; + + if( c > len ) + c = len; + + return c; +} +NK_INTERN void +nk_textedit_prep_selection_at_cursor(struct nk_text_edit *state) +{ + /* update selection and cursor to match each other */ + if (!NK_TEXT_HAS_SELECTION(state)) + state->select_start = state->select_end = state->cursor; + else state->cursor = state->select_end; +} +NK_API nk_bool +nk_textedit_cut(struct nk_text_edit *state) +{ + /* API cut: delete selection */ + if (state->mode == NK_TEXT_EDIT_MODE_VIEW) + return 0; + if (NK_TEXT_HAS_SELECTION(state)) { + nk_textedit_delete_selection(state); /* implicitly clamps */ + state->has_preferred_x = 0; + return 1; + } + return 0; +} +NK_API nk_bool +nk_textedit_paste(struct nk_text_edit *state, char const *ctext, int len) +{ + /* API paste: replace existing selection with passed-in text */ + int glyphs; + const char *text = (const char *) ctext; + if (state->mode == NK_TEXT_EDIT_MODE_VIEW) return 0; + + /* if there's a selection, the paste should delete it */ + nk_textedit_clamp(state); + nk_textedit_delete_selection(state); + + /* try to insert the characters */ + glyphs = nk_utf_len(ctext, len); + if (nk_str_insert_text_char(&state->string, state->cursor, text, len)) { + nk_textedit_makeundo_insert(state, state->cursor, glyphs); + state->cursor += len; + state->has_preferred_x = 0; + return 1; + } + /* remove the undo since we didn't actually insert the characters */ + if (state->undo.undo_point) + --state->undo.undo_point; + return 0; +} +NK_API void +nk_textedit_text(struct nk_text_edit *state, const char *text, int total_len) +{ + nk_rune unicode; + int glyph_len; + int text_len = 0; + + NK_ASSERT(state); + NK_ASSERT(text); + if (!text || !total_len || state->mode == NK_TEXT_EDIT_MODE_VIEW) return; + + glyph_len = nk_utf_decode(text, &unicode, total_len); + while ((text_len < total_len) && glyph_len) + { + /* don't insert a backward delete, just process the event */ + if (unicode == 127) goto next; + /* can't add newline in single-line mode */ + if (unicode == '\n' && state->single_line) goto next; + /* filter incoming text */ + if (state->filter && !state->filter(state, unicode)) goto next; + + if (!NK_TEXT_HAS_SELECTION(state) && + state->cursor < state->string.len) + { + if (state->mode == NK_TEXT_EDIT_MODE_REPLACE) { + nk_textedit_makeundo_replace(state, state->cursor, 1, 1); + nk_str_delete_runes(&state->string, state->cursor, 1); + } + if (nk_str_insert_text_utf8(&state->string, state->cursor, + text+text_len, 1)) + { + ++state->cursor; + state->has_preferred_x = 0; + } + } else { + nk_textedit_delete_selection(state); /* implicitly clamps */ + if (nk_str_insert_text_utf8(&state->string, state->cursor, + text+text_len, 1)) + { + nk_textedit_makeundo_insert(state, state->cursor, 1); + state->cursor = NK_MIN(state->cursor + 1, state->string.len); + state->has_preferred_x = 0; + } + } + next: + text_len += glyph_len; + glyph_len = nk_utf_decode(text + text_len, &unicode, total_len-text_len); + } +} +NK_LIB void +nk_textedit_key(struct nk_text_edit *state, enum nk_keys key, int shift_mod, + const struct nk_user_font *font, float row_height) +{ +retry: + switch (key) + { + case NK_KEY_NONE: + case NK_KEY_CTRL: + case NK_KEY_ENTER: + case NK_KEY_SHIFT: + case NK_KEY_TAB: + case NK_KEY_COPY: + case NK_KEY_CUT: + case NK_KEY_PASTE: + case NK_KEY_MAX: + default: break; + case NK_KEY_TEXT_UNDO: + nk_textedit_undo(state); + state->has_preferred_x = 0; + break; + + case NK_KEY_TEXT_REDO: + nk_textedit_redo(state); + state->has_preferred_x = 0; + break; + + case NK_KEY_TEXT_SELECT_ALL: + nk_textedit_select_all(state); + state->has_preferred_x = 0; + break; + + case NK_KEY_TEXT_INSERT_MODE: + if (state->mode == NK_TEXT_EDIT_MODE_VIEW) + state->mode = NK_TEXT_EDIT_MODE_INSERT; + break; + case NK_KEY_TEXT_REPLACE_MODE: + if (state->mode == NK_TEXT_EDIT_MODE_VIEW) + state->mode = NK_TEXT_EDIT_MODE_REPLACE; + break; + case NK_KEY_TEXT_RESET_MODE: + if (state->mode == NK_TEXT_EDIT_MODE_INSERT || + state->mode == NK_TEXT_EDIT_MODE_REPLACE) + state->mode = NK_TEXT_EDIT_MODE_VIEW; + break; + + case NK_KEY_LEFT: + if (shift_mod) { + nk_textedit_clamp(state); + nk_textedit_prep_selection_at_cursor(state); + /* move selection left */ + if (state->select_end > 0) + --state->select_end; + state->cursor = state->select_end; + state->has_preferred_x = 0; + } else { + /* if currently there's a selection, + * move cursor to start of selection */ + if (NK_TEXT_HAS_SELECTION(state)) + nk_textedit_move_to_first(state); + else if (state->cursor > 0) + --state->cursor; + state->has_preferred_x = 0; + } break; + + case NK_KEY_RIGHT: + if (shift_mod) { + nk_textedit_prep_selection_at_cursor(state); + /* move selection right */ + ++state->select_end; + nk_textedit_clamp(state); + state->cursor = state->select_end; + state->has_preferred_x = 0; + } else { + /* if currently there's a selection, + * move cursor to end of selection */ + if (NK_TEXT_HAS_SELECTION(state)) + nk_textedit_move_to_last(state); + else ++state->cursor; + nk_textedit_clamp(state); + state->has_preferred_x = 0; + } break; + + case NK_KEY_TEXT_WORD_LEFT: + if (shift_mod) { + if( !NK_TEXT_HAS_SELECTION( state ) ) + nk_textedit_prep_selection_at_cursor(state); + state->cursor = nk_textedit_move_to_word_previous(state); + state->select_end = state->cursor; + nk_textedit_clamp(state ); + } else { + if (NK_TEXT_HAS_SELECTION(state)) + nk_textedit_move_to_first(state); + else { + state->cursor = nk_textedit_move_to_word_previous(state); + nk_textedit_clamp(state ); + } + } break; + + case NK_KEY_TEXT_WORD_RIGHT: + if (shift_mod) { + if( !NK_TEXT_HAS_SELECTION( state ) ) + nk_textedit_prep_selection_at_cursor(state); + state->cursor = nk_textedit_move_to_word_next(state); + state->select_end = state->cursor; + nk_textedit_clamp(state); + } else { + if (NK_TEXT_HAS_SELECTION(state)) + nk_textedit_move_to_last(state); + else { + state->cursor = nk_textedit_move_to_word_next(state); + nk_textedit_clamp(state ); + } + } break; + + case NK_KEY_DOWN: { + struct nk_text_find find; + struct nk_text_edit_row row; + int i, sel = shift_mod; + + if (state->single_line) { + /* on windows, up&down in single-line behave like left&right */ + key = NK_KEY_RIGHT; + goto retry; + } + + if (sel) + nk_textedit_prep_selection_at_cursor(state); + else if (NK_TEXT_HAS_SELECTION(state)) + nk_textedit_move_to_last(state); + + /* compute current position of cursor point */ + nk_textedit_clamp(state); + nk_textedit_find_charpos(&find, state, state->cursor, state->single_line, + font, row_height); + + /* now find character position down a row */ + if (find.length) + { + float x; + float goal_x = state->has_preferred_x ? state->preferred_x : find.x; + int start = find.first_char + find.length; + + state->cursor = start; + nk_textedit_layout_row(&row, state, state->cursor, row_height, font); + x = row.x0; + + for (i=0; i < row.num_chars && x < row.x1; ++i) { + float dx = nk_textedit_get_width(state, start, i, font); + x += dx; + if (x > goal_x) + break; + ++state->cursor; + } + nk_textedit_clamp(state); + + state->has_preferred_x = 1; + state->preferred_x = goal_x; + if (sel) + state->select_end = state->cursor; + } + } break; + + case NK_KEY_UP: { + struct nk_text_find find; + struct nk_text_edit_row row; + int i, sel = shift_mod; + + if (state->single_line) { + /* on windows, up&down become left&right */ + key = NK_KEY_LEFT; + goto retry; + } + + if (sel) + nk_textedit_prep_selection_at_cursor(state); + else if (NK_TEXT_HAS_SELECTION(state)) + nk_textedit_move_to_first(state); + + /* compute current position of cursor point */ + nk_textedit_clamp(state); + nk_textedit_find_charpos(&find, state, state->cursor, state->single_line, + font, row_height); + + /* can only go up if there's a previous row */ + if (find.prev_first != find.first_char) { + /* now find character position up a row */ + float x; + float goal_x = state->has_preferred_x ? state->preferred_x : find.x; + + state->cursor = find.prev_first; + nk_textedit_layout_row(&row, state, state->cursor, row_height, font); + x = row.x0; + + for (i=0; i < row.num_chars && x < row.x1; ++i) { + float dx = nk_textedit_get_width(state, find.prev_first, i, font); + x += dx; + if (x > goal_x) + break; + ++state->cursor; + } + nk_textedit_clamp(state); + + state->has_preferred_x = 1; + state->preferred_x = goal_x; + if (sel) state->select_end = state->cursor; + } + } break; + + case NK_KEY_DEL: + if (state->mode == NK_TEXT_EDIT_MODE_VIEW) + break; + if (NK_TEXT_HAS_SELECTION(state)) + nk_textedit_delete_selection(state); + else { + int n = state->string.len; + if (state->cursor < n) + nk_textedit_delete(state, state->cursor, 1); + } + state->has_preferred_x = 0; + break; + + case NK_KEY_BACKSPACE: + if (state->mode == NK_TEXT_EDIT_MODE_VIEW) + break; + if (NK_TEXT_HAS_SELECTION(state)) + nk_textedit_delete_selection(state); + else { + nk_textedit_clamp(state); + if (state->cursor > 0) { + nk_textedit_delete(state, state->cursor-1, 1); + --state->cursor; + } + } + state->has_preferred_x = 0; + break; + + case NK_KEY_TEXT_START: + if (shift_mod) { + nk_textedit_prep_selection_at_cursor(state); + state->cursor = state->select_end = 0; + state->has_preferred_x = 0; + } else { + state->cursor = state->select_start = state->select_end = 0; + state->has_preferred_x = 0; + } + break; + + case NK_KEY_TEXT_END: + if (shift_mod) { + nk_textedit_prep_selection_at_cursor(state); + state->cursor = state->select_end = state->string.len; + state->has_preferred_x = 0; + } else { + state->cursor = state->string.len; + state->select_start = state->select_end = 0; + state->has_preferred_x = 0; + } + break; + + case NK_KEY_TEXT_LINE_START: { + if (shift_mod) { + struct nk_text_find find; + nk_textedit_clamp(state); + nk_textedit_prep_selection_at_cursor(state); + if (state->string.len && state->cursor == state->string.len) + --state->cursor; + nk_textedit_find_charpos(&find, state,state->cursor, state->single_line, + font, row_height); + state->cursor = state->select_end = find.first_char; + state->has_preferred_x = 0; + } else { + struct nk_text_find find; + if (state->string.len && state->cursor == state->string.len) + --state->cursor; + nk_textedit_clamp(state); + nk_textedit_move_to_first(state); + nk_textedit_find_charpos(&find, state, state->cursor, state->single_line, + font, row_height); + state->cursor = find.first_char; + state->has_preferred_x = 0; + } + } break; + + case NK_KEY_TEXT_LINE_END: { + if (shift_mod) { + struct nk_text_find find; + nk_textedit_clamp(state); + nk_textedit_prep_selection_at_cursor(state); + nk_textedit_find_charpos(&find, state, state->cursor, state->single_line, + font, row_height); + state->has_preferred_x = 0; + state->cursor = find.first_char + find.length; + if (find.length > 0 && nk_str_rune_at(&state->string, state->cursor-1) == '\n') + --state->cursor; + state->select_end = state->cursor; + } else { + struct nk_text_find find; + nk_textedit_clamp(state); + nk_textedit_move_to_first(state); + nk_textedit_find_charpos(&find, state, state->cursor, state->single_line, + font, row_height); + + state->has_preferred_x = 0; + state->cursor = find.first_char + find.length; + if (find.length > 0 && nk_str_rune_at(&state->string, state->cursor-1) == '\n') + --state->cursor; + }} break; + } +} +NK_INTERN void +nk_textedit_flush_redo(struct nk_text_undo_state *state) +{ + state->redo_point = NK_TEXTEDIT_UNDOSTATECOUNT; + state->redo_char_point = NK_TEXTEDIT_UNDOCHARCOUNT; +} +NK_INTERN void +nk_textedit_discard_undo(struct nk_text_undo_state *state) +{ + /* discard the oldest entry in the undo list */ + if (state->undo_point > 0) { + /* if the 0th undo state has characters, clean those up */ + if (state->undo_rec[0].char_storage >= 0) { + int n = state->undo_rec[0].insert_length, i; + /* delete n characters from all other records */ + state->undo_char_point = (short)(state->undo_char_point - n); + NK_MEMCPY(state->undo_char, state->undo_char + n, + (nk_size)state->undo_char_point*sizeof(nk_rune)); + for (i=0; i < state->undo_point; ++i) { + if (state->undo_rec[i].char_storage >= 0) + state->undo_rec[i].char_storage = (short) + (state->undo_rec[i].char_storage - n); + } + } + --state->undo_point; + NK_MEMCPY(state->undo_rec, state->undo_rec+1, + (nk_size)((nk_size)state->undo_point * sizeof(state->undo_rec[0]))); + } +} +NK_INTERN void +nk_textedit_discard_redo(struct nk_text_undo_state *state) +{ +/* discard the oldest entry in the redo list--it's bad if this + ever happens, but because undo & redo have to store the actual + characters in different cases, the redo character buffer can + fill up even though the undo buffer didn't */ + nk_size num; + int k = NK_TEXTEDIT_UNDOSTATECOUNT-1; + if (state->redo_point <= k) { + /* if the k'th undo state has characters, clean those up */ + if (state->undo_rec[k].char_storage >= 0) { + int n = state->undo_rec[k].insert_length, i; + /* delete n characters from all other records */ + state->redo_char_point = (short)(state->redo_char_point + n); + num = (nk_size)(NK_TEXTEDIT_UNDOCHARCOUNT - state->redo_char_point); + NK_MEMCPY(state->undo_char + state->redo_char_point, + state->undo_char + state->redo_char_point-n, num * sizeof(char)); + for (i = state->redo_point; i < k; ++i) { + if (state->undo_rec[i].char_storage >= 0) { + state->undo_rec[i].char_storage = (short) + (state->undo_rec[i].char_storage + n); + } + } + } + ++state->redo_point; + num = (nk_size)(NK_TEXTEDIT_UNDOSTATECOUNT - state->redo_point); + if (num) NK_MEMCPY(state->undo_rec + state->redo_point-1, + state->undo_rec + state->redo_point, num * sizeof(state->undo_rec[0])); + } +} +NK_INTERN struct nk_text_undo_record* +nk_textedit_create_undo_record(struct nk_text_undo_state *state, int numchars) +{ + /* any time we create a new undo record, we discard redo*/ + nk_textedit_flush_redo(state); + + /* if we have no free records, we have to make room, + * by sliding the existing records down */ + if (state->undo_point == NK_TEXTEDIT_UNDOSTATECOUNT) + nk_textedit_discard_undo(state); + + /* if the characters to store won't possibly fit in the buffer, + * we can't undo */ + if (numchars > NK_TEXTEDIT_UNDOCHARCOUNT) { + state->undo_point = 0; + state->undo_char_point = 0; + return 0; + } + + /* if we don't have enough free characters in the buffer, + * we have to make room */ + while (state->undo_char_point + numchars > NK_TEXTEDIT_UNDOCHARCOUNT) + nk_textedit_discard_undo(state); + return &state->undo_rec[state->undo_point++]; +} +NK_INTERN nk_rune* +nk_textedit_createundo(struct nk_text_undo_state *state, int pos, + int insert_len, int delete_len) +{ + struct nk_text_undo_record *r = nk_textedit_create_undo_record(state, insert_len); + if (r == 0) + return 0; + + r->where = pos; + r->insert_length = (short) insert_len; + r->delete_length = (short) delete_len; + + if (insert_len == 0) { + r->char_storage = -1; + return 0; + } else { + r->char_storage = state->undo_char_point; + state->undo_char_point = (short)(state->undo_char_point + insert_len); + return &state->undo_char[r->char_storage]; + } +} +NK_API void +nk_textedit_undo(struct nk_text_edit *state) +{ + struct nk_text_undo_state *s = &state->undo; + struct nk_text_undo_record u, *r; + if (s->undo_point == 0) + return; + + /* we need to do two things: apply the undo record, and create a redo record */ + u = s->undo_rec[s->undo_point-1]; + r = &s->undo_rec[s->redo_point-1]; + r->char_storage = -1; + + r->insert_length = u.delete_length; + r->delete_length = u.insert_length; + r->where = u.where; + + if (u.delete_length) + { + /* if the undo record says to delete characters, then the redo record will + need to re-insert the characters that get deleted, so we need to store + them. + there are three cases: + - there's enough room to store the characters + - characters stored for *redoing* don't leave room for redo + - characters stored for *undoing* don't leave room for redo + if the last is true, we have to bail */ + if (s->undo_char_point + u.delete_length >= NK_TEXTEDIT_UNDOCHARCOUNT) { + /* the undo records take up too much character space; there's no space + * to store the redo characters */ + r->insert_length = 0; + } else { + int i; + /* there's definitely room to store the characters eventually */ + while (s->undo_char_point + u.delete_length > s->redo_char_point) { + /* there's currently not enough room, so discard a redo record */ + nk_textedit_discard_redo(s); + /* should never happen: */ + if (s->redo_point == NK_TEXTEDIT_UNDOSTATECOUNT) + return; + } + + r = &s->undo_rec[s->redo_point-1]; + r->char_storage = (short)(s->redo_char_point - u.delete_length); + s->redo_char_point = (short)(s->redo_char_point - u.delete_length); + + /* now save the characters */ + for (i=0; i < u.delete_length; ++i) + s->undo_char[r->char_storage + i] = + nk_str_rune_at(&state->string, u.where + i); + } + /* now we can carry out the deletion */ + nk_str_delete_runes(&state->string, u.where, u.delete_length); + } + + /* check type of recorded action: */ + if (u.insert_length) { + /* easy case: was a deletion, so we need to insert n characters */ + nk_str_insert_text_runes(&state->string, u.where, + &s->undo_char[u.char_storage], u.insert_length); + s->undo_char_point = (short)(s->undo_char_point - u.insert_length); + } + state->cursor = (short)(u.where + u.insert_length); + + s->undo_point--; + s->redo_point--; +} +NK_API void +nk_textedit_redo(struct nk_text_edit *state) +{ + struct nk_text_undo_state *s = &state->undo; + struct nk_text_undo_record *u, r; + if (s->redo_point == NK_TEXTEDIT_UNDOSTATECOUNT) + return; + + /* we need to do two things: apply the redo record, and create an undo record */ + u = &s->undo_rec[s->undo_point]; + r = s->undo_rec[s->redo_point]; + + /* we KNOW there must be room for the undo record, because the redo record + was derived from an undo record */ + u->delete_length = r.insert_length; + u->insert_length = r.delete_length; + u->where = r.where; + u->char_storage = -1; + + if (r.delete_length) { + /* the redo record requires us to delete characters, so the undo record + needs to store the characters */ + if (s->undo_char_point + u->insert_length > s->redo_char_point) { + u->insert_length = 0; + u->delete_length = 0; + } else { + int i; + u->char_storage = s->undo_char_point; + s->undo_char_point = (short)(s->undo_char_point + u->insert_length); + + /* now save the characters */ + for (i=0; i < u->insert_length; ++i) { + s->undo_char[u->char_storage + i] = + nk_str_rune_at(&state->string, u->where + i); + } + } + nk_str_delete_runes(&state->string, r.where, r.delete_length); + } + + if (r.insert_length) { + /* easy case: need to insert n characters */ + nk_str_insert_text_runes(&state->string, r.where, + &s->undo_char[r.char_storage], r.insert_length); + } + state->cursor = r.where + r.insert_length; + + s->undo_point++; + s->redo_point++; +} +NK_INTERN void +nk_textedit_makeundo_insert(struct nk_text_edit *state, int where, int length) +{ + nk_textedit_createundo(&state->undo, where, 0, length); +} +NK_INTERN void +nk_textedit_makeundo_delete(struct nk_text_edit *state, int where, int length) +{ + int i; + nk_rune *p = nk_textedit_createundo(&state->undo, where, length, 0); + if (p) { + for (i=0; i < length; ++i) + p[i] = nk_str_rune_at(&state->string, where+i); + } +} +NK_INTERN void +nk_textedit_makeundo_replace(struct nk_text_edit *state, int where, + int old_length, int new_length) +{ + int i; + nk_rune *p = nk_textedit_createundo(&state->undo, where, old_length, new_length); + if (p) { + for (i=0; i < old_length; ++i) + p[i] = nk_str_rune_at(&state->string, where+i); + } +} +NK_LIB void +nk_textedit_clear_state(struct nk_text_edit *state, enum nk_text_edit_type type, + nk_plugin_filter filter) +{ + /* reset the state to default */ + state->undo.undo_point = 0; + state->undo.undo_char_point = 0; + state->undo.redo_point = NK_TEXTEDIT_UNDOSTATECOUNT; + state->undo.redo_char_point = NK_TEXTEDIT_UNDOCHARCOUNT; + state->select_end = state->select_start = 0; + state->cursor = 0; + state->has_preferred_x = 0; + state->preferred_x = 0; + state->cursor_at_end_of_line = 0; + state->initialized = 1; + state->single_line = (unsigned char)(type == NK_TEXT_EDIT_SINGLE_LINE); + state->mode = NK_TEXT_EDIT_MODE_VIEW; + state->filter = filter; + state->scrollbar = nk_vec2(0,0); +} +NK_API void +nk_textedit_init_fixed(struct nk_text_edit *state, void *memory, nk_size size) +{ + NK_ASSERT(state); + NK_ASSERT(memory); + if (!state || !memory || !size) return; + NK_MEMSET(state, 0, sizeof(struct nk_text_edit)); + nk_textedit_clear_state(state, NK_TEXT_EDIT_SINGLE_LINE, 0); + nk_str_init_fixed(&state->string, memory, size); +} +NK_API void +nk_textedit_init(struct nk_text_edit *state, struct nk_allocator *alloc, nk_size size) +{ + NK_ASSERT(state); + NK_ASSERT(alloc); + if (!state || !alloc) return; + NK_MEMSET(state, 0, sizeof(struct nk_text_edit)); + nk_textedit_clear_state(state, NK_TEXT_EDIT_SINGLE_LINE, 0); + nk_str_init(&state->string, alloc, size); +} +#ifdef NK_INCLUDE_DEFAULT_ALLOCATOR +NK_API void +nk_textedit_init_default(struct nk_text_edit *state) +{ + NK_ASSERT(state); + if (!state) return; + NK_MEMSET(state, 0, sizeof(struct nk_text_edit)); + nk_textedit_clear_state(state, NK_TEXT_EDIT_SINGLE_LINE, 0); + nk_str_init_default(&state->string); +} +#endif +NK_API void +nk_textedit_select_all(struct nk_text_edit *state) +{ + NK_ASSERT(state); + state->select_start = 0; + state->select_end = state->string.len; +} +NK_API void +nk_textedit_free(struct nk_text_edit *state) +{ + NK_ASSERT(state); + if (!state) return; + nk_str_free(&state->string); +} + + + + + +/* =============================================================== + * + * FILTER + * + * ===============================================================*/ +NK_API nk_bool +nk_filter_default(const struct nk_text_edit *box, nk_rune unicode) +{ + NK_UNUSED(unicode); + NK_UNUSED(box); + return nk_true; +} +NK_API nk_bool +nk_filter_ascii(const struct nk_text_edit *box, nk_rune unicode) +{ + NK_UNUSED(box); + if (unicode > 128) return nk_false; + else return nk_true; +} +NK_API nk_bool +nk_filter_float(const struct nk_text_edit *box, nk_rune unicode) +{ + NK_UNUSED(box); + if ((unicode < '0' || unicode > '9') && unicode != '.' && unicode != '-') + return nk_false; + else return nk_true; +} +NK_API nk_bool +nk_filter_decimal(const struct nk_text_edit *box, nk_rune unicode) +{ + NK_UNUSED(box); + if ((unicode < '0' || unicode > '9') && unicode != '-') + return nk_false; + else return nk_true; +} +NK_API nk_bool +nk_filter_hex(const struct nk_text_edit *box, nk_rune unicode) +{ + NK_UNUSED(box); + if ((unicode < '0' || unicode > '9') && + (unicode < 'a' || unicode > 'f') && + (unicode < 'A' || unicode > 'F')) + return nk_false; + else return nk_true; +} +NK_API nk_bool +nk_filter_oct(const struct nk_text_edit *box, nk_rune unicode) +{ + NK_UNUSED(box); + if (unicode < '0' || unicode > '7') + return nk_false; + else return nk_true; +} +NK_API nk_bool +nk_filter_binary(const struct nk_text_edit *box, nk_rune unicode) +{ + NK_UNUSED(box); + if (unicode != '0' && unicode != '1') + return nk_false; + else return nk_true; +} + +/* =============================================================== + * + * EDIT + * + * ===============================================================*/ +NK_LIB void +nk_edit_draw_text(struct nk_command_buffer *out, + const struct nk_style_edit *style, float pos_x, float pos_y, + float x_offset, const char *text, int byte_len, float row_height, + const struct nk_user_font *font, struct nk_color background, + struct nk_color foreground, nk_bool is_selected) +{ + NK_ASSERT(out); + NK_ASSERT(font); + NK_ASSERT(style); + if (!text || !byte_len || !out || !style) return; + + {int glyph_len = 0; + nk_rune unicode = 0; + int text_len = 0; + float line_width = 0; + float glyph_width; + const char *line = text; + float line_offset = 0; + int line_count = 0; + + struct nk_text txt; + txt.padding = nk_vec2(0,0); + txt.background = background; + txt.text = foreground; + + glyph_len = nk_utf_decode(text+text_len, &unicode, byte_len-text_len); + if (!glyph_len) return; + while ((text_len < byte_len) && glyph_len) + { + if (unicode == '\n') { + /* new line separator so draw previous line */ + struct nk_rect label; + label.y = pos_y + line_offset; + label.h = row_height; + label.w = line_width; + label.x = pos_x; + if (!line_count) + label.x += x_offset; + + if (is_selected) /* selection needs to draw different background color */ + nk_fill_rect(out, label, 0, background); + nk_widget_text(out, label, line, (int)((text + text_len) - line), + &txt, NK_TEXT_CENTERED, font); + + text_len++; + line_count++; + line_width = 0; + line = text + text_len; + line_offset += row_height; + glyph_len = nk_utf_decode(text + text_len, &unicode, (int)(byte_len-text_len)); + continue; + } + if (unicode == '\r') { + text_len++; + glyph_len = nk_utf_decode(text + text_len, &unicode, byte_len-text_len); + continue; + } + glyph_width = font->width(font->userdata, font->height, text+text_len, glyph_len); + line_width += (float)glyph_width; + text_len += glyph_len; + glyph_len = nk_utf_decode(text + text_len, &unicode, byte_len-text_len); + continue; + } + if (line_width > 0) { + /* draw last line */ + struct nk_rect label; + label.y = pos_y + line_offset; + label.h = row_height; + label.w = line_width; + label.x = pos_x; + if (!line_count) + label.x += x_offset; + + if (is_selected) + nk_fill_rect(out, label, 0, background); + nk_widget_text(out, label, line, (int)((text + text_len) - line), + &txt, NK_TEXT_LEFT, font); + }} +} +NK_LIB nk_flags +nk_do_edit(nk_flags *state, struct nk_command_buffer *out, + struct nk_rect bounds, nk_flags flags, nk_plugin_filter filter, + struct nk_text_edit *edit, const struct nk_style_edit *style, + struct nk_input *in, const struct nk_user_font *font) +{ + struct nk_rect area; + nk_flags ret = 0; + float row_height; + char prev_state = 0; + char is_hovered = 0; + char select_all = 0; + char cursor_follow = 0; + struct nk_rect old_clip; + struct nk_rect clip; + + NK_ASSERT(state); + NK_ASSERT(out); + NK_ASSERT(style); + if (!state || !out || !style) + return ret; + + /* visible text area calculation */ + area.x = bounds.x + style->padding.x + style->border; + area.y = bounds.y + style->padding.y + style->border; + area.w = bounds.w - (2.0f * style->padding.x + 2 * style->border); + area.h = bounds.h - (2.0f * style->padding.y + 2 * style->border); + if (flags & NK_EDIT_MULTILINE) + area.w = NK_MAX(0, area.w - style->scrollbar_size.x); + row_height = (flags & NK_EDIT_MULTILINE)? font->height + style->row_padding: area.h; + + /* calculate clipping rectangle */ + old_clip = out->clip; + nk_unify(&clip, &old_clip, area.x, area.y, area.x + area.w, area.y + area.h); + + /* update edit state */ + prev_state = (char)edit->active; + is_hovered = (char)nk_input_is_mouse_hovering_rect(in, bounds); + if (in && in->mouse.buttons[NK_BUTTON_LEFT].clicked && in->mouse.buttons[NK_BUTTON_LEFT].down) { + edit->active = NK_INBOX(in->mouse.pos.x, in->mouse.pos.y, + bounds.x, bounds.y, bounds.w, bounds.h); + } + + /* (de)activate text editor */ + if (!prev_state && edit->active) { + const enum nk_text_edit_type type = (flags & NK_EDIT_MULTILINE) ? + NK_TEXT_EDIT_MULTI_LINE: NK_TEXT_EDIT_SINGLE_LINE; + /* keep scroll position when re-activating edit widget */ + struct nk_vec2 oldscrollbar = edit->scrollbar; + nk_textedit_clear_state(edit, type, filter); + edit->scrollbar = oldscrollbar; + if (flags & NK_EDIT_AUTO_SELECT) + select_all = nk_true; + if (flags & NK_EDIT_GOTO_END_ON_ACTIVATE) { + edit->cursor = edit->string.len; + in = 0; + } + } else if (!edit->active) edit->mode = NK_TEXT_EDIT_MODE_VIEW; + if (flags & NK_EDIT_READ_ONLY) + edit->mode = NK_TEXT_EDIT_MODE_VIEW; + else if (flags & NK_EDIT_ALWAYS_INSERT_MODE) + edit->mode = NK_TEXT_EDIT_MODE_INSERT; + + ret = (edit->active) ? NK_EDIT_ACTIVE: NK_EDIT_INACTIVE; + if (prev_state != edit->active) + ret |= (edit->active) ? NK_EDIT_ACTIVATED: NK_EDIT_DEACTIVATED; + + /* handle user input */ + if (edit->active && in) + { + int shift_mod = in->keyboard.keys[NK_KEY_SHIFT].down; + const float mouse_x = (in->mouse.pos.x - area.x) + edit->scrollbar.x; + const float mouse_y = (in->mouse.pos.y - area.y) + edit->scrollbar.y; + + /* mouse click handler */ + is_hovered = (char)nk_input_is_mouse_hovering_rect(in, area); + if (select_all) { + nk_textedit_select_all(edit); + } else if (is_hovered && in->mouse.buttons[NK_BUTTON_LEFT].down && + in->mouse.buttons[NK_BUTTON_LEFT].clicked) { + nk_textedit_click(edit, mouse_x, mouse_y, font, row_height); + } else if (is_hovered && in->mouse.buttons[NK_BUTTON_LEFT].down && + (in->mouse.delta.x != 0.0f || in->mouse.delta.y != 0.0f)) { + nk_textedit_drag(edit, mouse_x, mouse_y, font, row_height); + cursor_follow = nk_true; + } else if (is_hovered && in->mouse.buttons[NK_BUTTON_RIGHT].clicked && + in->mouse.buttons[NK_BUTTON_RIGHT].down) { + nk_textedit_key(edit, NK_KEY_TEXT_WORD_LEFT, nk_false, font, row_height); + nk_textedit_key(edit, NK_KEY_TEXT_WORD_RIGHT, nk_true, font, row_height); + cursor_follow = nk_true; + } + + {int i; /* keyboard input */ + int old_mode = edit->mode; + for (i = 0; i < NK_KEY_MAX; ++i) { + if (i == NK_KEY_ENTER || i == NK_KEY_TAB) continue; /* special case */ + if (nk_input_is_key_pressed(in, (enum nk_keys)i)) { + nk_textedit_key(edit, (enum nk_keys)i, shift_mod, font, row_height); + cursor_follow = nk_true; + } + } + if (old_mode != edit->mode) { + in->keyboard.text_len = 0; + }} + + /* text input */ + edit->filter = filter; + if (in->keyboard.text_len) { + nk_textedit_text(edit, in->keyboard.text, in->keyboard.text_len); + cursor_follow = nk_true; + in->keyboard.text_len = 0; + } + + /* enter key handler */ + if (nk_input_is_key_pressed(in, NK_KEY_ENTER)) { + cursor_follow = nk_true; + if (flags & NK_EDIT_CTRL_ENTER_NEWLINE && shift_mod) + nk_textedit_text(edit, "\n", 1); + else if (flags & NK_EDIT_SIG_ENTER) + ret |= NK_EDIT_COMMITED; + else nk_textedit_text(edit, "\n", 1); + } + + /* cut & copy handler */ + {int copy= nk_input_is_key_pressed(in, NK_KEY_COPY); + int cut = nk_input_is_key_pressed(in, NK_KEY_CUT); + if ((copy || cut) && (flags & NK_EDIT_CLIPBOARD)) + { + int glyph_len; + nk_rune unicode; + const char *text; + int b = edit->select_start; + int e = edit->select_end; + + int begin = NK_MIN(b, e); + int end = NK_MAX(b, e); + text = nk_str_at_const(&edit->string, begin, &unicode, &glyph_len); + if (edit->clip.copy) + edit->clip.copy(edit->clip.userdata, text, end - begin); + if (cut && !(flags & NK_EDIT_READ_ONLY)){ + nk_textedit_cut(edit); + cursor_follow = nk_true; + } + }} + + /* paste handler */ + {int paste = nk_input_is_key_pressed(in, NK_KEY_PASTE); + if (paste && (flags & NK_EDIT_CLIPBOARD) && edit->clip.paste) { + edit->clip.paste(edit->clip.userdata, edit); + cursor_follow = nk_true; + }} + + /* tab handler */ + {int tab = nk_input_is_key_pressed(in, NK_KEY_TAB); + if (tab && (flags & NK_EDIT_ALLOW_TAB)) { + nk_textedit_text(edit, " ", 4); + cursor_follow = nk_true; + }} + } + + /* set widget state */ + if (edit->active) + *state = NK_WIDGET_STATE_ACTIVE; + else nk_widget_state_reset(state); + + if (is_hovered) + *state |= NK_WIDGET_STATE_HOVERED; + + /* DRAW EDIT */ + {const char *text = nk_str_get_const(&edit->string); + int len = nk_str_len_char(&edit->string); + + {/* select background colors/images */ + const struct nk_style_item *background; + if (*state & NK_WIDGET_STATE_ACTIVED) + background = &style->active; + else if (*state & NK_WIDGET_STATE_HOVER) + background = &style->hover; + else background = &style->normal; + + /* draw background frame */ + switch(background->type) { + case NK_STYLE_ITEM_IMAGE: + nk_draw_image(out, bounds, &background->data.image, nk_white); + break; + case NK_STYLE_ITEM_NINE_SLICE: + nk_draw_nine_slice(out, bounds, &background->data.slice, nk_white); + break; + case NK_STYLE_ITEM_COLOR: + nk_fill_rect(out, bounds, style->rounding, background->data.color); + nk_stroke_rect(out, bounds, style->rounding, style->border, style->border_color); + break; + }} + + + area.w = NK_MAX(0, area.w - style->cursor_size); + if (edit->active) + { + int total_lines = 1; + struct nk_vec2 text_size = nk_vec2(0,0); + + /* text pointer positions */ + const char *cursor_ptr = 0; + const char *select_begin_ptr = 0; + const char *select_end_ptr = 0; + + /* 2D pixel positions */ + struct nk_vec2 cursor_pos = nk_vec2(0,0); + struct nk_vec2 selection_offset_start = nk_vec2(0,0); + struct nk_vec2 selection_offset_end = nk_vec2(0,0); + + int selection_begin = NK_MIN(edit->select_start, edit->select_end); + int selection_end = NK_MAX(edit->select_start, edit->select_end); + + /* calculate total line count + total space + cursor/selection position */ + float line_width = 0.0f; + if (text && len) + { + /* utf8 encoding */ + float glyph_width; + int glyph_len = 0; + nk_rune unicode = 0; + int text_len = 0; + int glyphs = 0; + int row_begin = 0; + + glyph_len = nk_utf_decode(text, &unicode, len); + glyph_width = font->width(font->userdata, font->height, text, glyph_len); + line_width = 0; + + /* iterate all lines */ + while ((text_len < len) && glyph_len) + { + /* set cursor 2D position and line */ + if (!cursor_ptr && glyphs == edit->cursor) + { + int glyph_offset; + struct nk_vec2 out_offset; + struct nk_vec2 row_size; + const char *remaining; + + /* calculate 2d position */ + cursor_pos.y = (float)(total_lines-1) * row_height; + row_size = nk_text_calculate_text_bounds(font, text+row_begin, + text_len-row_begin, row_height, &remaining, + &out_offset, &glyph_offset, NK_STOP_ON_NEW_LINE); + cursor_pos.x = row_size.x; + cursor_ptr = text + text_len; + } + + /* set start selection 2D position and line */ + if (!select_begin_ptr && edit->select_start != edit->select_end && + glyphs == selection_begin) + { + int glyph_offset; + struct nk_vec2 out_offset; + struct nk_vec2 row_size; + const char *remaining; + + /* calculate 2d position */ + selection_offset_start.y = (float)(NK_MAX(total_lines-1,0)) * row_height; + row_size = nk_text_calculate_text_bounds(font, text+row_begin, + text_len-row_begin, row_height, &remaining, + &out_offset, &glyph_offset, NK_STOP_ON_NEW_LINE); + selection_offset_start.x = row_size.x; + select_begin_ptr = text + text_len; + } + + /* set end selection 2D position and line */ + if (!select_end_ptr && edit->select_start != edit->select_end && + glyphs == selection_end) + { + int glyph_offset; + struct nk_vec2 out_offset; + struct nk_vec2 row_size; + const char *remaining; + + /* calculate 2d position */ + selection_offset_end.y = (float)(total_lines-1) * row_height; + row_size = nk_text_calculate_text_bounds(font, text+row_begin, + text_len-row_begin, row_height, &remaining, + &out_offset, &glyph_offset, NK_STOP_ON_NEW_LINE); + selection_offset_end.x = row_size.x; + select_end_ptr = text + text_len; + } + if (unicode == '\n') { + text_size.x = NK_MAX(text_size.x, line_width); + total_lines++; + line_width = 0; + text_len++; + glyphs++; + row_begin = text_len; + glyph_len = nk_utf_decode(text + text_len, &unicode, len-text_len); + glyph_width = font->width(font->userdata, font->height, text+text_len, glyph_len); + continue; + } + + glyphs++; + text_len += glyph_len; + line_width += (float)glyph_width; + + glyph_len = nk_utf_decode(text + text_len, &unicode, len-text_len); + glyph_width = font->width(font->userdata, font->height, + text+text_len, glyph_len); + continue; + } + text_size.y = (float)total_lines * row_height; + + /* handle case when cursor is at end of text buffer */ + if (!cursor_ptr && edit->cursor == edit->string.len) { + cursor_pos.x = line_width; + cursor_pos.y = text_size.y - row_height; + } + } + { + /* scrollbar */ + if (cursor_follow) + { + /* update scrollbar to follow cursor */ + if (!(flags & NK_EDIT_NO_HORIZONTAL_SCROLL)) { + /* horizontal scroll */ + const float scroll_increment = area.w * 0.25f; + if (cursor_pos.x < edit->scrollbar.x) + edit->scrollbar.x = (float)(int)NK_MAX(0.0f, cursor_pos.x - scroll_increment); + if (cursor_pos.x >= edit->scrollbar.x + area.w) + edit->scrollbar.x = (float)(int)NK_MAX(0.0f, cursor_pos.x - area.w + scroll_increment); + } else edit->scrollbar.x = 0; + + if (flags & NK_EDIT_MULTILINE) { + /* vertical scroll */ + if (cursor_pos.y < edit->scrollbar.y) + edit->scrollbar.y = NK_MAX(0.0f, cursor_pos.y - row_height); + if (cursor_pos.y >= edit->scrollbar.y + row_height) + edit->scrollbar.y = edit->scrollbar.y + row_height; + } else edit->scrollbar.y = 0; + } + + /* scrollbar widget */ + if (flags & NK_EDIT_MULTILINE) + { + nk_flags ws; + struct nk_rect scroll; + float scroll_target; + float scroll_offset; + float scroll_step; + float scroll_inc; + + scroll = area; + scroll.x = (bounds.x + bounds.w - style->border) - style->scrollbar_size.x; + scroll.w = style->scrollbar_size.x; + + scroll_offset = edit->scrollbar.y; + scroll_step = scroll.h * 0.10f; + scroll_inc = scroll.h * 0.01f; + scroll_target = text_size.y; + edit->scrollbar.y = nk_do_scrollbarv(&ws, out, scroll, 0, + scroll_offset, scroll_target, scroll_step, scroll_inc, + &style->scrollbar, in, font); + } + } + + /* draw text */ + {struct nk_color background_color; + struct nk_color text_color; + struct nk_color sel_background_color; + struct nk_color sel_text_color; + struct nk_color cursor_color; + struct nk_color cursor_text_color; + const struct nk_style_item *background; + nk_push_scissor(out, clip); + + /* select correct colors to draw */ + if (*state & NK_WIDGET_STATE_ACTIVED) { + background = &style->active; + text_color = style->text_active; + sel_text_color = style->selected_text_hover; + sel_background_color = style->selected_hover; + cursor_color = style->cursor_hover; + cursor_text_color = style->cursor_text_hover; + } else if (*state & NK_WIDGET_STATE_HOVER) { + background = &style->hover; + text_color = style->text_hover; + sel_text_color = style->selected_text_hover; + sel_background_color = style->selected_hover; + cursor_text_color = style->cursor_text_hover; + cursor_color = style->cursor_hover; + } else { + background = &style->normal; + text_color = style->text_normal; + sel_text_color = style->selected_text_normal; + sel_background_color = style->selected_normal; + cursor_color = style->cursor_normal; + cursor_text_color = style->cursor_text_normal; + } + if (background->type == NK_STYLE_ITEM_IMAGE) + background_color = nk_rgba(0,0,0,0); + else + background_color = background->data.color; + + + if (edit->select_start == edit->select_end) { + /* no selection so just draw the complete text */ + const char *begin = nk_str_get_const(&edit->string); + int l = nk_str_len_char(&edit->string); + nk_edit_draw_text(out, style, area.x - edit->scrollbar.x, + area.y - edit->scrollbar.y, 0, begin, l, row_height, font, + background_color, text_color, nk_false); + } else { + /* edit has selection so draw 1-3 text chunks */ + if (edit->select_start != edit->select_end && selection_begin > 0){ + /* draw unselected text before selection */ + const char *begin = nk_str_get_const(&edit->string); + NK_ASSERT(select_begin_ptr); + nk_edit_draw_text(out, style, area.x - edit->scrollbar.x, + area.y - edit->scrollbar.y, 0, begin, (int)(select_begin_ptr - begin), + row_height, font, background_color, text_color, nk_false); + } + if (edit->select_start != edit->select_end) { + /* draw selected text */ + NK_ASSERT(select_begin_ptr); + if (!select_end_ptr) { + const char *begin = nk_str_get_const(&edit->string); + select_end_ptr = begin + nk_str_len_char(&edit->string); + } + nk_edit_draw_text(out, style, + area.x - edit->scrollbar.x, + area.y + selection_offset_start.y - edit->scrollbar.y, + selection_offset_start.x, + select_begin_ptr, (int)(select_end_ptr - select_begin_ptr), + row_height, font, sel_background_color, sel_text_color, nk_true); + } + if ((edit->select_start != edit->select_end && + selection_end < edit->string.len)) + { + /* draw unselected text after selected text */ + const char *begin = select_end_ptr; + const char *end = nk_str_get_const(&edit->string) + + nk_str_len_char(&edit->string); + NK_ASSERT(select_end_ptr); + nk_edit_draw_text(out, style, + area.x - edit->scrollbar.x, + area.y + selection_offset_end.y - edit->scrollbar.y, + selection_offset_end.x, + begin, (int)(end - begin), row_height, font, + background_color, text_color, nk_true); + } + } + + /* cursor */ + if (edit->select_start == edit->select_end) + { + if (edit->cursor >= nk_str_len(&edit->string) || + (cursor_ptr && *cursor_ptr == '\n')) { + /* draw cursor at end of line */ + struct nk_rect cursor; + cursor.w = style->cursor_size; + cursor.h = font->height; + cursor.x = area.x + cursor_pos.x - edit->scrollbar.x; + cursor.y = area.y + cursor_pos.y + row_height/2.0f - cursor.h/2.0f; + cursor.y -= edit->scrollbar.y; + nk_fill_rect(out, cursor, 0, cursor_color); + } else { + /* draw cursor inside text */ + int glyph_len; + struct nk_rect label; + struct nk_text txt; + + nk_rune unicode; + NK_ASSERT(cursor_ptr); + glyph_len = nk_utf_decode(cursor_ptr, &unicode, 4); + + label.x = area.x + cursor_pos.x - edit->scrollbar.x; + label.y = area.y + cursor_pos.y - edit->scrollbar.y; + label.w = font->width(font->userdata, font->height, cursor_ptr, glyph_len); + label.h = row_height; + + txt.padding = nk_vec2(0,0); + txt.background = cursor_color;; + txt.text = cursor_text_color; + nk_fill_rect(out, label, 0, cursor_color); + nk_widget_text(out, label, cursor_ptr, glyph_len, &txt, NK_TEXT_LEFT, font); + } + }} + } else { + /* not active so just draw text */ + int l = nk_str_len_char(&edit->string); + const char *begin = nk_str_get_const(&edit->string); + + const struct nk_style_item *background; + struct nk_color background_color; + struct nk_color text_color; + nk_push_scissor(out, clip); + if (*state & NK_WIDGET_STATE_ACTIVED) { + background = &style->active; + text_color = style->text_active; + } else if (*state & NK_WIDGET_STATE_HOVER) { + background = &style->hover; + text_color = style->text_hover; + } else { + background = &style->normal; + text_color = style->text_normal; + } + if (background->type == NK_STYLE_ITEM_IMAGE) + background_color = nk_rgba(0,0,0,0); + else + background_color = background->data.color; + nk_edit_draw_text(out, style, area.x - edit->scrollbar.x, + area.y - edit->scrollbar.y, 0, begin, l, row_height, font, + background_color, text_color, nk_false); + } + nk_push_scissor(out, old_clip);} + return ret; +} +NK_API void +nk_edit_focus(struct nk_context *ctx, nk_flags flags) +{ + nk_hash hash; + struct nk_window *win; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + if (!ctx || !ctx->current) return; + + win = ctx->current; + hash = win->edit.seq; + win->edit.active = nk_true; + win->edit.name = hash; + if (flags & NK_EDIT_ALWAYS_INSERT_MODE) + win->edit.mode = NK_TEXT_EDIT_MODE_INSERT; +} +NK_API void +nk_edit_unfocus(struct nk_context *ctx) +{ + struct nk_window *win; + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + if (!ctx || !ctx->current) return; + + win = ctx->current; + win->edit.active = nk_false; + win->edit.name = 0; +} +NK_API nk_flags +nk_edit_string(struct nk_context *ctx, nk_flags flags, + char *memory, int *len, int max, nk_plugin_filter filter) +{ + nk_hash hash; + nk_flags state; + struct nk_text_edit *edit; + struct nk_window *win; + + NK_ASSERT(ctx); + NK_ASSERT(memory); + NK_ASSERT(len); + if (!ctx || !memory || !len) + return 0; + + filter = (!filter) ? nk_filter_default: filter; + win = ctx->current; + hash = win->edit.seq; + edit = &ctx->text_edit; + nk_textedit_clear_state(&ctx->text_edit, (flags & NK_EDIT_MULTILINE)? + NK_TEXT_EDIT_MULTI_LINE: NK_TEXT_EDIT_SINGLE_LINE, filter); + + if (win->edit.active && hash == win->edit.name) { + if (flags & NK_EDIT_NO_CURSOR) + edit->cursor = nk_utf_len(memory, *len); + else edit->cursor = win->edit.cursor; + if (!(flags & NK_EDIT_SELECTABLE)) { + edit->select_start = win->edit.cursor; + edit->select_end = win->edit.cursor; + } else { + edit->select_start = win->edit.sel_start; + edit->select_end = win->edit.sel_end; + } + edit->mode = win->edit.mode; + edit->scrollbar.x = (float)win->edit.scrollbar.x; + edit->scrollbar.y = (float)win->edit.scrollbar.y; + edit->active = nk_true; + } else edit->active = nk_false; + + max = NK_MAX(1, max); + *len = NK_MIN(*len, max-1); + nk_str_init_fixed(&edit->string, memory, (nk_size)max); + edit->string.buffer.allocated = (nk_size)*len; + edit->string.len = nk_utf_len(memory, *len); + state = nk_edit_buffer(ctx, flags, edit, filter); + *len = (int)edit->string.buffer.allocated; + + if (edit->active) { + win->edit.cursor = edit->cursor; + win->edit.sel_start = edit->select_start; + win->edit.sel_end = edit->select_end; + win->edit.mode = edit->mode; + win->edit.scrollbar.x = (nk_uint)edit->scrollbar.x; + win->edit.scrollbar.y = (nk_uint)edit->scrollbar.y; + } return state; +} +NK_API nk_flags +nk_edit_buffer(struct nk_context *ctx, nk_flags flags, + struct nk_text_edit *edit, nk_plugin_filter filter) +{ + struct nk_window *win; + struct nk_style *style; + struct nk_input *in; + + enum nk_widget_layout_states state; + struct nk_rect bounds; + + nk_flags ret_flags = 0; + unsigned char prev_state; + nk_hash hash; + + /* make sure correct values */ + NK_ASSERT(ctx); + NK_ASSERT(edit); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return 0; + + win = ctx->current; + style = &ctx->style; + state = nk_widget(&bounds, ctx); + if (!state) return state; + in = (win->layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + + /* check if edit is currently hot item */ + hash = win->edit.seq++; + if (win->edit.active && hash == win->edit.name) { + if (flags & NK_EDIT_NO_CURSOR) + edit->cursor = edit->string.len; + if (!(flags & NK_EDIT_SELECTABLE)) { + edit->select_start = edit->cursor; + edit->select_end = edit->cursor; + } + if (flags & NK_EDIT_CLIPBOARD) + edit->clip = ctx->clip; + edit->active = (unsigned char)win->edit.active; + } else edit->active = nk_false; + edit->mode = win->edit.mode; + + filter = (!filter) ? nk_filter_default: filter; + prev_state = (unsigned char)edit->active; + in = (flags & NK_EDIT_READ_ONLY) ? 0: in; + ret_flags = nk_do_edit(&ctx->last_widget_state, &win->buffer, bounds, flags, + filter, edit, &style->edit, in, style->font); + + if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER) + ctx->style.cursor_active = ctx->style.cursors[NK_CURSOR_TEXT]; + if (edit->active && prev_state != edit->active) { + /* current edit is now hot */ + win->edit.active = nk_true; + win->edit.name = hash; + } else if (prev_state && !edit->active) { + /* current edit is now cold */ + win->edit.active = nk_false; + } return ret_flags; +} +NK_API nk_flags +nk_edit_string_zero_terminated(struct nk_context *ctx, nk_flags flags, + char *buffer, int max, nk_plugin_filter filter) +{ + nk_flags result; + int len = nk_strlen(buffer); + result = nk_edit_string(ctx, flags, buffer, &len, max, filter); + buffer[NK_MIN(NK_MAX(max-1,0), len)] = '\0'; + return result; +} + + + + + +/* =============================================================== + * + * PROPERTY + * + * ===============================================================*/ +NK_LIB void +nk_drag_behavior(nk_flags *state, const struct nk_input *in, + struct nk_rect drag, struct nk_property_variant *variant, + float inc_per_pixel) +{ + int left_mouse_down = in && in->mouse.buttons[NK_BUTTON_LEFT].down; + int left_mouse_click_in_cursor = in && + nk_input_has_mouse_click_down_in_rect(in, NK_BUTTON_LEFT, drag, nk_true); + + nk_widget_state_reset(state); + if (nk_input_is_mouse_hovering_rect(in, drag)) + *state = NK_WIDGET_STATE_HOVERED; + + if (left_mouse_down && left_mouse_click_in_cursor) { + float delta, pixels; + pixels = in->mouse.delta.x; + delta = pixels * inc_per_pixel; + switch (variant->kind) { + default: break; + case NK_PROPERTY_INT: + variant->value.i = variant->value.i + (int)delta; + variant->value.i = NK_CLAMP(variant->min_value.i, variant->value.i, variant->max_value.i); + break; + case NK_PROPERTY_FLOAT: + variant->value.f = variant->value.f + (float)delta; + variant->value.f = NK_CLAMP(variant->min_value.f, variant->value.f, variant->max_value.f); + break; + case NK_PROPERTY_DOUBLE: + variant->value.d = variant->value.d + (double)delta; + variant->value.d = NK_CLAMP(variant->min_value.d, variant->value.d, variant->max_value.d); + break; + } + *state = NK_WIDGET_STATE_ACTIVE; + } + if (*state & NK_WIDGET_STATE_HOVER && !nk_input_is_mouse_prev_hovering_rect(in, drag)) + *state |= NK_WIDGET_STATE_ENTERED; + else if (nk_input_is_mouse_prev_hovering_rect(in, drag)) + *state |= NK_WIDGET_STATE_LEFT; +} +NK_LIB void +nk_property_behavior(nk_flags *ws, const struct nk_input *in, + struct nk_rect property, struct nk_rect label, struct nk_rect edit, + struct nk_rect empty, int *state, struct nk_property_variant *variant, + float inc_per_pixel) +{ + nk_widget_state_reset(ws); + if (in && *state == NK_PROPERTY_DEFAULT) { + if (nk_button_behavior(ws, edit, in, NK_BUTTON_DEFAULT)) + *state = NK_PROPERTY_EDIT; + else if (nk_input_is_mouse_click_down_in_rect(in, NK_BUTTON_LEFT, label, nk_true)) + *state = NK_PROPERTY_DRAG; + else if (nk_input_is_mouse_click_down_in_rect(in, NK_BUTTON_LEFT, empty, nk_true)) + *state = NK_PROPERTY_DRAG; + } + if (*state == NK_PROPERTY_DRAG) { + nk_drag_behavior(ws, in, property, variant, inc_per_pixel); + if (!(*ws & NK_WIDGET_STATE_ACTIVED)) *state = NK_PROPERTY_DEFAULT; + } +} +NK_LIB void +nk_draw_property(struct nk_command_buffer *out, const struct nk_style_property *style, + const struct nk_rect *bounds, const struct nk_rect *label, nk_flags state, + const char *name, int len, const struct nk_user_font *font) +{ + struct nk_text text; + const struct nk_style_item *background; + + /* select correct background and text color */ + if (state & NK_WIDGET_STATE_ACTIVED) { + background = &style->active; + text.text = style->label_active; + } else if (state & NK_WIDGET_STATE_HOVER) { + background = &style->hover; + text.text = style->label_hover; + } else { + background = &style->normal; + text.text = style->label_normal; + } + + /* draw background */ + switch(background->type) { + case NK_STYLE_ITEM_IMAGE: + text.background = nk_rgba(0, 0, 0, 0); + nk_draw_image(out, *bounds, &background->data.image, nk_white); + break; + case NK_STYLE_ITEM_NINE_SLICE: + text.background = nk_rgba(0, 0, 0, 0); + nk_draw_nine_slice(out, *bounds, &background->data.slice, nk_white); + break; + case NK_STYLE_ITEM_COLOR: + text.background = background->data.color; + nk_fill_rect(out, *bounds, style->rounding, background->data.color); + nk_stroke_rect(out, *bounds, style->rounding, style->border, background->data.color); + break; + } + + /* draw label */ + text.padding = nk_vec2(0,0); + nk_widget_text(out, *label, name, len, &text, NK_TEXT_CENTERED, font); +} +NK_LIB void +nk_do_property(nk_flags *ws, + struct nk_command_buffer *out, struct nk_rect property, + const char *name, struct nk_property_variant *variant, + float inc_per_pixel, char *buffer, int *len, + int *state, int *cursor, int *select_begin, int *select_end, + const struct nk_style_property *style, + enum nk_property_filter filter, struct nk_input *in, + const struct nk_user_font *font, struct nk_text_edit *text_edit, + enum nk_button_behavior behavior) +{ + const nk_plugin_filter filters[] = { + nk_filter_decimal, + nk_filter_float + }; + nk_bool active, old; + int num_len = 0, name_len; + char string[NK_MAX_NUMBER_BUFFER]; + float size; + + char *dst = 0; + int *length; + + struct nk_rect left; + struct nk_rect right; + struct nk_rect label; + struct nk_rect edit; + struct nk_rect empty; + + /* left decrement button */ + left.h = font->height/2; + left.w = left.h; + left.x = property.x + style->border + style->padding.x; + left.y = property.y + style->border + property.h/2.0f - left.h/2; + + /* text label */ + name_len = nk_strlen(name); + size = font->width(font->userdata, font->height, name, name_len); + label.x = left.x + left.w + style->padding.x; + label.w = (float)size + 2 * style->padding.x; + label.y = property.y + style->border + style->padding.y; + label.h = property.h - (2 * style->border + 2 * style->padding.y); + + /* right increment button */ + right.y = left.y; + right.w = left.w; + right.h = left.h; + right.x = property.x + property.w - (right.w + style->padding.x); + + /* edit */ + if (*state == NK_PROPERTY_EDIT) { + size = font->width(font->userdata, font->height, buffer, *len); + size += style->edit.cursor_size; + length = len; + dst = buffer; + } else { + switch (variant->kind) { + default: break; + case NK_PROPERTY_INT: + nk_itoa(string, variant->value.i); + num_len = nk_strlen(string); + break; + case NK_PROPERTY_FLOAT: + NK_DTOA(string, (double)variant->value.f); + num_len = nk_string_float_limit(string, NK_MAX_FLOAT_PRECISION); + break; + case NK_PROPERTY_DOUBLE: + NK_DTOA(string, variant->value.d); + num_len = nk_string_float_limit(string, NK_MAX_FLOAT_PRECISION); + break; + } + size = font->width(font->userdata, font->height, string, num_len); + dst = string; + length = &num_len; + } + + edit.w = (float)size + 2 * style->padding.x; + edit.w = NK_MIN(edit.w, right.x - (label.x + label.w)); + edit.x = right.x - (edit.w + style->padding.x); + edit.y = property.y + style->border; + edit.h = property.h - (2 * style->border); + + /* empty left space activator */ + empty.w = edit.x - (label.x + label.w); + empty.x = label.x + label.w; + empty.y = property.y; + empty.h = property.h; + + /* update property */ + old = (*state == NK_PROPERTY_EDIT); + nk_property_behavior(ws, in, property, label, edit, empty, state, variant, inc_per_pixel); + + /* draw property */ + if (style->draw_begin) style->draw_begin(out, style->userdata); + nk_draw_property(out, style, &property, &label, *ws, name, name_len, font); + if (style->draw_end) style->draw_end(out, style->userdata); + + /* execute right button */ + if (nk_do_button_symbol(ws, out, left, style->sym_left, behavior, &style->dec_button, in, font)) { + switch (variant->kind) { + default: break; + case NK_PROPERTY_INT: + variant->value.i = NK_CLAMP(variant->min_value.i, variant->value.i - variant->step.i, variant->max_value.i); break; + case NK_PROPERTY_FLOAT: + variant->value.f = NK_CLAMP(variant->min_value.f, variant->value.f - variant->step.f, variant->max_value.f); break; + case NK_PROPERTY_DOUBLE: + variant->value.d = NK_CLAMP(variant->min_value.d, variant->value.d - variant->step.d, variant->max_value.d); break; + } + } + /* execute left button */ + if (nk_do_button_symbol(ws, out, right, style->sym_right, behavior, &style->inc_button, in, font)) { + switch (variant->kind) { + default: break; + case NK_PROPERTY_INT: + variant->value.i = NK_CLAMP(variant->min_value.i, variant->value.i + variant->step.i, variant->max_value.i); break; + case NK_PROPERTY_FLOAT: + variant->value.f = NK_CLAMP(variant->min_value.f, variant->value.f + variant->step.f, variant->max_value.f); break; + case NK_PROPERTY_DOUBLE: + variant->value.d = NK_CLAMP(variant->min_value.d, variant->value.d + variant->step.d, variant->max_value.d); break; + } + } + if (old != NK_PROPERTY_EDIT && (*state == NK_PROPERTY_EDIT)) { + /* property has been activated so setup buffer */ + NK_MEMCPY(buffer, dst, (nk_size)*length); + *cursor = nk_utf_len(buffer, *length); + *len = *length; + length = len; + dst = buffer; + active = 0; + } else active = (*state == NK_PROPERTY_EDIT); + + /* execute and run text edit field */ + nk_textedit_clear_state(text_edit, NK_TEXT_EDIT_SINGLE_LINE, filters[filter]); + text_edit->active = (unsigned char)active; + text_edit->string.len = *length; + text_edit->cursor = NK_CLAMP(0, *cursor, *length); + text_edit->select_start = NK_CLAMP(0,*select_begin, *length); + text_edit->select_end = NK_CLAMP(0,*select_end, *length); + text_edit->string.buffer.allocated = (nk_size)*length; + text_edit->string.buffer.memory.size = NK_MAX_NUMBER_BUFFER; + text_edit->string.buffer.memory.ptr = dst; + text_edit->string.buffer.size = NK_MAX_NUMBER_BUFFER; + text_edit->mode = NK_TEXT_EDIT_MODE_INSERT; + nk_do_edit(ws, out, edit, NK_EDIT_FIELD|NK_EDIT_AUTO_SELECT, + filters[filter], text_edit, &style->edit, (*state == NK_PROPERTY_EDIT) ? in: 0, font); + + *length = text_edit->string.len; + *cursor = text_edit->cursor; + *select_begin = text_edit->select_start; + *select_end = text_edit->select_end; + if (text_edit->active && nk_input_is_key_pressed(in, NK_KEY_ENTER)) + text_edit->active = nk_false; + + if (active && !text_edit->active) { + /* property is now not active so convert edit text to value*/ + *state = NK_PROPERTY_DEFAULT; + buffer[*len] = '\0'; + switch (variant->kind) { + default: break; + case NK_PROPERTY_INT: + variant->value.i = nk_strtoi(buffer, 0); + variant->value.i = NK_CLAMP(variant->min_value.i, variant->value.i, variant->max_value.i); + break; + case NK_PROPERTY_FLOAT: + nk_string_float_limit(buffer, NK_MAX_FLOAT_PRECISION); + variant->value.f = nk_strtof(buffer, 0); + variant->value.f = NK_CLAMP(variant->min_value.f, variant->value.f, variant->max_value.f); + break; + case NK_PROPERTY_DOUBLE: + nk_string_float_limit(buffer, NK_MAX_FLOAT_PRECISION); + variant->value.d = nk_strtod(buffer, 0); + variant->value.d = NK_CLAMP(variant->min_value.d, variant->value.d, variant->max_value.d); + break; + } + } +} +NK_LIB struct nk_property_variant +nk_property_variant_int(int value, int min_value, int max_value, int step) +{ + struct nk_property_variant result; + result.kind = NK_PROPERTY_INT; + result.value.i = value; + result.min_value.i = min_value; + result.max_value.i = max_value; + result.step.i = step; + return result; +} +NK_LIB struct nk_property_variant +nk_property_variant_float(float value, float min_value, float max_value, float step) +{ + struct nk_property_variant result; + result.kind = NK_PROPERTY_FLOAT; + result.value.f = value; + result.min_value.f = min_value; + result.max_value.f = max_value; + result.step.f = step; + return result; +} +NK_LIB struct nk_property_variant +nk_property_variant_double(double value, double min_value, double max_value, + double step) +{ + struct nk_property_variant result; + result.kind = NK_PROPERTY_DOUBLE; + result.value.d = value; + result.min_value.d = min_value; + result.max_value.d = max_value; + result.step.d = step; + return result; +} +NK_LIB void +nk_property(struct nk_context *ctx, const char *name, struct nk_property_variant *variant, + float inc_per_pixel, const enum nk_property_filter filter) +{ + struct nk_window *win; + struct nk_panel *layout; + struct nk_input *in; + const struct nk_style *style; + + struct nk_rect bounds; + enum nk_widget_layout_states s; + + int *state = 0; + nk_hash hash = 0; + char *buffer = 0; + int *len = 0; + int *cursor = 0; + int *select_begin = 0; + int *select_end = 0; + int old_state; + + char dummy_buffer[NK_MAX_NUMBER_BUFFER]; + int dummy_state = NK_PROPERTY_DEFAULT; + int dummy_length = 0; + int dummy_cursor = 0; + int dummy_select_begin = 0; + int dummy_select_end = 0; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return; + + win = ctx->current; + layout = win->layout; + style = &ctx->style; + s = nk_widget(&bounds, ctx); + if (!s) return; + + /* calculate hash from name */ + if (name[0] == '#') { + hash = nk_murmur_hash(name, (int)nk_strlen(name), win->property.seq++); + name++; /* special number hash */ + } else hash = nk_murmur_hash(name, (int)nk_strlen(name), 42); + + /* check if property is currently hot item */ + if (win->property.active && hash == win->property.name) { + buffer = win->property.buffer; + len = &win->property.length; + cursor = &win->property.cursor; + state = &win->property.state; + select_begin = &win->property.select_start; + select_end = &win->property.select_end; + } else { + buffer = dummy_buffer; + len = &dummy_length; + cursor = &dummy_cursor; + state = &dummy_state; + select_begin = &dummy_select_begin; + select_end = &dummy_select_end; + } + + /* execute property widget */ + old_state = *state; + ctx->text_edit.clip = ctx->clip; + in = ((s == NK_WIDGET_ROM && !win->property.active) || + layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + nk_do_property(&ctx->last_widget_state, &win->buffer, bounds, name, + variant, inc_per_pixel, buffer, len, state, cursor, select_begin, + select_end, &style->property, filter, in, style->font, &ctx->text_edit, + ctx->button_behavior); + + if (in && *state != NK_PROPERTY_DEFAULT && !win->property.active) { + /* current property is now hot */ + win->property.active = 1; + NK_MEMCPY(win->property.buffer, buffer, (nk_size)*len); + win->property.length = *len; + win->property.cursor = *cursor; + win->property.state = *state; + win->property.name = hash; + win->property.select_start = *select_begin; + win->property.select_end = *select_end; + if (*state == NK_PROPERTY_DRAG) { + ctx->input.mouse.grab = nk_true; + ctx->input.mouse.grabbed = nk_true; + } + } + /* check if previously active property is now inactive */ + if (*state == NK_PROPERTY_DEFAULT && old_state != NK_PROPERTY_DEFAULT) { + if (old_state == NK_PROPERTY_DRAG) { + ctx->input.mouse.grab = nk_false; + ctx->input.mouse.grabbed = nk_false; + ctx->input.mouse.ungrab = nk_true; + } + win->property.select_start = 0; + win->property.select_end = 0; + win->property.active = 0; + } +} +NK_API void +nk_property_int(struct nk_context *ctx, const char *name, + int min, int *val, int max, int step, float inc_per_pixel) +{ + struct nk_property_variant variant; + NK_ASSERT(ctx); + NK_ASSERT(name); + NK_ASSERT(val); + + if (!ctx || !ctx->current || !name || !val) return; + variant = nk_property_variant_int(*val, min, max, step); + nk_property(ctx, name, &variant, inc_per_pixel, NK_FILTER_INT); + *val = variant.value.i; +} +NK_API void +nk_property_float(struct nk_context *ctx, const char *name, + float min, float *val, float max, float step, float inc_per_pixel) +{ + struct nk_property_variant variant; + NK_ASSERT(ctx); + NK_ASSERT(name); + NK_ASSERT(val); + + if (!ctx || !ctx->current || !name || !val) return; + variant = nk_property_variant_float(*val, min, max, step); + nk_property(ctx, name, &variant, inc_per_pixel, NK_FILTER_FLOAT); + *val = variant.value.f; +} +NK_API void +nk_property_double(struct nk_context *ctx, const char *name, + double min, double *val, double max, double step, float inc_per_pixel) +{ + struct nk_property_variant variant; + NK_ASSERT(ctx); + NK_ASSERT(name); + NK_ASSERT(val); + + if (!ctx || !ctx->current || !name || !val) return; + variant = nk_property_variant_double(*val, min, max, step); + nk_property(ctx, name, &variant, inc_per_pixel, NK_FILTER_FLOAT); + *val = variant.value.d; +} +NK_API int +nk_propertyi(struct nk_context *ctx, const char *name, int min, int val, + int max, int step, float inc_per_pixel) +{ + struct nk_property_variant variant; + NK_ASSERT(ctx); + NK_ASSERT(name); + + if (!ctx || !ctx->current || !name) return val; + variant = nk_property_variant_int(val, min, max, step); + nk_property(ctx, name, &variant, inc_per_pixel, NK_FILTER_INT); + val = variant.value.i; + return val; +} +NK_API float +nk_propertyf(struct nk_context *ctx, const char *name, float min, + float val, float max, float step, float inc_per_pixel) +{ + struct nk_property_variant variant; + NK_ASSERT(ctx); + NK_ASSERT(name); + + if (!ctx || !ctx->current || !name) return val; + variant = nk_property_variant_float(val, min, max, step); + nk_property(ctx, name, &variant, inc_per_pixel, NK_FILTER_FLOAT); + val = variant.value.f; + return val; +} +NK_API double +nk_propertyd(struct nk_context *ctx, const char *name, double min, + double val, double max, double step, float inc_per_pixel) +{ + struct nk_property_variant variant; + NK_ASSERT(ctx); + NK_ASSERT(name); + + if (!ctx || !ctx->current || !name) return val; + variant = nk_property_variant_double(val, min, max, step); + nk_property(ctx, name, &variant, inc_per_pixel, NK_FILTER_FLOAT); + val = variant.value.d; + return val; +} + + + + + +/* ============================================================== + * + * CHART + * + * ===============================================================*/ +NK_API nk_bool +nk_chart_begin_colored(struct nk_context *ctx, enum nk_chart_type type, + struct nk_color color, struct nk_color highlight, + int count, float min_value, float max_value) +{ + struct nk_window *win; + struct nk_chart *chart; + const struct nk_style *config; + const struct nk_style_chart *style; + + const struct nk_style_item *background; + struct nk_rect bounds = {0, 0, 0, 0}; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + + if (!ctx || !ctx->current || !ctx->current->layout) return 0; + if (!nk_widget(&bounds, ctx)) { + chart = &ctx->current->layout->chart; + nk_zero(chart, sizeof(*chart)); + return 0; + } + + win = ctx->current; + config = &ctx->style; + chart = &win->layout->chart; + style = &config->chart; + + /* setup basic generic chart */ + nk_zero(chart, sizeof(*chart)); + chart->x = bounds.x + style->padding.x; + chart->y = bounds.y + style->padding.y; + chart->w = bounds.w - 2 * style->padding.x; + chart->h = bounds.h - 2 * style->padding.y; + chart->w = NK_MAX(chart->w, 2 * style->padding.x); + chart->h = NK_MAX(chart->h, 2 * style->padding.y); + + /* add first slot into chart */ + {struct nk_chart_slot *slot = &chart->slots[chart->slot++]; + slot->type = type; + slot->count = count; + slot->color = color; + slot->highlight = highlight; + slot->min = NK_MIN(min_value, max_value); + slot->max = NK_MAX(min_value, max_value); + slot->range = slot->max - slot->min;} + + /* draw chart background */ + background = &style->background; + + switch(background->type) { + case NK_STYLE_ITEM_IMAGE: + nk_draw_image(&win->buffer, bounds, &background->data.image, nk_white); + break; + case NK_STYLE_ITEM_NINE_SLICE: + nk_draw_nine_slice(&win->buffer, bounds, &background->data.slice, nk_white); + break; + case NK_STYLE_ITEM_COLOR: + nk_fill_rect(&win->buffer, bounds, style->rounding, style->border_color); + nk_fill_rect(&win->buffer, nk_shrink_rect(bounds, style->border), + style->rounding, style->background.data.color); + break; + } + return 1; +} +NK_API nk_bool +nk_chart_begin(struct nk_context *ctx, const enum nk_chart_type type, + int count, float min_value, float max_value) +{ + return nk_chart_begin_colored(ctx, type, ctx->style.chart.color, + ctx->style.chart.selected_color, count, min_value, max_value); +} +NK_API void +nk_chart_add_slot_colored(struct nk_context *ctx, const enum nk_chart_type type, + struct nk_color color, struct nk_color highlight, + int count, float min_value, float max_value) +{ + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + NK_ASSERT(ctx->current->layout->chart.slot < NK_CHART_MAX_SLOT); + if (!ctx || !ctx->current || !ctx->current->layout) return; + if (ctx->current->layout->chart.slot >= NK_CHART_MAX_SLOT) return; + + /* add another slot into the graph */ + {struct nk_chart *chart = &ctx->current->layout->chart; + struct nk_chart_slot *slot = &chart->slots[chart->slot++]; + slot->type = type; + slot->count = count; + slot->color = color; + slot->highlight = highlight; + slot->min = NK_MIN(min_value, max_value); + slot->max = NK_MAX(min_value, max_value); + slot->range = slot->max - slot->min;} +} +NK_API void +nk_chart_add_slot(struct nk_context *ctx, const enum nk_chart_type type, + int count, float min_value, float max_value) +{ + nk_chart_add_slot_colored(ctx, type, ctx->style.chart.color, + ctx->style.chart.selected_color, count, min_value, max_value); +} +NK_INTERN nk_flags +nk_chart_push_line(struct nk_context *ctx, struct nk_window *win, + struct nk_chart *g, float value, int slot) +{ + struct nk_panel *layout = win->layout; + const struct nk_input *i = &ctx->input; + struct nk_command_buffer *out = &win->buffer; + + nk_flags ret = 0; + struct nk_vec2 cur; + struct nk_rect bounds; + struct nk_color color; + float step; + float range; + float ratio; + + NK_ASSERT(slot >= 0 && slot < NK_CHART_MAX_SLOT); + step = g->w / (float)g->slots[slot].count; + range = g->slots[slot].max - g->slots[slot].min; + ratio = (value - g->slots[slot].min) / range; + + if (g->slots[slot].index == 0) { + /* first data point does not have a connection */ + g->slots[slot].last.x = g->x; + g->slots[slot].last.y = (g->y + g->h) - ratio * (float)g->h; + + bounds.x = g->slots[slot].last.x - 2; + bounds.y = g->slots[slot].last.y - 2; + bounds.w = bounds.h = 4; + + color = g->slots[slot].color; + if (!(layout->flags & NK_WINDOW_ROM) && + NK_INBOX(i->mouse.pos.x,i->mouse.pos.y, g->slots[slot].last.x-3, g->slots[slot].last.y-3, 6, 6)){ + ret = nk_input_is_mouse_hovering_rect(i, bounds) ? NK_CHART_HOVERING : 0; + ret |= (i->mouse.buttons[NK_BUTTON_LEFT].down && + i->mouse.buttons[NK_BUTTON_LEFT].clicked) ? NK_CHART_CLICKED: 0; + color = g->slots[slot].highlight; + } + nk_fill_rect(out, bounds, 0, color); + g->slots[slot].index += 1; + return ret; + } + + /* draw a line between the last data point and the new one */ + color = g->slots[slot].color; + cur.x = g->x + (float)(step * (float)g->slots[slot].index); + cur.y = (g->y + g->h) - (ratio * (float)g->h); + nk_stroke_line(out, g->slots[slot].last.x, g->slots[slot].last.y, cur.x, cur.y, 1.0f, color); + + bounds.x = cur.x - 3; + bounds.y = cur.y - 3; + bounds.w = bounds.h = 6; + + /* user selection of current data point */ + if (!(layout->flags & NK_WINDOW_ROM)) { + if (nk_input_is_mouse_hovering_rect(i, bounds)) { + ret = NK_CHART_HOVERING; + ret |= (!i->mouse.buttons[NK_BUTTON_LEFT].down && + i->mouse.buttons[NK_BUTTON_LEFT].clicked) ? NK_CHART_CLICKED: 0; + color = g->slots[slot].highlight; + } + } + nk_fill_rect(out, nk_rect(cur.x - 2, cur.y - 2, 4, 4), 0, color); + + /* save current data point position */ + g->slots[slot].last.x = cur.x; + g->slots[slot].last.y = cur.y; + g->slots[slot].index += 1; + return ret; +} +NK_INTERN nk_flags +nk_chart_push_column(const struct nk_context *ctx, struct nk_window *win, + struct nk_chart *chart, float value, int slot) +{ + struct nk_command_buffer *out = &win->buffer; + const struct nk_input *in = &ctx->input; + struct nk_panel *layout = win->layout; + + float ratio; + nk_flags ret = 0; + struct nk_color color; + struct nk_rect item = {0,0,0,0}; + + NK_ASSERT(slot >= 0 && slot < NK_CHART_MAX_SLOT); + if (chart->slots[slot].index >= chart->slots[slot].count) + return nk_false; + if (chart->slots[slot].count) { + float padding = (float)(chart->slots[slot].count-1); + item.w = (chart->w - padding) / (float)(chart->slots[slot].count); + } + + /* calculate bounds of current bar chart entry */ + color = chart->slots[slot].color;; + item.h = chart->h * NK_ABS((value/chart->slots[slot].range)); + if (value >= 0) { + ratio = (value + NK_ABS(chart->slots[slot].min)) / NK_ABS(chart->slots[slot].range); + item.y = (chart->y + chart->h) - chart->h * ratio; + } else { + ratio = (value - chart->slots[slot].max) / chart->slots[slot].range; + item.y = chart->y + (chart->h * NK_ABS(ratio)) - item.h; + } + item.x = chart->x + ((float)chart->slots[slot].index * item.w); + item.x = item.x + ((float)chart->slots[slot].index); + + /* user chart bar selection */ + if (!(layout->flags & NK_WINDOW_ROM) && + NK_INBOX(in->mouse.pos.x,in->mouse.pos.y,item.x,item.y,item.w,item.h)) { + ret = NK_CHART_HOVERING; + ret |= (!in->mouse.buttons[NK_BUTTON_LEFT].down && + in->mouse.buttons[NK_BUTTON_LEFT].clicked) ? NK_CHART_CLICKED: 0; + color = chart->slots[slot].highlight; + } + nk_fill_rect(out, item, 0, color); + chart->slots[slot].index += 1; + return ret; +} +NK_API nk_flags +nk_chart_push_slot(struct nk_context *ctx, float value, int slot) +{ + nk_flags flags; + struct nk_window *win; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(slot >= 0 && slot < NK_CHART_MAX_SLOT); + NK_ASSERT(slot < ctx->current->layout->chart.slot); + if (!ctx || !ctx->current || slot >= NK_CHART_MAX_SLOT) return nk_false; + if (slot >= ctx->current->layout->chart.slot) return nk_false; + + win = ctx->current; + if (win->layout->chart.slot < slot) return nk_false; + switch (win->layout->chart.slots[slot].type) { + case NK_CHART_LINES: + flags = nk_chart_push_line(ctx, win, &win->layout->chart, value, slot); break; + case NK_CHART_COLUMN: + flags = nk_chart_push_column(ctx, win, &win->layout->chart, value, slot); break; + default: + case NK_CHART_MAX: + flags = 0; + } + return flags; +} +NK_API nk_flags +nk_chart_push(struct nk_context *ctx, float value) +{ + return nk_chart_push_slot(ctx, value, 0); +} +NK_API void +nk_chart_end(struct nk_context *ctx) +{ + struct nk_window *win; + struct nk_chart *chart; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + if (!ctx || !ctx->current) + return; + + win = ctx->current; + chart = &win->layout->chart; + NK_MEMSET(chart, 0, sizeof(*chart)); + return; +} +NK_API void +nk_plot(struct nk_context *ctx, enum nk_chart_type type, const float *values, + int count, int offset) +{ + int i = 0; + float min_value; + float max_value; + + NK_ASSERT(ctx); + NK_ASSERT(values); + if (!ctx || !values || !count) return; + + min_value = values[offset]; + max_value = values[offset]; + for (i = 0; i < count; ++i) { + min_value = NK_MIN(values[i + offset], min_value); + max_value = NK_MAX(values[i + offset], max_value); + } + + if (nk_chart_begin(ctx, type, count, min_value, max_value)) { + for (i = 0; i < count; ++i) + nk_chart_push(ctx, values[i + offset]); + nk_chart_end(ctx); + } +} +NK_API void +nk_plot_function(struct nk_context *ctx, enum nk_chart_type type, void *userdata, + float(*value_getter)(void* user, int index), int count, int offset) +{ + int i = 0; + float min_value; + float max_value; + + NK_ASSERT(ctx); + NK_ASSERT(value_getter); + if (!ctx || !value_getter || !count) return; + + max_value = min_value = value_getter(userdata, offset); + for (i = 0; i < count; ++i) { + float value = value_getter(userdata, i + offset); + min_value = NK_MIN(value, min_value); + max_value = NK_MAX(value, max_value); + } + + if (nk_chart_begin(ctx, type, count, min_value, max_value)) { + for (i = 0; i < count; ++i) + nk_chart_push(ctx, value_getter(userdata, i + offset)); + nk_chart_end(ctx); + } +} + + + + + +/* ============================================================== + * + * COLOR PICKER + * + * ===============================================================*/ +NK_LIB nk_bool +nk_color_picker_behavior(nk_flags *state, + const struct nk_rect *bounds, const struct nk_rect *matrix, + const struct nk_rect *hue_bar, const struct nk_rect *alpha_bar, + struct nk_colorf *color, const struct nk_input *in) +{ + float hsva[4]; + nk_bool value_changed = 0; + nk_bool hsv_changed = 0; + + NK_ASSERT(state); + NK_ASSERT(matrix); + NK_ASSERT(hue_bar); + NK_ASSERT(color); + + /* color matrix */ + nk_colorf_hsva_fv(hsva, *color); + if (nk_button_behavior(state, *matrix, in, NK_BUTTON_REPEATER)) { + hsva[1] = NK_SATURATE((in->mouse.pos.x - matrix->x) / (matrix->w-1)); + hsva[2] = 1.0f - NK_SATURATE((in->mouse.pos.y - matrix->y) / (matrix->h-1)); + value_changed = hsv_changed = 1; + } + /* hue bar */ + if (nk_button_behavior(state, *hue_bar, in, NK_BUTTON_REPEATER)) { + hsva[0] = NK_SATURATE((in->mouse.pos.y - hue_bar->y) / (hue_bar->h-1)); + value_changed = hsv_changed = 1; + } + /* alpha bar */ + if (alpha_bar) { + if (nk_button_behavior(state, *alpha_bar, in, NK_BUTTON_REPEATER)) { + hsva[3] = 1.0f - NK_SATURATE((in->mouse.pos.y - alpha_bar->y) / (alpha_bar->h-1)); + value_changed = 1; + } + } + nk_widget_state_reset(state); + if (hsv_changed) { + *color = nk_hsva_colorfv(hsva); + *state = NK_WIDGET_STATE_ACTIVE; + } + if (value_changed) { + color->a = hsva[3]; + *state = NK_WIDGET_STATE_ACTIVE; + } + /* set color picker widget state */ + if (nk_input_is_mouse_hovering_rect(in, *bounds)) + *state = NK_WIDGET_STATE_HOVERED; + if (*state & NK_WIDGET_STATE_HOVER && !nk_input_is_mouse_prev_hovering_rect(in, *bounds)) + *state |= NK_WIDGET_STATE_ENTERED; + else if (nk_input_is_mouse_prev_hovering_rect(in, *bounds)) + *state |= NK_WIDGET_STATE_LEFT; + return value_changed; +} +NK_LIB void +nk_draw_color_picker(struct nk_command_buffer *o, const struct nk_rect *matrix, + const struct nk_rect *hue_bar, const struct nk_rect *alpha_bar, + struct nk_colorf col) +{ + NK_STORAGE const struct nk_color black = {0,0,0,255}; + NK_STORAGE const struct nk_color white = {255, 255, 255, 255}; + NK_STORAGE const struct nk_color black_trans = {0,0,0,0}; + + const float crosshair_size = 7.0f; + struct nk_color temp; + float hsva[4]; + float line_y; + int i; + + NK_ASSERT(o); + NK_ASSERT(matrix); + NK_ASSERT(hue_bar); + + /* draw hue bar */ + nk_colorf_hsva_fv(hsva, col); + for (i = 0; i < 6; ++i) { + NK_GLOBAL const struct nk_color hue_colors[] = { + {255, 0, 0, 255}, {255,255,0,255}, {0,255,0,255}, {0, 255,255,255}, + {0,0,255,255}, {255, 0, 255, 255}, {255, 0, 0, 255} + }; + nk_fill_rect_multi_color(o, + nk_rect(hue_bar->x, hue_bar->y + (float)i * (hue_bar->h/6.0f) + 0.5f, + hue_bar->w, (hue_bar->h/6.0f) + 0.5f), hue_colors[i], hue_colors[i], + hue_colors[i+1], hue_colors[i+1]); + } + line_y = (float)(int)(hue_bar->y + hsva[0] * matrix->h + 0.5f); + nk_stroke_line(o, hue_bar->x-1, line_y, hue_bar->x + hue_bar->w + 2, + line_y, 1, nk_rgb(255,255,255)); + + /* draw alpha bar */ + if (alpha_bar) { + float alpha = NK_SATURATE(col.a); + line_y = (float)(int)(alpha_bar->y + (1.0f - alpha) * matrix->h + 0.5f); + + nk_fill_rect_multi_color(o, *alpha_bar, white, white, black, black); + nk_stroke_line(o, alpha_bar->x-1, line_y, alpha_bar->x + alpha_bar->w + 2, + line_y, 1, nk_rgb(255,255,255)); + } + + /* draw color matrix */ + temp = nk_hsv_f(hsva[0], 1.0f, 1.0f); + nk_fill_rect_multi_color(o, *matrix, white, temp, temp, white); + nk_fill_rect_multi_color(o, *matrix, black_trans, black_trans, black, black); + + /* draw cross-hair */ + {struct nk_vec2 p; float S = hsva[1]; float V = hsva[2]; + p.x = (float)(int)(matrix->x + S * matrix->w); + p.y = (float)(int)(matrix->y + (1.0f - V) * matrix->h); + nk_stroke_line(o, p.x - crosshair_size, p.y, p.x-2, p.y, 1.0f, white); + nk_stroke_line(o, p.x + crosshair_size + 1, p.y, p.x+3, p.y, 1.0f, white); + nk_stroke_line(o, p.x, p.y + crosshair_size + 1, p.x, p.y+3, 1.0f, white); + nk_stroke_line(o, p.x, p.y - crosshair_size, p.x, p.y-2, 1.0f, white);} +} +NK_LIB nk_bool +nk_do_color_picker(nk_flags *state, + struct nk_command_buffer *out, struct nk_colorf *col, + enum nk_color_format fmt, struct nk_rect bounds, + struct nk_vec2 padding, const struct nk_input *in, + const struct nk_user_font *font) +{ + int ret = 0; + struct nk_rect matrix; + struct nk_rect hue_bar; + struct nk_rect alpha_bar; + float bar_w; + + NK_ASSERT(out); + NK_ASSERT(col); + NK_ASSERT(state); + NK_ASSERT(font); + if (!out || !col || !state || !font) + return ret; + + bar_w = font->height; + bounds.x += padding.x; + bounds.y += padding.x; + bounds.w -= 2 * padding.x; + bounds.h -= 2 * padding.y; + + matrix.x = bounds.x; + matrix.y = bounds.y; + matrix.h = bounds.h; + matrix.w = bounds.w - (3 * padding.x + 2 * bar_w); + + hue_bar.w = bar_w; + hue_bar.y = bounds.y; + hue_bar.h = matrix.h; + hue_bar.x = matrix.x + matrix.w + padding.x; + + alpha_bar.x = hue_bar.x + hue_bar.w + padding.x; + alpha_bar.y = bounds.y; + alpha_bar.w = bar_w; + alpha_bar.h = matrix.h; + + ret = nk_color_picker_behavior(state, &bounds, &matrix, &hue_bar, + (fmt == NK_RGBA) ? &alpha_bar:0, col, in); + nk_draw_color_picker(out, &matrix, &hue_bar, (fmt == NK_RGBA) ? &alpha_bar:0, *col); + return ret; +} +NK_API nk_bool +nk_color_pick(struct nk_context * ctx, struct nk_colorf *color, + enum nk_color_format fmt) +{ + struct nk_window *win; + struct nk_panel *layout; + const struct nk_style *config; + const struct nk_input *in; + + enum nk_widget_layout_states state; + struct nk_rect bounds; + + NK_ASSERT(ctx); + NK_ASSERT(color); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout || !color) + return 0; + + win = ctx->current; + config = &ctx->style; + layout = win->layout; + state = nk_widget(&bounds, ctx); + if (!state) return 0; + in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; + return nk_do_color_picker(&ctx->last_widget_state, &win->buffer, color, fmt, bounds, + nk_vec2(0,0), in, config->font); +} +NK_API struct nk_colorf +nk_color_picker(struct nk_context *ctx, struct nk_colorf color, + enum nk_color_format fmt) +{ + nk_color_pick(ctx, &color, fmt); + return color; +} + + + + + +/* ============================================================== + * + * COMBO + * + * ===============================================================*/ +NK_INTERN nk_bool +nk_combo_begin(struct nk_context *ctx, struct nk_window *win, + struct nk_vec2 size, nk_bool is_clicked, struct nk_rect header) +{ + struct nk_window *popup; + int is_open = 0; + int is_active = 0; + struct nk_rect body; + nk_hash hash; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return 0; + + popup = win->popup.win; + body.x = header.x; + body.w = size.x; + body.y = header.y + header.h-ctx->style.window.combo_border; + body.h = size.y; + + hash = win->popup.combo_count++; + is_open = (popup) ? nk_true:nk_false; + is_active = (popup && (win->popup.name == hash) && win->popup.type == NK_PANEL_COMBO); + if ((is_clicked && is_open && !is_active) || (is_open && !is_active) || + (!is_open && !is_active && !is_clicked)) return 0; + if (!nk_nonblock_begin(ctx, 0, body, + (is_clicked && is_open)?nk_rect(0,0,0,0):header, NK_PANEL_COMBO)) return 0; + + win->popup.type = NK_PANEL_COMBO; + win->popup.name = hash; + return 1; +} +NK_API nk_bool +nk_combo_begin_text(struct nk_context *ctx, const char *selected, int len, + struct nk_vec2 size) +{ + const struct nk_input *in; + struct nk_window *win; + struct nk_style *style; + + enum nk_widget_layout_states s; + int is_clicked = nk_false; + struct nk_rect header; + const struct nk_style_item *background; + struct nk_text text; + + NK_ASSERT(ctx); + NK_ASSERT(selected); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout || !selected) + return 0; + + win = ctx->current; + style = &ctx->style; + s = nk_widget(&header, ctx); + if (s == NK_WIDGET_INVALID) + return 0; + + in = (win->layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_ROM)? 0: &ctx->input; + if (nk_button_behavior(&ctx->last_widget_state, header, in, NK_BUTTON_DEFAULT)) + is_clicked = nk_true; + + /* draw combo box header background and border */ + if (ctx->last_widget_state & NK_WIDGET_STATE_ACTIVED) { + background = &style->combo.active; + text.text = style->combo.label_active; + } else if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER) { + background = &style->combo.hover; + text.text = style->combo.label_hover; + } else { + background = &style->combo.normal; + text.text = style->combo.label_normal; + } + + switch(background->type) { + case NK_STYLE_ITEM_IMAGE: + text.background = nk_rgba(0, 0, 0, 0); + nk_draw_image(&win->buffer, header, &background->data.image, nk_white); + break; + case NK_STYLE_ITEM_NINE_SLICE: + text.background = nk_rgba(0, 0, 0, 0); + nk_draw_nine_slice(&win->buffer, header, &background->data.slice, nk_white); + break; + case NK_STYLE_ITEM_COLOR: + text.background = background->data.color; + nk_fill_rect(&win->buffer, header, style->combo.rounding, background->data.color); + nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, style->combo.border_color); + break; + } + { + /* print currently selected text item */ + struct nk_rect label; + struct nk_rect button; + struct nk_rect content; + int draw_button_symbol; + + enum nk_symbol_type sym; + if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER) + sym = style->combo.sym_hover; + else if (is_clicked) + sym = style->combo.sym_active; + else + sym = style->combo.sym_normal; + + /* represents whether or not the combo's button symbol should be drawn */ + draw_button_symbol = sym != NK_SYMBOL_NONE; + + /* calculate button */ + button.w = header.h - 2 * style->combo.button_padding.y; + button.x = (header.x + header.w - header.h) - style->combo.button_padding.x; + button.y = header.y + style->combo.button_padding.y; + button.h = button.w; + + content.x = button.x + style->combo.button.padding.x; + content.y = button.y + style->combo.button.padding.y; + content.w = button.w - 2 * style->combo.button.padding.x; + content.h = button.h - 2 * style->combo.button.padding.y; + + /* draw selected label */ + text.padding = nk_vec2(0,0); + label.x = header.x + style->combo.content_padding.x; + label.y = header.y + style->combo.content_padding.y; + label.h = header.h - 2 * style->combo.content_padding.y; + if (draw_button_symbol) + label.w = button.x - (style->combo.content_padding.x + style->combo.spacing.x) - label.x; + else + label.w = header.w - 2 * style->combo.content_padding.x; + nk_widget_text(&win->buffer, label, selected, len, &text, + NK_TEXT_LEFT, ctx->style.font); + + /* draw open/close button */ + if (draw_button_symbol) + nk_draw_button_symbol(&win->buffer, &button, &content, ctx->last_widget_state, + &ctx->style.combo.button, sym, style->font); + } + return nk_combo_begin(ctx, win, size, is_clicked, header); +} +NK_API nk_bool +nk_combo_begin_label(struct nk_context *ctx, const char *selected, struct nk_vec2 size) +{ + return nk_combo_begin_text(ctx, selected, nk_strlen(selected), size); +} +NK_API nk_bool +nk_combo_begin_color(struct nk_context *ctx, struct nk_color color, struct nk_vec2 size) +{ + struct nk_window *win; + struct nk_style *style; + const struct nk_input *in; + + struct nk_rect header; + int is_clicked = nk_false; + enum nk_widget_layout_states s; + const struct nk_style_item *background; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return 0; + + win = ctx->current; + style = &ctx->style; + s = nk_widget(&header, ctx); + if (s == NK_WIDGET_INVALID) + return 0; + + in = (win->layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_ROM)? 0: &ctx->input; + if (nk_button_behavior(&ctx->last_widget_state, header, in, NK_BUTTON_DEFAULT)) + is_clicked = nk_true; + + /* draw combo box header background and border */ + if (ctx->last_widget_state & NK_WIDGET_STATE_ACTIVED) + background = &style->combo.active; + else if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER) + background = &style->combo.hover; + else background = &style->combo.normal; + + switch(background->type) { + case NK_STYLE_ITEM_IMAGE: + nk_draw_image(&win->buffer, header, &background->data.image, nk_white); + break; + case NK_STYLE_ITEM_NINE_SLICE: + nk_draw_nine_slice(&win->buffer, header, &background->data.slice, nk_white); + break; + case NK_STYLE_ITEM_COLOR: + nk_fill_rect(&win->buffer, header, style->combo.rounding, background->data.color); + nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, style->combo.border_color); + break; + } + { + struct nk_rect content; + struct nk_rect button; + struct nk_rect bounds; + int draw_button_symbol; + + enum nk_symbol_type sym; + if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER) + sym = style->combo.sym_hover; + else if (is_clicked) + sym = style->combo.sym_active; + else sym = style->combo.sym_normal; + + /* represents whether or not the combo's button symbol should be drawn */ + draw_button_symbol = sym != NK_SYMBOL_NONE; + + /* calculate button */ + button.w = header.h - 2 * style->combo.button_padding.y; + button.x = (header.x + header.w - header.h) - style->combo.button_padding.x; + button.y = header.y + style->combo.button_padding.y; + button.h = button.w; + + content.x = button.x + style->combo.button.padding.x; + content.y = button.y + style->combo.button.padding.y; + content.w = button.w - 2 * style->combo.button.padding.x; + content.h = button.h - 2 * style->combo.button.padding.y; + + /* draw color */ + bounds.h = header.h - 4 * style->combo.content_padding.y; + bounds.y = header.y + 2 * style->combo.content_padding.y; + bounds.x = header.x + 2 * style->combo.content_padding.x; + if (draw_button_symbol) + bounds.w = (button.x - (style->combo.content_padding.x + style->combo.spacing.x)) - bounds.x; + else + bounds.w = header.w - 4 * style->combo.content_padding.x; + nk_fill_rect(&win->buffer, bounds, 0, color); + + /* draw open/close button */ + if (draw_button_symbol) + nk_draw_button_symbol(&win->buffer, &button, &content, ctx->last_widget_state, + &ctx->style.combo.button, sym, style->font); + } + return nk_combo_begin(ctx, win, size, is_clicked, header); +} +NK_API nk_bool +nk_combo_begin_symbol(struct nk_context *ctx, enum nk_symbol_type symbol, struct nk_vec2 size) +{ + struct nk_window *win; + struct nk_style *style; + const struct nk_input *in; + + struct nk_rect header; + int is_clicked = nk_false; + enum nk_widget_layout_states s; + const struct nk_style_item *background; + struct nk_color sym_background; + struct nk_color symbol_color; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return 0; + + win = ctx->current; + style = &ctx->style; + s = nk_widget(&header, ctx); + if (s == NK_WIDGET_INVALID) + return 0; + + in = (win->layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_ROM)? 0: &ctx->input; + if (nk_button_behavior(&ctx->last_widget_state, header, in, NK_BUTTON_DEFAULT)) + is_clicked = nk_true; + + /* draw combo box header background and border */ + if (ctx->last_widget_state & NK_WIDGET_STATE_ACTIVED) { + background = &style->combo.active; + symbol_color = style->combo.symbol_active; + } else if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER) { + background = &style->combo.hover; + symbol_color = style->combo.symbol_hover; + } else { + background = &style->combo.normal; + symbol_color = style->combo.symbol_hover; + } + + switch(background->type) { + case NK_STYLE_ITEM_IMAGE: + sym_background = nk_rgba(0, 0, 0, 0); + nk_draw_image(&win->buffer, header, &background->data.image, nk_white); + break; + case NK_STYLE_ITEM_NINE_SLICE: + sym_background = nk_rgba(0, 0, 0, 0); + nk_draw_nine_slice(&win->buffer, header, &background->data.slice, nk_white); + break; + case NK_STYLE_ITEM_COLOR: + sym_background = background->data.color; + nk_fill_rect(&win->buffer, header, style->combo.rounding, background->data.color); + nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, style->combo.border_color); + break; + } + { + struct nk_rect bounds = {0,0,0,0}; + struct nk_rect content; + struct nk_rect button; + + enum nk_symbol_type sym; + if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER) + sym = style->combo.sym_hover; + else if (is_clicked) + sym = style->combo.sym_active; + else sym = style->combo.sym_normal; + + /* calculate button */ + button.w = header.h - 2 * style->combo.button_padding.y; + button.x = (header.x + header.w - header.h) - style->combo.button_padding.y; + button.y = header.y + style->combo.button_padding.y; + button.h = button.w; + + content.x = button.x + style->combo.button.padding.x; + content.y = button.y + style->combo.button.padding.y; + content.w = button.w - 2 * style->combo.button.padding.x; + content.h = button.h - 2 * style->combo.button.padding.y; + + /* draw symbol */ + bounds.h = header.h - 2 * style->combo.content_padding.y; + bounds.y = header.y + style->combo.content_padding.y; + bounds.x = header.x + style->combo.content_padding.x; + bounds.w = (button.x - style->combo.content_padding.y) - bounds.x; + nk_draw_symbol(&win->buffer, symbol, bounds, sym_background, symbol_color, + 1.0f, style->font); + + /* draw open/close button */ + nk_draw_button_symbol(&win->buffer, &bounds, &content, ctx->last_widget_state, + &ctx->style.combo.button, sym, style->font); + } + return nk_combo_begin(ctx, win, size, is_clicked, header); +} +NK_API nk_bool +nk_combo_begin_symbol_text(struct nk_context *ctx, const char *selected, int len, + enum nk_symbol_type symbol, struct nk_vec2 size) +{ + struct nk_window *win; + struct nk_style *style; + struct nk_input *in; + + struct nk_rect header; + int is_clicked = nk_false; + enum nk_widget_layout_states s; + const struct nk_style_item *background; + struct nk_color symbol_color; + struct nk_text text; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return 0; + + win = ctx->current; + style = &ctx->style; + s = nk_widget(&header, ctx); + if (!s) return 0; + + in = (win->layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_ROM)? 0: &ctx->input; + if (nk_button_behavior(&ctx->last_widget_state, header, in, NK_BUTTON_DEFAULT)) + is_clicked = nk_true; + + /* draw combo box header background and border */ + if (ctx->last_widget_state & NK_WIDGET_STATE_ACTIVED) { + background = &style->combo.active; + symbol_color = style->combo.symbol_active; + text.text = style->combo.label_active; + } else if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER) { + background = &style->combo.hover; + symbol_color = style->combo.symbol_hover; + text.text = style->combo.label_hover; + } else { + background = &style->combo.normal; + symbol_color = style->combo.symbol_normal; + text.text = style->combo.label_normal; + } + + switch(background->type) { + case NK_STYLE_ITEM_IMAGE: + text.background = nk_rgba(0, 0, 0, 0); + nk_draw_image(&win->buffer, header, &background->data.image, nk_white); + break; + case NK_STYLE_ITEM_NINE_SLICE: + text.background = nk_rgba(0, 0, 0, 0); + nk_draw_nine_slice(&win->buffer, header, &background->data.slice, nk_white); + break; + case NK_STYLE_ITEM_COLOR: + text.background = background->data.color; + nk_fill_rect(&win->buffer, header, style->combo.rounding, background->data.color); + nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, style->combo.border_color); + break; + } + { + struct nk_rect content; + struct nk_rect button; + struct nk_rect label; + struct nk_rect image; + + enum nk_symbol_type sym; + if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER) + sym = style->combo.sym_hover; + else if (is_clicked) + sym = style->combo.sym_active; + else sym = style->combo.sym_normal; + + /* calculate button */ + button.w = header.h - 2 * style->combo.button_padding.y; + button.x = (header.x + header.w - header.h) - style->combo.button_padding.x; + button.y = header.y + style->combo.button_padding.y; + button.h = button.w; + + content.x = button.x + style->combo.button.padding.x; + content.y = button.y + style->combo.button.padding.y; + content.w = button.w - 2 * style->combo.button.padding.x; + content.h = button.h - 2 * style->combo.button.padding.y; + nk_draw_button_symbol(&win->buffer, &button, &content, ctx->last_widget_state, + &ctx->style.combo.button, sym, style->font); + + /* draw symbol */ + image.x = header.x + style->combo.content_padding.x; + image.y = header.y + style->combo.content_padding.y; + image.h = header.h - 2 * style->combo.content_padding.y; + image.w = image.h; + nk_draw_symbol(&win->buffer, symbol, image, text.background, symbol_color, + 1.0f, style->font); + + /* draw label */ + text.padding = nk_vec2(0,0); + label.x = image.x + image.w + style->combo.spacing.x + style->combo.content_padding.x; + label.y = header.y + style->combo.content_padding.y; + label.w = (button.x - style->combo.content_padding.x) - label.x; + label.h = header.h - 2 * style->combo.content_padding.y; + nk_widget_text(&win->buffer, label, selected, len, &text, NK_TEXT_LEFT, style->font); + } + return nk_combo_begin(ctx, win, size, is_clicked, header); +} +NK_API nk_bool +nk_combo_begin_image(struct nk_context *ctx, struct nk_image img, struct nk_vec2 size) +{ + struct nk_window *win; + struct nk_style *style; + const struct nk_input *in; + + struct nk_rect header; + int is_clicked = nk_false; + enum nk_widget_layout_states s; + const struct nk_style_item *background; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return 0; + + win = ctx->current; + style = &ctx->style; + s = nk_widget(&header, ctx); + if (s == NK_WIDGET_INVALID) + return 0; + + in = (win->layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_ROM)? 0: &ctx->input; + if (nk_button_behavior(&ctx->last_widget_state, header, in, NK_BUTTON_DEFAULT)) + is_clicked = nk_true; + + /* draw combo box header background and border */ + if (ctx->last_widget_state & NK_WIDGET_STATE_ACTIVED) + background = &style->combo.active; + else if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER) + background = &style->combo.hover; + else background = &style->combo.normal; + + switch (background->type) { + case NK_STYLE_ITEM_IMAGE: + nk_draw_image(&win->buffer, header, &background->data.image, nk_white); + break; + case NK_STYLE_ITEM_NINE_SLICE: + nk_draw_nine_slice(&win->buffer, header, &background->data.slice, nk_white); + break; + case NK_STYLE_ITEM_COLOR: + nk_fill_rect(&win->buffer, header, style->combo.rounding, background->data.color); + nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, style->combo.border_color); + break; + } + { + struct nk_rect bounds = {0,0,0,0}; + struct nk_rect content; + struct nk_rect button; + int draw_button_symbol; + + enum nk_symbol_type sym; + if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER) + sym = style->combo.sym_hover; + else if (is_clicked) + sym = style->combo.sym_active; + else sym = style->combo.sym_normal; + + /* represents whether or not the combo's button symbol should be drawn */ + draw_button_symbol = sym != NK_SYMBOL_NONE; + + /* calculate button */ + button.w = header.h - 2 * style->combo.button_padding.y; + button.x = (header.x + header.w - header.h) - style->combo.button_padding.y; + button.y = header.y + style->combo.button_padding.y; + button.h = button.w; + + content.x = button.x + style->combo.button.padding.x; + content.y = button.y + style->combo.button.padding.y; + content.w = button.w - 2 * style->combo.button.padding.x; + content.h = button.h - 2 * style->combo.button.padding.y; + + /* draw image */ + bounds.h = header.h - 2 * style->combo.content_padding.y; + bounds.y = header.y + style->combo.content_padding.y; + bounds.x = header.x + style->combo.content_padding.x; + if (draw_button_symbol) + bounds.w = (button.x - style->combo.content_padding.y) - bounds.x; + else + bounds.w = header.w - 2 * style->combo.content_padding.x; + nk_draw_image(&win->buffer, bounds, &img, nk_white); + + /* draw open/close button */ + if (draw_button_symbol) + nk_draw_button_symbol(&win->buffer, &bounds, &content, ctx->last_widget_state, + &ctx->style.combo.button, sym, style->font); + } + return nk_combo_begin(ctx, win, size, is_clicked, header); +} +NK_API nk_bool +nk_combo_begin_image_text(struct nk_context *ctx, const char *selected, int len, + struct nk_image img, struct nk_vec2 size) +{ + struct nk_window *win; + struct nk_style *style; + struct nk_input *in; + + struct nk_rect header; + int is_clicked = nk_false; + enum nk_widget_layout_states s; + const struct nk_style_item *background; + struct nk_text text; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return 0; + + win = ctx->current; + style = &ctx->style; + s = nk_widget(&header, ctx); + if (!s) return 0; + + in = (win->layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_ROM)? 0: &ctx->input; + if (nk_button_behavior(&ctx->last_widget_state, header, in, NK_BUTTON_DEFAULT)) + is_clicked = nk_true; + + /* draw combo box header background and border */ + if (ctx->last_widget_state & NK_WIDGET_STATE_ACTIVED) { + background = &style->combo.active; + text.text = style->combo.label_active; + } else if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER) { + background = &style->combo.hover; + text.text = style->combo.label_hover; + } else { + background = &style->combo.normal; + text.text = style->combo.label_normal; + } + + switch(background->type) { + case NK_STYLE_ITEM_IMAGE: + text.background = nk_rgba(0, 0, 0, 0); + nk_draw_image(&win->buffer, header, &background->data.image, nk_white); + break; + case NK_STYLE_ITEM_NINE_SLICE: + text.background = nk_rgba(0, 0, 0, 0); + nk_draw_nine_slice(&win->buffer, header, &background->data.slice, nk_white); + break; + case NK_STYLE_ITEM_COLOR: + text.background = background->data.color; + nk_fill_rect(&win->buffer, header, style->combo.rounding, background->data.color); + nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, style->combo.border_color); + break; + } + { + struct nk_rect content; + struct nk_rect button; + struct nk_rect label; + struct nk_rect image; + int draw_button_symbol; + + enum nk_symbol_type sym; + if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER) + sym = style->combo.sym_hover; + else if (is_clicked) + sym = style->combo.sym_active; + else sym = style->combo.sym_normal; + + /* represents whether or not the combo's button symbol should be drawn */ + draw_button_symbol = sym != NK_SYMBOL_NONE; + + /* calculate button */ + button.w = header.h - 2 * style->combo.button_padding.y; + button.x = (header.x + header.w - header.h) - style->combo.button_padding.x; + button.y = header.y + style->combo.button_padding.y; + button.h = button.w; + + content.x = button.x + style->combo.button.padding.x; + content.y = button.y + style->combo.button.padding.y; + content.w = button.w - 2 * style->combo.button.padding.x; + content.h = button.h - 2 * style->combo.button.padding.y; + if (draw_button_symbol) + nk_draw_button_symbol(&win->buffer, &button, &content, ctx->last_widget_state, + &ctx->style.combo.button, sym, style->font); + + /* draw image */ + image.x = header.x + style->combo.content_padding.x; + image.y = header.y + style->combo.content_padding.y; + image.h = header.h - 2 * style->combo.content_padding.y; + image.w = image.h; + nk_draw_image(&win->buffer, image, &img, nk_white); + + /* draw label */ + text.padding = nk_vec2(0,0); + label.x = image.x + image.w + style->combo.spacing.x + style->combo.content_padding.x; + label.y = header.y + style->combo.content_padding.y; + label.h = header.h - 2 * style->combo.content_padding.y; + if (draw_button_symbol) + label.w = (button.x - style->combo.content_padding.x) - label.x; + else + label.w = (header.x + header.w - style->combo.content_padding.x) - label.x; + nk_widget_text(&win->buffer, label, selected, len, &text, NK_TEXT_LEFT, style->font); + } + return nk_combo_begin(ctx, win, size, is_clicked, header); +} +NK_API nk_bool +nk_combo_begin_symbol_label(struct nk_context *ctx, + const char *selected, enum nk_symbol_type type, struct nk_vec2 size) +{ + return nk_combo_begin_symbol_text(ctx, selected, nk_strlen(selected), type, size); +} +NK_API nk_bool +nk_combo_begin_image_label(struct nk_context *ctx, + const char *selected, struct nk_image img, struct nk_vec2 size) +{ + return nk_combo_begin_image_text(ctx, selected, nk_strlen(selected), img, size); +} +NK_API nk_bool +nk_combo_item_text(struct nk_context *ctx, const char *text, int len,nk_flags align) +{ + return nk_contextual_item_text(ctx, text, len, align); +} +NK_API nk_bool +nk_combo_item_label(struct nk_context *ctx, const char *label, nk_flags align) +{ + return nk_contextual_item_label(ctx, label, align); +} +NK_API nk_bool +nk_combo_item_image_text(struct nk_context *ctx, struct nk_image img, const char *text, + int len, nk_flags alignment) +{ + return nk_contextual_item_image_text(ctx, img, text, len, alignment); +} +NK_API nk_bool +nk_combo_item_image_label(struct nk_context *ctx, struct nk_image img, + const char *text, nk_flags alignment) +{ + return nk_contextual_item_image_label(ctx, img, text, alignment); +} +NK_API nk_bool +nk_combo_item_symbol_text(struct nk_context *ctx, enum nk_symbol_type sym, + const char *text, int len, nk_flags alignment) +{ + return nk_contextual_item_symbol_text(ctx, sym, text, len, alignment); +} +NK_API nk_bool +nk_combo_item_symbol_label(struct nk_context *ctx, enum nk_symbol_type sym, + const char *label, nk_flags alignment) +{ + return nk_contextual_item_symbol_label(ctx, sym, label, alignment); +} +NK_API void nk_combo_end(struct nk_context *ctx) +{ + nk_contextual_end(ctx); +} +NK_API void nk_combo_close(struct nk_context *ctx) +{ + nk_contextual_close(ctx); +} +NK_API int +nk_combo(struct nk_context *ctx, const char **items, int count, + int selected, int item_height, struct nk_vec2 size) +{ + int i = 0; + int max_height; + struct nk_vec2 item_spacing; + struct nk_vec2 window_padding; + + NK_ASSERT(ctx); + NK_ASSERT(items); + NK_ASSERT(ctx->current); + if (!ctx || !items ||!count) + return selected; + + item_spacing = ctx->style.window.spacing; + window_padding = nk_panel_get_padding(&ctx->style, ctx->current->layout->type); + max_height = count * item_height + count * (int)item_spacing.y; + max_height += (int)item_spacing.y * 2 + (int)window_padding.y * 2; + size.y = NK_MIN(size.y, (float)max_height); + if (nk_combo_begin_label(ctx, items[selected], size)) { + nk_layout_row_dynamic(ctx, (float)item_height, 1); + for (i = 0; i < count; ++i) { + if (nk_combo_item_label(ctx, items[i], NK_TEXT_LEFT)) + selected = i; + } + nk_combo_end(ctx); + } + return selected; +} +NK_API int +nk_combo_separator(struct nk_context *ctx, const char *items_separated_by_separator, + int separator, int selected, int count, int item_height, struct nk_vec2 size) +{ + int i; + int max_height; + struct nk_vec2 item_spacing; + struct nk_vec2 window_padding; + const char *current_item; + const char *iter; + int length = 0; + + NK_ASSERT(ctx); + NK_ASSERT(items_separated_by_separator); + if (!ctx || !items_separated_by_separator) + return selected; + + /* calculate popup window */ + item_spacing = ctx->style.window.spacing; + window_padding = nk_panel_get_padding(&ctx->style, ctx->current->layout->type); + max_height = count * item_height + count * (int)item_spacing.y; + max_height += (int)item_spacing.y * 2 + (int)window_padding.y * 2; + size.y = NK_MIN(size.y, (float)max_height); + + /* find selected item */ + current_item = items_separated_by_separator; + for (i = 0; i < count; ++i) { + iter = current_item; + while (*iter && *iter != separator) iter++; + length = (int)(iter - current_item); + if (i == selected) break; + current_item = iter + 1; + } + + if (nk_combo_begin_text(ctx, current_item, length, size)) { + current_item = items_separated_by_separator; + nk_layout_row_dynamic(ctx, (float)item_height, 1); + for (i = 0; i < count; ++i) { + iter = current_item; + while (*iter && *iter != separator) iter++; + length = (int)(iter - current_item); + if (nk_combo_item_text(ctx, current_item, length, NK_TEXT_LEFT)) + selected = i; + current_item = current_item + length + 1; + } + nk_combo_end(ctx); + } + return selected; +} +NK_API int +nk_combo_string(struct nk_context *ctx, const char *items_separated_by_zeros, + int selected, int count, int item_height, struct nk_vec2 size) +{ + return nk_combo_separator(ctx, items_separated_by_zeros, '\0', selected, count, item_height, size); +} +NK_API int +nk_combo_callback(struct nk_context *ctx, void(*item_getter)(void*, int, const char**), + void *userdata, int selected, int count, int item_height, struct nk_vec2 size) +{ + int i; + int max_height; + struct nk_vec2 item_spacing; + struct nk_vec2 window_padding; + const char *item; + + NK_ASSERT(ctx); + NK_ASSERT(item_getter); + if (!ctx || !item_getter) + return selected; + + /* calculate popup window */ + item_spacing = ctx->style.window.spacing; + window_padding = nk_panel_get_padding(&ctx->style, ctx->current->layout->type); + max_height = count * item_height + count * (int)item_spacing.y; + max_height += (int)item_spacing.y * 2 + (int)window_padding.y * 2; + size.y = NK_MIN(size.y, (float)max_height); + + item_getter(userdata, selected, &item); + if (nk_combo_begin_label(ctx, item, size)) { + nk_layout_row_dynamic(ctx, (float)item_height, 1); + for (i = 0; i < count; ++i) { + item_getter(userdata, i, &item); + if (nk_combo_item_label(ctx, item, NK_TEXT_LEFT)) + selected = i; + } + nk_combo_end(ctx); + } return selected; +} +NK_API void +nk_combobox(struct nk_context *ctx, const char **items, int count, + int *selected, int item_height, struct nk_vec2 size) +{ + *selected = nk_combo(ctx, items, count, *selected, item_height, size); +} +NK_API void +nk_combobox_string(struct nk_context *ctx, const char *items_separated_by_zeros, + int *selected, int count, int item_height, struct nk_vec2 size) +{ + *selected = nk_combo_string(ctx, items_separated_by_zeros, *selected, count, item_height, size); +} +NK_API void +nk_combobox_separator(struct nk_context *ctx, const char *items_separated_by_separator, + int separator, int *selected, int count, int item_height, struct nk_vec2 size) +{ + *selected = nk_combo_separator(ctx, items_separated_by_separator, separator, + *selected, count, item_height, size); +} +NK_API void +nk_combobox_callback(struct nk_context *ctx, + void(*item_getter)(void* data, int id, const char **out_text), + void *userdata, int *selected, int count, int item_height, struct nk_vec2 size) +{ + *selected = nk_combo_callback(ctx, item_getter, userdata, *selected, count, item_height, size); +} + + + + + +/* =============================================================== + * + * TOOLTIP + * + * ===============================================================*/ +NK_API nk_bool +nk_tooltip_begin(struct nk_context *ctx, float width) +{ + int x,y,w,h; + struct nk_window *win; + const struct nk_input *in; + struct nk_rect bounds; + int ret; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return 0; + + /* make sure that no nonblocking popup is currently active */ + win = ctx->current; + in = &ctx->input; + if (win->popup.win && (win->popup.type & NK_PANEL_SET_NONBLOCK)) + return 0; + + w = nk_iceilf(width); + h = nk_iceilf(nk_null_rect.h); + x = nk_ifloorf(in->mouse.pos.x + 1) - (int)win->layout->clip.x; + y = nk_ifloorf(in->mouse.pos.y + 1) - (int)win->layout->clip.y; + + bounds.x = (float)x; + bounds.y = (float)y; + bounds.w = (float)w; + bounds.h = (float)h; + + ret = nk_popup_begin(ctx, NK_POPUP_DYNAMIC, + "__##Tooltip##__", NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_BORDER, bounds); + if (ret) win->layout->flags &= ~(nk_flags)NK_WINDOW_ROM; + win->popup.type = NK_PANEL_TOOLTIP; + ctx->current->layout->type = NK_PANEL_TOOLTIP; + return ret; +} + +NK_API void +nk_tooltip_end(struct nk_context *ctx) +{ + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + if (!ctx || !ctx->current) return; + ctx->current->seq--; + nk_popup_close(ctx); + nk_popup_end(ctx); +} +NK_API void +nk_tooltip(struct nk_context *ctx, const char *text) +{ + const struct nk_style *style; + struct nk_vec2 padding; + + int text_len; + float text_width; + float text_height; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + NK_ASSERT(text); + if (!ctx || !ctx->current || !ctx->current->layout || !text) + return; + + /* fetch configuration data */ + style = &ctx->style; + padding = style->window.padding; + + /* calculate size of the text and tooltip */ + text_len = nk_strlen(text); + text_width = style->font->width(style->font->userdata, + style->font->height, text, text_len); + text_width += (4 * padding.x); + text_height = (style->font->height + 2 * padding.y); + + /* execute tooltip and fill with text */ + if (nk_tooltip_begin(ctx, (float)text_width)) { + nk_layout_row_dynamic(ctx, (float)text_height, 1); + nk_text(ctx, text, text_len, NK_TEXT_LEFT); + nk_tooltip_end(ctx); + } +} +#ifdef NK_INCLUDE_STANDARD_VARARGS +NK_API void +nk_tooltipf(struct nk_context *ctx, const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + nk_tooltipfv(ctx, fmt, args); + va_end(args); +} +NK_API void +nk_tooltipfv(struct nk_context *ctx, const char *fmt, va_list args) +{ + char buf[256]; + nk_strfmt(buf, NK_LEN(buf), fmt, args); + nk_tooltip(ctx, buf); +} +#endif + + + +#endif /* NK_IMPLEMENTATION */ + +/* +/// ## License +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~none +/// ------------------------------------------------------------------------------ +/// This software is available under 2 licenses -- choose whichever you prefer. +/// ------------------------------------------------------------------------------ +/// ALTERNATIVE A - MIT License +/// Copyright (c) 2016-2018 Micha Mettke +/// Permission is hereby granted, free of charge, to any person obtaining a copy of +/// this software and associated documentation files (the "Software"), to deal in +/// the Software without restriction, including without limitation the rights to +/// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +/// of the Software, and to permit persons to whom the Software is furnished to do +/// so, subject to the following conditions: +/// The above copyright notice and this permission notice shall be included in all +/// copies or substantial portions of the Software. +/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +/// SOFTWARE. +/// ------------------------------------------------------------------------------ +/// ALTERNATIVE B - Public Domain (www.unlicense.org) +/// This is free and unencumbered software released into the public domain. +/// Anyone is free to copy, modify, publish, use, compile, sell, or distribute this +/// software, either in source code form or as a compiled binary, for any purpose, +/// commercial or non-commercial, and by any means. +/// In jurisdictions that recognize copyright laws, the author or authors of this +/// software dedicate any and all copyright interest in the software to the public +/// domain. We make this dedication for the benefit of the public at large and to +/// the detriment of our heirs and successors. We intend this dedication to be an +/// overt act of relinquishment in perpetuity of all present and future rights to +/// this software under copyright law. +/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +/// AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +/// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +/// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +/// ------------------------------------------------------------------------------ +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +/// ## Changelog +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~none +/// [date] ([x.y.z]) - [description] +/// - [date]: date on which the change has been pushed +/// - [x.y.z]: Version string, represented in Semantic Versioning format +/// - [x]: Major version with API and library breaking changes +/// - [y]: Minor version with non-breaking API and library changes +/// - [z]: Patch version with no direct changes to the API +/// +/// - 2022/12/23 (4.10.6) - Fix incorrect glyph index in nk_font_bake() +/// - 2022/12/17 (4.10.5) - Fix nk_font_bake_pack() using TTC font offset incorrectly +/// - 2022/10/24 (4.10.4) - Fix nk_str_{append,insert}_str_utf8 always returning 0 +/// - 2022/09/03 (4.10.3) - Renamed the `null` texture variable to `tex_null` +/// - 2022/08/01 (4.10.2) - Fix Apple Silicon with incorrect NK_SITE_TYPE and NK_POINTER_TYPE +/// - 2022/08/01 (4.10.1) - Fix cursor jumping back to beginning of text when typing more than +/// nk_edit_xxx limit +/// - 2022/05/27 (4.10.0) - Add nk_input_has_mouse_click_in_button_rect() to fix window move bug +/// - 2022/04/18 (4.9.7) - Change button behavior when NK_BUTTON_TRIGGER_ON_RELEASE is defined to +/// only trigger when the mouse position was inside the same button on down +/// - 2022/02/03 (4.9.6) - Allow overriding the NK_INV_SQRT function, similar to NK_SIN and NK_COS +/// - 2021/12/22 (4.9.5) - Revert layout bounds not accounting for padding due to regressions +/// - 2021/12/22 (4.9.4) - Fix checking hovering when window is minimized +/// - 2021/12/22 (4.09.3) - Fix layout bounds not accounting for padding +/// - 2021/12/19 (4.09.2) - Update to stb_rect_pack.h v1.01 and stb_truetype.h v1.26 +/// - 2021/12/16 (4.09.1) - Fix the majority of GCC warnings +/// - 2021/10/16 (4.09.0) - Added nk_spacer() widget +/// - 2021/09/22 (4.08.6) - Fix "may be used uninitialized" warnings in nk_widget +/// - 2021/09/22 (4.08.5) - GCC __builtin_offsetof only exists in version 4 and later +/// - 2021/09/15 (4.08.4) - Fix "'num_len' may be used uninitialized" in nk_do_property +/// - 2021/09/15 (4.08.3) - Fix "Templates cannot be declared to have 'C' Linkage" +/// - 2021/09/08 (4.08.2) - Fix warnings in C89 builds +/// - 2021/09/08 (4.08.1) - Use compiler builtins for NK_OFFSETOF when possible +/// - 2021/08/17 (4.08.0) - Implemented 9-slice scaling support for widget styles +/// - 2021/08/16 (4.07.5) - Replace usage of memset in nk_font_atlas_bake with NK_MEMSET +/// - 2021/08/15 (4.07.4) - Fix conversion and sign conversion warnings +/// - 2021/08/08 (4.07.3) - Fix crash when baking merged fonts +/// - 2021/08/08 (4.07.2) - Fix Multiline Edit wrong offset +/// - 2021/03/17 (4.07.1) - Fix warning about unused parameter +/// - 2021/03/17 (4.07.0) - Fix nk_property hover bug +/// - 2021/03/15 (4.06.4) - Change nk_propertyi back to int +/// - 2021/03/15 (4.06.3) - Update documentation for functions that now return nk_bool +/// - 2020/12/19 (4.06.2) - Fix additional C++ style comments which are not allowed in ISO C90. +/// - 2020/10/11 (4.06.1) - Fix C++ style comments which are not allowed in ISO C90. +/// - 2020/10/07 (4.06.0) - Fix nk_combo return type wrongly changed to nk_bool +/// - 2020/09/05 (4.05.0) - Use the nk_font_atlas allocator for stb_truetype memory management. +/// - 2020/09/04 (4.04.1) - Replace every boolean int by nk_bool +/// - 2020/09/04 (4.04.0) - Add nk_bool with NK_INCLUDE_STANDARD_BOOL +/// - 2020/06/13 (4.03.1) - Fix nk_pool allocation sizes. +/// - 2020/06/04 (4.03.0) - Made nk_combo header symbols optional. +/// - 2020/05/27 (4.02.5) - Fix nk_do_edit: Keep scroll position when re-activating edit widget. +/// - 2020/05/09 (4.02.4) - Fix nk_menubar height calculation bug +/// - 2020/05/08 (4.02.3) - Fix missing stdarg.h with NK_INCLUDE_STANDARD_VARARGS +/// - 2020/04/30 (4.02.2) - Fix nk_edit border drawing bug +/// - 2020/04/09 (4.02.1) - Removed unused nk_sqrt function to fix compiler warnings +/// - Fixed compiler warnings if you bring your own methods for +/// nk_cos/nk_sin/nk_strtod/nk_memset/nk_memcopy/nk_dtoa +/// - 2020/04/06 (4.01.10) - Fix bug: Do not use pool before checking for NULL +/// - 2020/03/22 (4.01.9) - Fix bug where layout state wasn't restored correctly after +/// popping a tree. +/// - 2020/03/11 (4.01.8) - Fix bug where padding is subtracted from widget +/// - 2020/03/06 (4.01.7) - Fix bug where width padding was applied twice +/// - 2020/02/06 (4.01.6) - Update stb_truetype.h and stb_rect_pack.h and separate them +/// - 2019/12/10 (4.01.5) - Fix off-by-one error in NK_INTERSECT +/// - 2019/10/09 (4.01.4) - Fix bug for autoscrolling in nk_do_edit +/// - 2019/09/20 (4.01.3) - Fixed a bug wherein combobox cannot be closed by clicking the header +/// when NK_BUTTON_TRIGGER_ON_RELEASE is defined. +/// - 2019/09/10 (4.01.2) - Fixed the nk_cos function, which deviated significantly. +/// - 2019/09/08 (4.01.1) - Fixed a bug wherein re-baking of fonts caused a segmentation +/// fault due to dst_font->glyph_count not being zeroed on subsequent +/// bakes of the same set of fonts. +/// - 2019/06/23 (4.01.0) - Added nk_***_get_scroll and nk_***_set_scroll for groups, windows, and popups. +/// - 2019/06/12 (4.00.3) - Fix panel background drawing bug. +/// - 2018/10/31 (4.00.2) - Added NK_KEYSTATE_BASED_INPUT to "fix" state based backends +/// like GLFW without breaking key repeat behavior on event based. +/// - 2018/04/01 (4.00.1) - Fixed calling `nk_convert` multiple time per single frame. +/// - 2018/04/01 (4.00.0) - BREAKING CHANGE: nk_draw_list_clear no longer tries to +/// clear provided buffers. So make sure to either free +/// or clear each passed buffer after calling nk_convert. +/// - 2018/02/23 (3.00.6) - Fixed slider dragging behavior. +/// - 2018/01/31 (3.00.5) - Fixed overcalculation of cursor data in font baking process. +/// - 2018/01/31 (3.00.4) - Removed name collision with stb_truetype. +/// - 2018/01/28 (3.00.3) - Fixed panel window border drawing bug. +/// - 2018/01/12 (3.00.2) - Added `nk_group_begin_titled` for separated group identifier and title. +/// - 2018/01/07 (3.00.1) - Started to change documentation style. +/// - 2018/01/05 (3.00.0) - BREAKING CHANGE: The previous color picker API was broken +/// because of conversions between float and byte color representation. +/// Color pickers now use floating point values to represent +/// HSV values. To get back the old behavior I added some additional +/// color conversion functions to cast between nk_color and +/// nk_colorf. +/// - 2017/12/23 (2.00.7) - Fixed small warning. +/// - 2017/12/23 (2.00.7) - Fixed `nk_edit_buffer` behavior if activated to allow input. +/// - 2017/12/23 (2.00.7) - Fixed modifyable progressbar dragging visuals and input behavior. +/// - 2017/12/04 (2.00.6) - Added formatted string tooltip widget. +/// - 2017/11/18 (2.00.5) - Fixed window becoming hidden with flag `NK_WINDOW_NO_INPUT`. +/// - 2017/11/15 (2.00.4) - Fixed font merging. +/// - 2017/11/07 (2.00.3) - Fixed window size and position modifier functions. +/// - 2017/09/14 (2.00.2) - Fixed `nk_edit_buffer` and `nk_edit_focus` behavior. +/// - 2017/09/14 (2.00.1) - Fixed window closing behavior. +/// - 2017/09/14 (2.00.0) - BREAKING CHANGE: Modifying window position and size functions now +/// require the name of the window and must happen outside the window +/// building process (between function call nk_begin and nk_end). +/// - 2017/09/11 (1.40.9) - Fixed window background flag if background window is declared last. +/// - 2017/08/27 (1.40.8) - Fixed `nk_item_is_any_active` for hidden windows. +/// - 2017/08/27 (1.40.7) - Fixed window background flag. +/// - 2017/07/07 (1.40.6) - Fixed missing clipping rect check for hovering/clicked +/// query for widgets. +/// - 2017/07/07 (1.40.5) - Fixed drawing bug for vertex output for lines and stroked +/// and filled rectangles. +/// - 2017/07/07 (1.40.4) - Fixed bug in nk_convert trying to add windows that are in +/// process of being destroyed. +/// - 2017/07/07 (1.40.3) - Fixed table internal bug caused by storing table size in +/// window instead of directly in table. +/// - 2017/06/30 (1.40.2) - Removed unneeded semicolon in C++ NK_ALIGNOF macro. +/// - 2017/06/30 (1.40.1) - Fixed drawing lines smaller or equal zero. +/// - 2017/06/08 (1.40.0) - Removed the breaking part of last commit. Auto layout now only +/// comes in effect if you pass in zero was row height argument. +/// - 2017/06/08 (1.40.0) - BREAKING CHANGE: while not directly API breaking it will change +/// how layouting works. From now there will be an internal minimum +/// row height derived from font height. If you need a row smaller than +/// that you can directly set it by `nk_layout_set_min_row_height` and +/// reset the value back by calling `nk_layout_reset_min_row_height. +/// - 2017/06/08 (1.39.1) - Fixed property text edit handling bug caused by past `nk_widget` fix. +/// - 2017/06/08 (1.39.0) - Added function to retrieve window space without calling a `nk_layout_xxx` function. +/// - 2017/06/06 (1.38.5) - Fixed `nk_convert` return flag for command buffer. +/// - 2017/05/23 (1.38.4) - Fixed activation behavior for widgets partially clipped. +/// - 2017/05/10 (1.38.3) - Fixed wrong min window size mouse scaling over boundaries. +/// - 2017/05/09 (1.38.2) - Fixed vertical scrollbar drawing with not enough space. +/// - 2017/05/09 (1.38.1) - Fixed scaler dragging behavior if window size hits minimum size. +/// - 2017/05/06 (1.38.0) - Added platform double-click support. +/// - 2017/04/20 (1.37.1) - Fixed key repeat found inside glfw demo backends. +/// - 2017/04/20 (1.37.0) - Extended properties with selection and clipboard support. +/// - 2017/04/20 (1.36.2) - Fixed #405 overlapping rows with zero padding and spacing. +/// - 2017/04/09 (1.36.1) - Fixed #403 with another widget float error. +/// - 2017/04/09 (1.36.0) - Added window `NK_WINDOW_NO_INPUT` and `NK_WINDOW_NOT_INTERACTIVE` flags. +/// - 2017/04/09 (1.35.3) - Fixed buffer heap corruption. +/// - 2017/03/25 (1.35.2) - Fixed popup overlapping for `NK_WINDOW_BACKGROUND` windows. +/// - 2017/03/25 (1.35.1) - Fixed windows closing behavior. +/// - 2017/03/18 (1.35.0) - Added horizontal scroll requested in #377. +/// - 2017/03/18 (1.34.3) - Fixed long window header titles. +/// - 2017/03/04 (1.34.2) - Fixed text edit filtering. +/// - 2017/03/04 (1.34.1) - Fixed group closable flag. +/// - 2017/02/25 (1.34.0) - Added custom draw command for better language binding support. +/// - 2017/01/24 (1.33.0) - Added programmatic way to remove edit focus. +/// - 2017/01/24 (1.32.3) - Fixed wrong define for basic type definitions for windows. +/// - 2017/01/21 (1.32.2) - Fixed input capture from hidden or closed windows. +/// - 2017/01/21 (1.32.1) - Fixed slider behavior and drawing. +/// - 2017/01/13 (1.32.0) - Added flag to put scaler into the bottom left corner. +/// - 2017/01/13 (1.31.0) - Added additional row layouting method to combine both +/// dynamic and static widgets. +/// - 2016/12/31 (1.30.0) - Extended scrollbar offset from 16-bit to 32-bit. +/// - 2016/12/31 (1.29.2) - Fixed closing window bug of minimized windows. +/// - 2016/12/03 (1.29.1) - Fixed wrapped text with no seperator and C89 error. +/// - 2016/12/03 (1.29.0) - Changed text wrapping to process words not characters. +/// - 2016/11/22 (1.28.6) - Fixed window minimized closing bug. +/// - 2016/11/19 (1.28.5) - Fixed abstract combo box closing behavior. +/// - 2016/11/19 (1.28.4) - Fixed tooltip flickering. +/// - 2016/11/19 (1.28.3) - Fixed memory leak caused by popup repeated closing. +/// - 2016/11/18 (1.28.2) - Fixed memory leak caused by popup panel allocation. +/// - 2016/11/10 (1.28.1) - Fixed some warnings and C++ error. +/// - 2016/11/10 (1.28.0) - Added additional `nk_button` versions which allows to directly +/// pass in a style struct to change buttons visual. +/// - 2016/11/10 (1.27.0) - Added additional `nk_tree` versions to support external state +/// storage. Just like last the `nk_group` commit the main +/// advantage is that you optionally can minimize nuklears runtime +/// memory consumption or handle hash collisions. +/// - 2016/11/09 (1.26.0) - Added additional `nk_group` version to support external scrollbar +/// offset storage. Main advantage is that you can externalize +/// the memory management for the offset. It could also be helpful +/// if you have a hash collision in `nk_group_begin` but really +/// want the name. In addition I added `nk_list_view` which allows +/// to draw big lists inside a group without actually having to +/// commit the whole list to nuklear (issue #269). +/// - 2016/10/30 (1.25.1) - Fixed clipping rectangle bug inside `nk_draw_list`. +/// - 2016/10/29 (1.25.0) - Pulled `nk_panel` memory management into nuklear and out of +/// the hands of the user. From now on users don't have to care +/// about panels unless they care about some information. If you +/// still need the panel just call `nk_window_get_panel`. +/// - 2016/10/21 (1.24.0) - Changed widget border drawing to stroked rectangle from filled +/// rectangle for less overdraw and widget background transparency. +/// - 2016/10/18 (1.23.0) - Added `nk_edit_focus` for manually edit widget focus control. +/// - 2016/09/29 (1.22.7) - Fixed deduction of basic type in non `` compilation. +/// - 2016/09/29 (1.22.6) - Fixed edit widget UTF-8 text cursor drawing bug. +/// - 2016/09/28 (1.22.5) - Fixed edit widget UTF-8 text appending/inserting/removing. +/// - 2016/09/28 (1.22.4) - Fixed drawing bug inside edit widgets which offset all text +/// text in every edit widget if one of them is scrolled. +/// - 2016/09/28 (1.22.3) - Fixed small bug in edit widgets if not active. The wrong +/// text length is passed. It should have been in bytes but +/// was passed as glyphs. +/// - 2016/09/20 (1.22.2) - Fixed color button size calculation. +/// - 2016/09/20 (1.22.1) - Fixed some `nk_vsnprintf` behavior bugs and removed `` +/// again from `NK_INCLUDE_STANDARD_VARARGS`. +/// - 2016/09/18 (1.22.0) - C89 does not support vsnprintf only C99 and newer as well +/// as C++11 and newer. In addition to use vsnprintf you have +/// to include . So just defining `NK_INCLUDE_STD_VAR_ARGS` +/// is not enough. That behavior is now fixed. By default if +/// both varargs as well as stdio is selected I try to use +/// vsnprintf if not possible I will revert to vsprintf. If +/// varargs but not stdio was defined I will use my own function. +/// - 2016/09/15 (1.21.2) - Fixed panel `close` behavior for deeper panel levels. +/// - 2016/09/15 (1.21.1) - Fixed C++ errors and wrong argument to `nk_panel_get_xxxx`. +/// - 2016/09/13 (1.21.0) - !BREAKING! Fixed nonblocking popup behavior in menu, combo, +/// and contextual which prevented closing in y-direction if +/// popup did not reach max height. +/// In addition the height parameter was changed into vec2 +/// for width and height to have more control over the popup size. +/// - 2016/09/13 (1.20.3) - Cleaned up and extended type selection. +/// - 2016/09/13 (1.20.2) - Fixed slider behavior hopefully for the last time. This time +/// all calculation are correct so no more hackery. +/// - 2016/09/13 (1.20.1) - Internal change to divide window/panel flags into panel flags and types. +/// Suprisinly spend years in C and still happened to confuse types +/// with flags. Probably something to take note. +/// - 2016/09/08 (1.20.0) - Added additional helper function to make it easier to just +/// take the produced buffers from `nk_convert` and unplug the +/// iteration process from `nk_context`. So now you can +/// just use the vertex,element and command buffer + two pointer +/// inside the command buffer retrieved by calls `nk__draw_begin` +/// and `nk__draw_end` and macro `nk_draw_foreach_bounded`. +/// - 2016/09/08 (1.19.0) - Added additional asserts to make sure every `nk_xxx_begin` call +/// for windows, popups, combobox, menu and contextual is guarded by +/// `if` condition and does not produce false drawing output. +/// - 2016/09/08 (1.18.0) - Changed confusing name for `NK_SYMBOL_RECT_FILLED`, `NK_SYMBOL_RECT` +/// to hopefully easier to understand `NK_SYMBOL_RECT_FILLED` and +/// `NK_SYMBOL_RECT_OUTLINE`. +/// - 2016/09/08 (1.17.0) - Changed confusing name for `NK_SYMBOL_CIRLCE_FILLED`, `NK_SYMBOL_CIRCLE` +/// to hopefully easier to understand `NK_SYMBOL_CIRCLE_FILLED` and +/// `NK_SYMBOL_CIRCLE_OUTLINE`. +/// - 2016/09/08 (1.16.0) - Added additional checks to select correct types if `NK_INCLUDE_FIXED_TYPES` +/// is not defined by supporting the biggest compiler GCC, clang and MSVC. +/// - 2016/09/07 (1.15.3) - Fixed `NK_INCLUDE_COMMAND_USERDATA` define to not cause an error. +/// - 2016/09/04 (1.15.2) - Fixed wrong combobox height calculation. +/// - 2016/09/03 (1.15.1) - Fixed gaps inside combo boxes in OpenGL. +/// - 2016/09/02 (1.15.0) - Changed nuklear to not have any default vertex layout and +/// instead made it user provided. The range of types to convert +/// to is quite limited at the moment, but I would be more than +/// happy to accept PRs to add additional. +/// - 2016/08/30 (1.14.2) - Removed unused variables. +/// - 2016/08/30 (1.14.1) - Fixed C++ build errors. +/// - 2016/08/30 (1.14.0) - Removed mouse dragging from SDL demo since it does not work correctly. +/// - 2016/08/30 (1.13.4) - Tweaked some default styling variables. +/// - 2016/08/30 (1.13.3) - Hopefully fixed drawing bug in slider, in general I would +/// refrain from using slider with a big number of steps. +/// - 2016/08/30 (1.13.2) - Fixed close and minimize button which would fire even if the +/// window was in Read Only Mode. +/// - 2016/08/30 (1.13.1) - Fixed popup panel padding handling which was previously just +/// a hack for combo box and menu. +/// - 2016/08/30 (1.13.0) - Removed `NK_WINDOW_DYNAMIC` flag from public API since +/// it is bugged and causes issues in window selection. +/// - 2016/08/30 (1.12.0) - Removed scaler size. The size of the scaler is now +/// determined by the scrollbar size. +/// - 2016/08/30 (1.11.2) - Fixed some drawing bugs caused by changes from 1.11.0. +/// - 2016/08/30 (1.11.1) - Fixed overlapping minimized window selection. +/// - 2016/08/30 (1.11.0) - Removed some internal complexity and overly complex code +/// handling panel padding and panel border. +/// - 2016/08/29 (1.10.0) - Added additional height parameter to `nk_combobox_xxx`. +/// - 2016/08/29 (1.10.0) - Fixed drawing bug in dynamic popups. +/// - 2016/08/29 (1.10.0) - Added experimental mouse scrolling to popups, menus and comboboxes. +/// - 2016/08/26 (1.10.0) - Added window name string prepresentation to account for +/// hash collisions. Currently limited to `NK_WINDOW_MAX_NAME` +/// which in term can be redefined if not big enough. +/// - 2016/08/26 (1.10.0) - Added stacks for temporary style/UI changes in code. +/// - 2016/08/25 (1.10.0) - Changed `nk_input_is_key_pressed` and 'nk_input_is_key_released' +/// to account for key press and release happening in one frame. +/// - 2016/08/25 (1.10.0) - Added additional nk_edit flag to directly jump to the end on activate. +/// - 2016/08/17 (1.09.6) - Removed invalid check for value zero in `nk_propertyx`. +/// - 2016/08/16 (1.09.5) - Fixed ROM mode for deeper levels of popup windows parents. +/// - 2016/08/15 (1.09.4) - Editbox are now still active if enter was pressed with flag +/// `NK_EDIT_SIG_ENTER`. Main reasoning is to be able to keep +/// typing after committing. +/// - 2016/08/15 (1.09.4) - Removed redundant code. +/// - 2016/08/15 (1.09.4) - Fixed negative numbers in `nk_strtoi` and remove unused variable. +/// - 2016/08/15 (1.09.3) - Fixed `NK_WINDOW_BACKGROUND` flag behavior to select a background +/// window only as selected by hovering and not by clicking. +/// - 2016/08/14 (1.09.2) - Fixed a bug in font atlas which caused wrong loading +/// of glyphs for font with multiple ranges. +/// - 2016/08/12 (1.09.1) - Added additional function to check if window is currently +/// hidden and therefore not visible. +/// - 2016/08/12 (1.09.1) - nk_window_is_closed now queries the correct flag `NK_WINDOW_CLOSED` +/// instead of the old flag `NK_WINDOW_HIDDEN`. +/// - 2016/08/09 (1.09.0) - Added additional double version to nk_property and changed +/// the underlying implementation to not cast to float and instead +/// work directly on the given values. +/// - 2016/08/09 (1.08.0) - Added additional define to overwrite library internal +/// floating pointer number to string conversion for additional +/// precision. +/// - 2016/08/09 (1.08.0) - Added additional define to overwrite library internal +/// string to floating point number conversion for additional +/// precision. +/// - 2016/08/08 (1.07.2) - Fixed compiling error without define `NK_INCLUDE_FIXED_TYPE`. +/// - 2016/08/08 (1.07.1) - Fixed possible floating point error inside `nk_widget` leading +/// to wrong wiget width calculation which results in widgets falsely +/// becoming tagged as not inside window and cannot be accessed. +/// - 2016/08/08 (1.07.0) - Nuklear now differentiates between hiding a window (NK_WINDOW_HIDDEN) and +/// closing a window (NK_WINDOW_CLOSED). A window can be hidden/shown +/// by using `nk_window_show` and closed by either clicking the close +/// icon in a window or by calling `nk_window_close`. Only closed +/// windows get removed at the end of the frame while hidden windows +/// remain. +/// - 2016/08/08 (1.06.0) - Added `nk_edit_string_zero_terminated` as a second option to +/// `nk_edit_string` which takes, edits and outputs a '\0' terminated string. +/// - 2016/08/08 (1.05.4) - Fixed scrollbar auto hiding behavior. +/// - 2016/08/08 (1.05.3) - Fixed wrong panel padding selection in `nk_layout_widget_space`. +/// - 2016/08/07 (1.05.2) - Fixed old bug in dynamic immediate mode layout API, calculating +/// wrong item spacing and panel width. +/// - 2016/08/07 (1.05.1) - Hopefully finally fixed combobox popup drawing bug. +/// - 2016/08/07 (1.05.0) - Split varargs away from `NK_INCLUDE_STANDARD_IO` into own +/// define `NK_INCLUDE_STANDARD_VARARGS` to allow more fine +/// grained controlled over library includes. +/// - 2016/08/06 (1.04.5) - Changed memset calls to `NK_MEMSET`. +/// - 2016/08/04 (1.04.4) - Fixed fast window scaling behavior. +/// - 2016/08/04 (1.04.3) - Fixed window scaling, movement bug which appears if you +/// move/scale a window and another window is behind it. +/// If you are fast enough then the window behind gets activated +/// and the operation is blocked. I now require activating +/// by hovering only if mouse is not pressed. +/// - 2016/08/04 (1.04.2) - Fixed changing fonts. +/// - 2016/08/03 (1.04.1) - Fixed `NK_WINDOW_BACKGROUND` behavior. +/// - 2016/08/03 (1.04.0) - Added color parameter to `nk_draw_image`. +/// - 2016/08/03 (1.04.0) - Added additional window padding style attributes for +/// sub windows (combo, menu, ...). +/// - 2016/08/03 (1.04.0) - Added functions to show/hide software cursor. +/// - 2016/08/03 (1.04.0) - Added `NK_WINDOW_BACKGROUND` flag to force a window +/// to be always in the background of the screen. +/// - 2016/08/03 (1.03.2) - Removed invalid assert macro for NK_RGB color picker. +/// - 2016/08/01 (1.03.1) - Added helper macros into header include guard. +/// - 2016/07/29 (1.03.0) - Moved the window/table pool into the header part to +/// simplify memory management by removing the need to +/// allocate the pool. +/// - 2016/07/29 (1.02.0) - Added auto scrollbar hiding window flag which if enabled +/// will hide the window scrollbar after NK_SCROLLBAR_HIDING_TIMEOUT +/// seconds without window interaction. To make it work +/// you have to also set a delta time inside the `nk_context`. +/// - 2016/07/25 (1.01.1) - Fixed small panel and panel border drawing bugs. +/// - 2016/07/15 (1.01.0) - Added software cursor to `nk_style` and `nk_context`. +/// - 2016/07/15 (1.01.0) - Added const correctness to `nk_buffer_push' data argument. +/// - 2016/07/15 (1.01.0) - Removed internal font baking API and simplified +/// font atlas memory management by converting pointer +/// arrays for fonts and font configurations to lists. +/// - 2016/07/15 (1.00.0) - Changed button API to use context dependent button +/// behavior instead of passing it for every function call. +/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// ## Gallery +/// ![Figure [blue]: Feature overview with blue color styling](https://cloud.githubusercontent.com/assets/8057201/13538240/acd96876-e249-11e5-9547-5ac0b19667a0.png) +/// ![Figure [red]: Feature overview with red color styling](https://cloud.githubusercontent.com/assets/8057201/13538243/b04acd4c-e249-11e5-8fd2-ad7744a5b446.png) +/// ![Figure [widgets]: Widget overview](https://cloud.githubusercontent.com/assets/8057201/11282359/3325e3c6-8eff-11e5-86cb-cf02b0596087.png) +/// ![Figure [blackwhite]: Black and white](https://cloud.githubusercontent.com/assets/8057201/11033668/59ab5d04-86e5-11e5-8091-c56f16411565.png) +/// ![Figure [filexp]: File explorer](https://cloud.githubusercontent.com/assets/8057201/10718115/02a9ba08-7b6b-11e5-950f-adacdd637739.png) +/// ![Figure [opengl]: OpenGL Editor](https://cloud.githubusercontent.com/assets/8057201/12779619/2a20d72c-ca69-11e5-95fe-4edecf820d5c.png) +/// ![Figure [nodedit]: Node Editor](https://cloud.githubusercontent.com/assets/8057201/9976995/e81ac04a-5ef7-11e5-872b-acd54fbeee03.gif) +/// ![Figure [skinning]: Using skinning in Nuklear](https://cloud.githubusercontent.com/assets/8057201/15991632/76494854-30b8-11e6-9555-a69840d0d50b.png) +/// ![Figure [bf]: Heavy modified version](https://cloud.githubusercontent.com/assets/8057201/14902576/339926a8-0d9c-11e6-9fee-a8b73af04473.png) +/// +/// ## Credits +/// Developed by Micha Mettke and every direct or indirect github contributor.

+/// +/// Embeds [stb_texedit](https://github.com/nothings/stb/blob/master/stb_textedit.h), [stb_truetype](https://github.com/nothings/stb/blob/master/stb_truetype.h) and [stb_rectpack](https://github.com/nothings/stb/blob/master/stb_rect_pack.h) by Sean Barret (public domain)
+/// Uses [stddoc.c](https://github.com/r-lyeh/stddoc.c) from r-lyeh@github.com for documentation generation

+/// Embeds ProggyClean.ttf font by Tristan Grimmer (MIT license).
+/// +/// Big thank you to Omar Cornut (ocornut@github) for his [imgui library](https://github.com/ocornut/imgui) and +/// giving me the inspiration for this library, Casey Muratori for handmade hero +/// and his original immediate mode graphical user interface idea and Sean +/// Barret for his amazing single header libraries which restored my faith +/// in libraries and brought me to create some of my own. Finally Apoorva Joshi +/// for his single header file packer. +*/ + diff --git a/nuklear/nuklear_xlib_gl3.h b/nuklear/nuklear_xlib_gl3.h new file mode 100644 index 0000000..f2cdbba --- /dev/null +++ b/nuklear/nuklear_xlib_gl3.h @@ -0,0 +1,756 @@ +/* + * Nuklear - v1.17 - public domain + * no warrenty implied; use at your own risk. + * authored from 2015-2016 by Micha Mettke + */ +/* + * ============================================================== + * + * API + * + * =============================================================== + */ +#ifndef NK_XLIB_GL3_H_ +#define NK_XLIB_GL3_H_ + +#include +NK_API struct nk_context* nk_x11_init(Display *dpy, Window win); +NK_API void nk_x11_font_stash_begin(struct nk_font_atlas **atlas); +NK_API void nk_x11_font_stash_end(void); +NK_API int nk_x11_handle_event(XEvent *evt); +NK_API void nk_x11_render(enum nk_anti_aliasing, int max_vertex_buffer, int max_element_buffer); +NK_API void nk_x11_shutdown(void); +NK_API int nk_x11_device_create(void); +NK_API void nk_x11_device_destroy(void); + +#endif +/* + * ============================================================== + * + * IMPLEMENTATION + * + * =============================================================== + */ +#ifdef NK_XLIB_GL3_IMPLEMENTATION +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + +#ifndef NK_X11_DOUBLE_CLICK_LO +#define NK_X11_DOUBLE_CLICK_LO 20 +#endif +#ifndef NK_X11_DOUBLE_CLICK_HI +#define NK_X11_DOUBLE_CLICK_HI 200 +#endif + +#ifdef NK_XLIB_LOAD_OPENGL_EXTENSIONS +#include + +/* GL_ARB_vertex_buffer_object */ +typedef void(*nkglGenBuffers)(GLsizei, GLuint*); +typedef void(*nkglBindBuffer)(GLenum, GLuint); +typedef void(*nkglBufferData)(GLenum, GLsizeiptr, const GLvoid*, GLenum); +typedef void(*nkglBufferSubData)(GLenum, GLintptr, GLsizeiptr, const GLvoid*); +typedef void*(*nkglMapBuffer)(GLenum, GLenum); +typedef GLboolean(*nkglUnmapBuffer)(GLenum); +typedef void(*nkglDeleteBuffers)(GLsizei, GLuint*); +/* GL_ARB_vertex_array_object */ +typedef void (*nkglGenVertexArrays)(GLsizei, GLuint*); +typedef void (*nkglBindVertexArray)(GLuint); +typedef void (*nkglDeleteVertexArrays)(GLsizei, const GLuint*); +/* GL_ARB_vertex_program / GL_ARB_fragment_program */ +typedef void(*nkglVertexAttribPointer)(GLuint, GLint, GLenum, GLboolean, GLsizei, const GLvoid*); +typedef void(*nkglEnableVertexAttribArray)(GLuint); +typedef void(*nkglDisableVertexAttribArray)(GLuint); +/* GL_ARB_framebuffer_object */ +typedef void(*nkglGenerateMipmap)(GLenum target); +/* GLSL/OpenGL 2.0 core */ +typedef GLuint(*nkglCreateShader)(GLenum); +typedef void(*nkglShaderSource)(GLuint, GLsizei, const GLchar**, const GLint*); +typedef void(*nkglCompileShader)(GLuint); +typedef void(*nkglGetShaderiv)(GLuint, GLenum, GLint*); +typedef void(*nkglGetShaderInfoLog)(GLuint, GLsizei, GLsizei*, GLchar*); +typedef void(*nkglDeleteShader)(GLuint); +typedef GLuint(*nkglCreateProgram)(void); +typedef void(*nkglAttachShader)(GLuint, GLuint); +typedef void(*nkglDetachShader)(GLuint, GLuint); +typedef void(*nkglLinkProgram)(GLuint); +typedef void(*nkglUseProgram)(GLuint); +typedef void(*nkglGetProgramiv)(GLuint, GLenum, GLint*); +typedef void(*nkglGetProgramInfoLog)(GLuint, GLsizei, GLsizei*, GLchar*); +typedef void(*nkglDeleteProgram)(GLuint); +typedef GLint(*nkglGetUniformLocation)(GLuint, const GLchar*); +typedef GLint(*nkglGetAttribLocation)(GLuint, const GLchar*); +typedef void(*nkglUniform1i)(GLint, GLint); +typedef void(*nkglUniform1f)(GLint, GLfloat); +typedef void(*nkglUniformMatrix3fv)(GLint, GLsizei, GLboolean, const GLfloat*); +typedef void(*nkglUniformMatrix4fv)(GLint, GLsizei, GLboolean, const GLfloat*); + +static nkglGenBuffers glGenBuffers; +static nkglBindBuffer glBindBuffer; +static nkglBufferData glBufferData; +static nkglBufferSubData glBufferSubData; +static nkglMapBuffer glMapBuffer; +static nkglUnmapBuffer glUnmapBuffer; +static nkglDeleteBuffers glDeleteBuffers; +static nkglGenVertexArrays glGenVertexArrays; +static nkglBindVertexArray glBindVertexArray; +static nkglDeleteVertexArrays glDeleteVertexArrays; +static nkglVertexAttribPointer glVertexAttribPointer; +static nkglEnableVertexAttribArray glEnableVertexAttribArray; +static nkglDisableVertexAttribArray glDisableVertexAttribArray; +static nkglGenerateMipmap glGenerateMipmap; +static nkglCreateShader glCreateShader; +static nkglShaderSource glShaderSource; +static nkglCompileShader glCompileShader; +static nkglGetShaderiv glGetShaderiv; +static nkglGetShaderInfoLog glGetShaderInfoLog; +static nkglDeleteShader glDeleteShader; +static nkglCreateProgram glCreateProgram; +static nkglAttachShader glAttachShader; +static nkglDetachShader glDetachShader; +static nkglLinkProgram glLinkProgram; +static nkglUseProgram glUseProgram; +static nkglGetProgramiv glGetProgramiv; +static nkglGetProgramInfoLog glGetProgramInfoLog; +static nkglDeleteProgram glDeleteProgram; +static nkglGetUniformLocation glGetUniformLocation; +static nkglGetAttribLocation glGetAttribLocation; +static nkglUniform1i glUniform1i; +static nkglUniform1f glUniform1f; +static nkglUniformMatrix3fv glUniformMatrix3fv; +static nkglUniformMatrix4fv glUniformMatrix4fv; + +enum graphics_card_vendors { + VENDOR_UNKNOWN, + VENDOR_NVIDIA, + VENDOR_AMD, + VENDOR_INTEL +}; + +struct opengl_info { + /* info */ + const char *vendor_str; + const char *version_str; + const char *extensions_str; + const char *renderer_str; + const char *glsl_version_str; + enum graphics_card_vendors vendor; + /* version */ + float version; + int major_version; + int minor_version; + /* extensions */ + int glsl_available; + int vertex_buffer_obj_available; + int vertex_array_obj_available; + int map_buffer_range_available; + int fragment_program_available; + int frame_buffer_object_available; +}; +#endif + +struct nk_x11_vertex { + float position[2]; + float uv[2]; + nk_byte col[4]; +}; + +struct nk_x11_device { +#ifdef NK_XLIB_LOAD_OPENGL_EXTENSIONS + struct opengl_info info; +#endif + struct nk_buffer cmds; + struct nk_draw_null_texture tex_null; + GLuint vbo, vao, ebo; + GLuint prog; + GLuint vert_shdr; + GLuint frag_shdr; + GLint attrib_pos; + GLint attrib_uv; + GLint attrib_col; + GLint uniform_tex; + GLint uniform_proj; + GLuint font_tex; +}; + +static struct nk_x11 { + struct nk_x11_device ogl; + struct nk_context ctx; + struct nk_font_atlas atlas; + Cursor cursor; + Display *dpy; + Window win; + long last_button_click; +} x11; + +#ifdef __APPLE__ + #define NK_SHADER_VERSION "#version 150\n" +#else + #define NK_SHADER_VERSION "#version 300 es\n" +#endif + +#ifdef NK_XLIB_LOAD_OPENGL_EXTENSIONS +#include + +NK_INTERN long +nk_timestamp(void) +{ + struct timeval tv; + if (gettimeofday(&tv, NULL) < 0) return 0; + return (long)((long)tv.tv_sec * 1000 + (long)tv.tv_usec/1000); +} + +NK_INTERN int +nk_x11_stricmpn(const char *a, const char *b, int len) +{ + int i = 0; + for (i = 0; i < len && a[i] && b[i]; ++i) + if (a[i] != b[i]) return 1; + if (i != len) return 1; + return 0; +} + +NK_INTERN int +nk_x11_check_extension(struct opengl_info *GL, const char *ext) +{ + const char *start, *where, *term; + where = strchr(ext, ' '); + if (where || *ext == '\0') + return nk_false; + + for (start = GL->extensions_str;;) { + where = strstr((const char*)start, ext); + if (!where) break; + term = where + strlen(ext); + if (where == start || *(where - 1) == ' ') { + if (*term == ' ' || *term == '\0') + return nk_true; + } + start = term; + } + return nk_false; +} + +#define GL_EXT(name) (nk##name)nk_gl_ext(#name) +NK_INTERN __GLXextFuncPtr +nk_gl_ext(const char *name) +{ + __GLXextFuncPtr func; + func = glXGetProcAddress((const GLubyte*)name); + if (!func) { + fprintf(stdout, "[GL]: failed to load extension: %s", name); + return NULL; + } + return func; +} + +NK_INTERN int +nk_load_opengl(struct opengl_info *gl) +{ + int failed = nk_false; + gl->version_str = (const char*)glGetString(GL_VERSION); + glGetIntegerv(GL_MAJOR_VERSION, &gl->major_version); + glGetIntegerv(GL_MINOR_VERSION, &gl->minor_version); + if (gl->major_version < 2) { + fprintf(stderr, "[GL]: Graphics card does not fulfill minimum OpenGL 2.0 support\n"); + return 0; + } + gl->version = (float)gl->major_version + (float)gl->minor_version * 0.1f; + gl->renderer_str = (const char*)glGetString(GL_RENDERER); + gl->extensions_str = (const char*)glGetString(GL_EXTENSIONS); + gl->glsl_version_str = (const char*)glGetString(GL_SHADING_LANGUAGE_VERSION); + gl->vendor_str = (const char*)glGetString(GL_VENDOR); + if (!nk_x11_stricmpn(gl->vendor_str, "ATI", 4) || + !nk_x11_stricmpn(gl->vendor_str, "AMD", 4)) + gl->vendor = VENDOR_AMD; + else if (!nk_x11_stricmpn(gl->vendor_str, "NVIDIA", 6)) + gl->vendor = VENDOR_NVIDIA; + else if (!nk_x11_stricmpn(gl->vendor_str, "Intel", 5)) + gl->vendor = VENDOR_INTEL; + else gl->vendor = VENDOR_UNKNOWN; + + /* Extensions */ + gl->glsl_available = (gl->version >= 2.0f); + if (gl->glsl_available) { + /* GLSL core in OpenGL > 2 */ + glCreateShader = GL_EXT(glCreateShader); + glShaderSource = GL_EXT(glShaderSource); + glCompileShader = GL_EXT(glCompileShader); + glGetShaderiv = GL_EXT(glGetShaderiv); + glGetShaderInfoLog = GL_EXT(glGetShaderInfoLog); + glDeleteShader = GL_EXT(glDeleteShader); + glCreateProgram = GL_EXT(glCreateProgram); + glAttachShader = GL_EXT(glAttachShader); + glDetachShader = GL_EXT(glDetachShader); + glLinkProgram = GL_EXT(glLinkProgram); + glUseProgram = GL_EXT(glUseProgram); + glGetProgramiv = GL_EXT(glGetProgramiv); + glGetProgramInfoLog = GL_EXT(glGetProgramInfoLog); + glDeleteProgram = GL_EXT(glDeleteProgram); + glGetUniformLocation = GL_EXT(glGetUniformLocation); + glGetAttribLocation = GL_EXT(glGetAttribLocation); + glUniform1i = GL_EXT(glUniform1i); + glUniform1f = GL_EXT(glUniform1f); + glUniformMatrix3fv = GL_EXT(glUniformMatrix3fv); + glUniformMatrix4fv = GL_EXT(glUniformMatrix4fv); + } + gl->vertex_buffer_obj_available = nk_x11_check_extension(gl, "GL_ARB_vertex_buffer_object"); + if (gl->vertex_buffer_obj_available) { + /* GL_ARB_vertex_buffer_object */ + glGenBuffers = GL_EXT(glGenBuffers); + glBindBuffer = GL_EXT(glBindBuffer); + glBufferData = GL_EXT(glBufferData); + glBufferSubData = GL_EXT(glBufferSubData); + glMapBuffer = GL_EXT(glMapBuffer); + glUnmapBuffer = GL_EXT(glUnmapBuffer); + glDeleteBuffers = GL_EXT(glDeleteBuffers); + } + gl->fragment_program_available = nk_x11_check_extension(gl, "GL_ARB_fragment_program"); + if (gl->fragment_program_available) { + /* GL_ARB_vertex_program / GL_ARB_fragment_program */ + glVertexAttribPointer = GL_EXT(glVertexAttribPointer); + glEnableVertexAttribArray = GL_EXT(glEnableVertexAttribArray); + glDisableVertexAttribArray = GL_EXT(glDisableVertexAttribArray); + } + gl->vertex_array_obj_available = nk_x11_check_extension(gl, "GL_ARB_vertex_array_object"); + if (gl->vertex_array_obj_available) { + /* GL_ARB_vertex_array_object */ + glGenVertexArrays = GL_EXT(glGenVertexArrays); + glBindVertexArray = GL_EXT(glBindVertexArray); + glDeleteVertexArrays = GL_EXT(glDeleteVertexArrays); + } + gl->frame_buffer_object_available = nk_x11_check_extension(gl, "GL_ARB_framebuffer_object"); + if (gl->frame_buffer_object_available) { + /* GL_ARB_framebuffer_object */ + glGenerateMipmap = GL_EXT(glGenerateMipmap); + } + if (!gl->vertex_buffer_obj_available) { + fprintf(stdout, "[GL] Error: GL_ARB_vertex_buffer_object is not available!\n"); + failed = nk_true; + } + if (!gl->fragment_program_available) { + fprintf(stdout, "[GL] Error: GL_ARB_fragment_program is not available!\n"); + failed = nk_true; + } + if (!gl->vertex_array_obj_available) { + fprintf(stdout, "[GL] Error: GL_ARB_vertex_array_object is not available!\n"); + failed = nk_true; + } + if (!gl->frame_buffer_object_available) { + fprintf(stdout, "[GL] Error: GL_ARB_framebuffer_object is not available!\n"); + failed = nk_true; + } + return !failed; +} +#endif + +NK_API int +nk_x11_device_create(void) +{ + GLint status; + static const GLchar *vertex_shader = + NK_SHADER_VERSION + "uniform mat4 ProjMtx;\n" + "in vec2 Position;\n" + "in vec2 TexCoord;\n" + "in vec4 Color;\n" + "out vec2 Frag_UV;\n" + "out vec4 Frag_Color;\n" + "void main() {\n" + " Frag_UV = TexCoord;\n" + " Frag_Color = Color;\n" + " gl_Position = ProjMtx * vec4(Position.xy, 0, 1);\n" + "}\n"; + static const GLchar *fragment_shader = + NK_SHADER_VERSION + "precision mediump float;\n" + "uniform sampler2D Texture;\n" + "in vec2 Frag_UV;\n" + "in vec4 Frag_Color;\n" + "out vec4 Out_Color;\n" + "void main(){\n" + " Out_Color = Frag_Color * texture(Texture, Frag_UV.st);\n" + "}\n"; + + struct nk_x11_device *dev = &x11.ogl; +#ifdef NK_XLIB_LOAD_OPENGL_EXTENSIONS + if (!nk_load_opengl(&dev->info)) return 0; +#endif + nk_buffer_init_default(&dev->cmds); + + dev->prog = glCreateProgram(); + dev->vert_shdr = glCreateShader(GL_VERTEX_SHADER); + dev->frag_shdr = glCreateShader(GL_FRAGMENT_SHADER); + glShaderSource(dev->vert_shdr, 1, &vertex_shader, 0); + glShaderSource(dev->frag_shdr, 1, &fragment_shader, 0); + glCompileShader(dev->vert_shdr); + glCompileShader(dev->frag_shdr); + glGetShaderiv(dev->vert_shdr, GL_COMPILE_STATUS, &status); + assert(status == GL_TRUE); + glGetShaderiv(dev->frag_shdr, GL_COMPILE_STATUS, &status); + assert(status == GL_TRUE); + glAttachShader(dev->prog, dev->vert_shdr); + glAttachShader(dev->prog, dev->frag_shdr); + glLinkProgram(dev->prog); + glGetProgramiv(dev->prog, GL_LINK_STATUS, &status); + assert(status == GL_TRUE); + + dev->uniform_tex = glGetUniformLocation(dev->prog, "Texture"); + dev->uniform_proj = glGetUniformLocation(dev->prog, "ProjMtx"); + dev->attrib_pos = glGetAttribLocation(dev->prog, "Position"); + dev->attrib_uv = glGetAttribLocation(dev->prog, "TexCoord"); + dev->attrib_col = glGetAttribLocation(dev->prog, "Color"); + + { + /* buffer setup */ + GLsizei vs = sizeof(struct nk_x11_vertex); + size_t vp = offsetof(struct nk_x11_vertex, position); + size_t vt = offsetof(struct nk_x11_vertex, uv); + size_t vc = offsetof(struct nk_x11_vertex, col); + + glGenBuffers(1, &dev->vbo); + glGenBuffers(1, &dev->ebo); + glGenVertexArrays(1, &dev->vao); + + glBindVertexArray(dev->vao); + glBindBuffer(GL_ARRAY_BUFFER, dev->vbo); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, dev->ebo); + + glEnableVertexAttribArray((GLuint)dev->attrib_pos); + glEnableVertexAttribArray((GLuint)dev->attrib_uv); + glEnableVertexAttribArray((GLuint)dev->attrib_col); + + glVertexAttribPointer((GLuint)dev->attrib_pos, 2, GL_FLOAT, GL_FALSE, vs, (void*)vp); + glVertexAttribPointer((GLuint)dev->attrib_uv, 2, GL_FLOAT, GL_FALSE, vs, (void*)vt); + glVertexAttribPointer((GLuint)dev->attrib_col, 4, GL_UNSIGNED_BYTE, GL_TRUE, vs, (void*)vc); + } + + glBindTexture(GL_TEXTURE_2D, 0); + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + glBindVertexArray(0); + return 1; +} + +NK_INTERN void +nk_x11_device_upload_atlas(const void *image, int width, int height) +{ + struct nk_x11_device *dev = &x11.ogl; + glGenTextures(1, &dev->font_tex); + glBindTexture(GL_TEXTURE_2D, dev->font_tex); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei)width, (GLsizei)height, 0, + GL_RGBA, GL_UNSIGNED_BYTE, image); +} + +NK_API void +nk_x11_device_destroy(void) +{ + struct nk_x11_device *dev = &x11.ogl; + glDetachShader(dev->prog, dev->vert_shdr); + glDetachShader(dev->prog, dev->frag_shdr); + glDeleteShader(dev->vert_shdr); + glDeleteShader(dev->frag_shdr); + glDeleteProgram(dev->prog); + glDeleteTextures(1, &dev->font_tex); + glDeleteBuffers(1, &dev->vbo); + glDeleteBuffers(1, &dev->ebo); + nk_buffer_free(&dev->cmds); +} + +NK_API void +nk_x11_render(enum nk_anti_aliasing AA, int max_vertex_buffer, int max_element_buffer) +{ + int width, height; + XWindowAttributes attr; + struct nk_x11_device *dev = &x11.ogl; + GLfloat ortho[4][4] = { + {2.0f, 0.0f, 0.0f, 0.0f}, + {0.0f,-2.0f, 0.0f, 0.0f}, + {0.0f, 0.0f,-1.0f, 0.0f}, + {-1.0f,1.0f, 0.0f, 1.0f}, + }; + XGetWindowAttributes(x11.dpy, x11.win, &attr); + width = attr.width; + height = attr.height; + + ortho[0][0] /= (GLfloat)width; + ortho[1][1] /= (GLfloat)height; + + /* setup global state */ + glEnable(GL_BLEND); + glBlendEquation(GL_FUNC_ADD); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glDisable(GL_CULL_FACE); + glDisable(GL_DEPTH_TEST); + glEnable(GL_SCISSOR_TEST); + glActiveTexture(GL_TEXTURE0); + + /* setup program */ + glUseProgram(dev->prog); + glUniform1i(dev->uniform_tex, 0); + glUniformMatrix4fv(dev->uniform_proj, 1, GL_FALSE, &ortho[0][0]); + glViewport(0,0,(GLsizei)width,(GLsizei)height); + { + /* convert from command queue into draw list and draw to screen */ + const struct nk_draw_command *cmd; + void *vertices, *elements; + const nk_draw_index *offset = NULL; + struct nk_buffer vbuf, ebuf; + + /* allocate vertex and element buffer */ + glBindVertexArray(dev->vao); + glBindBuffer(GL_ARRAY_BUFFER, dev->vbo); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, dev->ebo); + + glBufferData(GL_ARRAY_BUFFER, max_vertex_buffer, NULL, GL_STREAM_DRAW); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, max_element_buffer, NULL, GL_STREAM_DRAW); + + /* load draw vertices & elements directly into vertex + element buffer */ + vertices = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY); + elements = glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY); + { + /* fill convert configuration */ + struct nk_convert_config config; + static const struct nk_draw_vertex_layout_element vertex_layout[] = { + {NK_VERTEX_POSITION, NK_FORMAT_FLOAT, NK_OFFSETOF(struct nk_x11_vertex, position)}, + {NK_VERTEX_TEXCOORD, NK_FORMAT_FLOAT, NK_OFFSETOF(struct nk_x11_vertex, uv)}, + {NK_VERTEX_COLOR, NK_FORMAT_R8G8B8A8, NK_OFFSETOF(struct nk_x11_vertex, col)}, + {NK_VERTEX_LAYOUT_END} + }; + memset(&config, 0, sizeof(config)); + config.vertex_layout = vertex_layout; + config.vertex_size = sizeof(struct nk_x11_vertex); + config.vertex_alignment = NK_ALIGNOF(struct nk_x11_vertex); + config.tex_null = dev->tex_null; + config.circle_segment_count = 22; + config.curve_segment_count = 22; + config.arc_segment_count = 22; + config.global_alpha = 1.0f; + config.shape_AA = AA; + config.line_AA = AA; + + /* setup buffers to load vertices and elements */ + nk_buffer_init_fixed(&vbuf, vertices, (size_t)max_vertex_buffer); + nk_buffer_init_fixed(&ebuf, elements, (size_t)max_element_buffer); + nk_convert(&x11.ctx, &dev->cmds, &vbuf, &ebuf, &config); + } + glUnmapBuffer(GL_ARRAY_BUFFER); + glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER); + + /* iterate over and execute each draw command */ + nk_draw_foreach(cmd, &x11.ctx, &dev->cmds) + { + if (!cmd->elem_count) continue; +// GLint unit = cmd->texture.id + glBindTexture(GL_TEXTURE_2D, (GLuint)cmd->texture.id); + glScissor( + (GLint)(cmd->clip_rect.x), + (GLint)((height - (GLint)(cmd->clip_rect.y + cmd->clip_rect.h))), + (GLint)(cmd->clip_rect.w), + (GLint)(cmd->clip_rect.h)); + glDrawElements(GL_TRIANGLES, (GLsizei)cmd->elem_count, GL_UNSIGNED_SHORT, offset); + offset += cmd->elem_count; + } + nk_clear(&x11.ctx); + nk_buffer_clear(&dev->cmds); + } + + /* default OpenGL state */ + glUseProgram(0); + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + glBindVertexArray(0); + glDisable(GL_BLEND); + glDisable(GL_SCISSOR_TEST); +} + +NK_API void +nk_x11_font_stash_begin(struct nk_font_atlas **atlas) +{ + nk_font_atlas_init_default(&x11.atlas); + nk_font_atlas_begin(&x11.atlas); + *atlas = &x11.atlas; +} + +NK_API void +nk_x11_font_stash_end(void) +{ + const void *image; int w, h; + image = nk_font_atlas_bake(&x11.atlas, &w, &h, NK_FONT_ATLAS_RGBA32); + nk_x11_device_upload_atlas(image, w, h); + nk_font_atlas_end(&x11.atlas, nk_handle_id((int)x11.ogl.font_tex), &x11.ogl.tex_null); + if (x11.atlas.default_font) + nk_style_set_font(&x11.ctx, &x11.atlas.default_font->handle); +} + +NK_API int +nk_x11_handle_event(XEvent *evt) +{ + struct nk_context *ctx = &x11.ctx; + + /* optional grabbing behavior */ + if (ctx->input.mouse.grab) { + XDefineCursor(x11.dpy, x11.win, x11.cursor); + ctx->input.mouse.grab = 0; + } else if (ctx->input.mouse.ungrab) { + XWarpPointer(x11.dpy, None, x11.win, 0, 0, 0, 0, + (int)ctx->input.mouse.pos.x, (int)ctx->input.mouse.pos.y); + XUndefineCursor(x11.dpy, x11.win); + ctx->input.mouse.ungrab = 0; + } + + if (evt->type == KeyPress || evt->type == KeyRelease) + { + /* Key handler */ + int ret, down = (evt->type == KeyPress); + KeySym *code = XGetKeyboardMapping(x11.dpy, (KeyCode)evt->xkey.keycode, 1, &ret); + if (*code == XK_Shift_L || *code == XK_Shift_R) nk_input_key(ctx, NK_KEY_SHIFT, down); + else if (*code == XK_Control_L || *code == XK_Control_R) nk_input_key(ctx, NK_KEY_CTRL, down); + else if (*code == XK_Alt_L || *code == XK_Alt_R) nk_input_key(ctx, NK_KEY_ALT, down); + else if (*code == XK_Delete) nk_input_key(ctx, NK_KEY_DEL, down); + else if (*code == XK_Return) nk_input_key(ctx, NK_KEY_ENTER, down); + else if (*code == XK_Tab) nk_input_key(ctx, NK_KEY_TAB, down); + else if (*code == XK_Left) nk_input_key(ctx, NK_KEY_LEFT, down); + else if (*code == XK_Right) nk_input_key(ctx, NK_KEY_RIGHT, down); + else if (*code == XK_Up) nk_input_key(ctx, NK_KEY_UP, down); + else if (*code == XK_Down) nk_input_key(ctx, NK_KEY_DOWN, down); + else if (*code == XK_BackSpace) nk_input_key(ctx, NK_KEY_BACKSPACE, down); + else if (*code == XK_Escape) nk_input_key(ctx, NK_KEY_ESCAPE, down); + // else if (*code == XK_space && !down) nk_input_char(ctx, ' '); + else if (*code == XK_Page_Up) nk_input_key(ctx, NK_KEY_SCROLL_UP, down); + else if (*code == XK_Page_Down) nk_input_key(ctx, NK_KEY_SCROLL_DOWN, down); + else if (*code == XK_Home) { + nk_input_key(ctx, NK_KEY_TEXT_START, down); + nk_input_key(ctx, NK_KEY_SCROLL_START, down); + } else if (*code == XK_End) { + nk_input_key(ctx, NK_KEY_TEXT_END, down); + nk_input_key(ctx, NK_KEY_SCROLL_END, down); + } else { + if (*code == 'c' && (evt->xkey.state & ControlMask)) + nk_input_key(ctx, NK_KEY_COPY, down); + else if (*code == 'v' && (evt->xkey.state & ControlMask)) + nk_input_key(ctx, NK_KEY_PASTE, down); + else if (*code == 'x' && (evt->xkey.state & ControlMask)) + nk_input_key(ctx, NK_KEY_CUT, down); + else if (*code == 'z' && (evt->xkey.state & ControlMask)) + nk_input_key(ctx, NK_KEY_TEXT_UNDO, down); + else if (*code == 'r' && (evt->xkey.state & ControlMask)) + nk_input_key(ctx, NK_KEY_TEXT_REDO, down); + else if (*code == XK_Left && (evt->xkey.state & ControlMask)) + nk_input_key(ctx, NK_KEY_TEXT_WORD_LEFT, down); + else if (*code == XK_Right && (evt->xkey.state & ControlMask)) + nk_input_key(ctx, NK_KEY_TEXT_WORD_RIGHT, down); + else if (*code == 'b' && (evt->xkey.state & ControlMask)) + nk_input_key(ctx, NK_KEY_TEXT_LINE_START, down); + else if (*code == 'e' && (evt->xkey.state & ControlMask)) + nk_input_key(ctx, NK_KEY_TEXT_LINE_END, down); + else { + if (*code == 'i') + nk_input_key(ctx, NK_KEY_TEXT_INSERT_MODE, down); + else if (*code == 'r') + nk_input_key(ctx, NK_KEY_TEXT_REPLACE_MODE, down); + + char buf[32]; + KeySym keysym = 0; + if (XLookupString((XKeyEvent*)evt, buf, 32, &keysym, NULL) != NoSymbol) { + if (down) + nk_input_glyph(ctx, buf); + } else { +// printf("Unknown key %lx, pass on RAW %d\n", *code, +// ctx->input.keyboard.text_len); + uint32_t *d = (uint32_t *) ctx->input.keyboard.text; + d[ctx->input.keyboard.text_len / 4] = + (*code << 16) | !!down; + ctx->input.keyboard.text_len += 4; + } + } + } + XFree(code); + return 1; + } else if (evt->type == ButtonPress || evt->type == ButtonRelease) { + /* Button handler */ + int down = (evt->type == ButtonPress); + const int x = evt->xbutton.x, y = evt->xbutton.y; + if (evt->xbutton.button == Button1) { + if (down) { /* Double-Click Button handler */ + long dt = nk_timestamp() - x11.last_button_click; + if (dt > NK_X11_DOUBLE_CLICK_LO && dt < NK_X11_DOUBLE_CLICK_HI) + nk_input_button(ctx, NK_BUTTON_DOUBLE, x, y, nk_true); + x11.last_button_click = nk_timestamp(); + } else nk_input_button(ctx, NK_BUTTON_DOUBLE, x, y, nk_false); + nk_input_button(ctx, NK_BUTTON_LEFT, x, y, down); + } else if (evt->xbutton.button == Button2) + nk_input_button(ctx, NK_BUTTON_MIDDLE, x, y, down); + else if (evt->xbutton.button == Button3) + nk_input_button(ctx, NK_BUTTON_RIGHT, x, y, down); + else if (evt->xbutton.button == Button4) + nk_input_scroll(ctx, nk_vec2(0,1.0f)); + else if (evt->xbutton.button == Button5) + nk_input_scroll(ctx, nk_vec2(0,-1.0f)); + else return 0; + return 1; + } else if (evt->type == MotionNotify) { + /* Mouse motion handler */ + const int x = evt->xmotion.x, y = evt->xmotion.y; + nk_input_motion(ctx, x, y); + if (ctx->input.mouse.grabbed) { + ctx->input.mouse.pos.x = ctx->input.mouse.prev.x; + ctx->input.mouse.pos.y = ctx->input.mouse.prev.y; + XWarpPointer(x11.dpy, None, x11.win, 0, 0, 0, 0, (int)ctx->input.mouse.pos.x, (int)ctx->input.mouse.pos.y); + } + return 1; + } else if (evt->type == KeymapNotify) { + XRefreshKeyboardMapping(&evt->xmapping); + return 1; + } + return 0; +} + +NK_API struct nk_context* +nk_x11_init(Display *dpy, Window win) +{ + if (!setlocale(LC_ALL,"")) return 0; + if (!XSupportsLocale()) return 0; + if (!XSetLocaleModifiers("@im=none")) return 0; + if (!nk_x11_device_create()) return 0; + + x11.dpy = dpy; + x11.win = win; + + /* create invisible cursor */ + {static XColor dummy; char data[1] = {0}; + Pixmap blank = XCreateBitmapFromData(dpy, win, data, 1, 1); + if (blank == None) return 0; + x11.cursor = XCreatePixmapCursor(dpy, blank, blank, &dummy, &dummy, 0, 0); + XFreePixmap(dpy, blank);} + + nk_init_default(&x11.ctx, 0); + return &x11.ctx; +} + +NK_API void +nk_x11_shutdown(void) +{ + nk_font_atlas_clear(&x11.atlas); + nk_free(&x11.ctx); + nk_x11_device_destroy(); + XFreeCursor(x11.dpy, x11.cursor); + memset(&x11, 0, sizeof(x11)); +} + +#endif diff --git a/src/drivers/mii_disk2.c b/src/drivers/mii_disk2.c new file mode 100644 index 0000000..8cf522b --- /dev/null +++ b/src/drivers/mii_disk2.c @@ -0,0 +1,379 @@ +/* + * mii_disk2.c + * + * Copyright (C) 2023 Michel Pollet + * + * SPDX-License-Identifier: MIT + */ + +// Shamelesly lifted from periph/disk2.c +// +// Copyright (c) 2023 Micah John Cowan. +// This code is licensed under the MIT license. +// See the accompanying LICENSE file for details. + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "mii.h" +#include "mii_bank.h" +#include "mii_disk2.h" +#include "mii_rom_disk2.h" +#include "mii_disk_format.h" + +//#define DISK_DEBUG +#ifdef DISK_DEBUG +# define D2DBG(...) do { \ + if (c->pr_count == 1) \ + fprintf(stderr, __VA_ARGS__); \ + } while(0) +#else +# define D2DBG(...) +#endif + +typedef struct mii_card_disk2_t { + uint32_t timer; + bool motor_on; + bool drive_two; + bool write_mode; + union { + struct { + DiskFormatDesc disk1; + DiskFormatDesc disk2; + }; + DiskFormatDesc disk[2]; + }; + uint8_t data_register; // only used for write + bool steppers[4]; + int cog1; + int cog2; +// int pr_count; // debug print +} mii_card_disk2_t; + +//static const size_t dsk_disksz = 143360; + +int disk2_debug = 0; + +static DiskFormatDesc * +active_disk_obj( + mii_card_disk2_t *c) +{ + return c->drive_two ? &c->disk2 : &c->disk1; +} + +#if 0 +bool +drive_spinning( + mii_card_disk2_t *c) +{ + return c->motor_on; +} + +int +active_disk( + mii_card_disk2_t *c) +{ + return c->drive_two ? 2 : 1; +} +int +eject_disk( + mii_card_disk2_t *c, + int drive) +{ + if (c->motor_on && active_disk(c) == drive) { + return -1; + } + init(c); // to make sure + + if (drive == 1) { + c->disk1.eject(&c->disk1); + c->disk1 = disk_format_load(NULL); + } else if (drive == 2) { + c->disk2.eject(&c->disk2); + c->disk2 = disk_format_load(NULL); + } + return 0; +} + +int +insert_disk( + mii_card_disk2_t *c, + int drive, + const char *path) +{ + int err = eject_disk(c, drive); + if (err != 0) return err; + + // Make sure we're inserted to slot 6 + // XXX should check for error/distinguish if we're already in that slot + (void) periph_slot_reg(6, &disk2card); + + if (err) { + return -1; // XXX should be a distinguishable err code + } + if (drive == 1) { + c->disk1 = disk_format_load(path); + } else if (drive == 2) { + c->disk2 = disk_format_load(path); + } + + return 0; +} +#endif + +// NOTE: cog "left" and "right" refers only to the number line, +// and not the physical cog or track head movement. +static bool +cogleft( + mii_card_disk2_t *c, + int *cog) +{ + int cl = ((*cog) + 3) % 4; // position to the "left" of cog + return (!c->steppers[(*cog)] && c->steppers[cl]); +} + +// NOTE: cog "left" and "right" refers only to the number line, +// and not the physical cog or track head movement. +static bool +cogright( + mii_card_disk2_t *c, + int *cog) +{ + int cr = ((*cog) + 1) % 4; // position to the "right" of cog + return (!c->steppers[(*cog)] && c->steppers[cr]); +} + +static int * +active_cog( + mii_card_disk2_t *c) +{ + return c->drive_two? &c->cog2 : &c->cog1; +} + +static void +adjust_track( + mii_card_disk2_t *c) +{ + DiskFormatDesc *disk = active_disk_obj(c); + int *cog = active_cog(c); + D2DBG("halftrack: "); + if (cogleft(c, cog)) { + *cog = ((*cog) + 3) % 4; + if (disk->halftrack > 0) --disk->halftrack; + D2DBG("dec to %d", disk->halftrack); + } else if (cogright(c, cog)) { + *cog = ((*cog) + 1) % 4; + if (disk->halftrack < 69) ++disk->halftrack; + D2DBG("inc to %d", disk->halftrack); + } else { + D2DBG("no change (%d)", disk->halftrack); + } +} + +static void +stepper_motor( + mii_card_disk2_t *c, + uint8_t psw) +{ + uint8_t phase = psw >> 1; + bool onoff = (psw & 1) != 0; + + D2DBG("phase %d %s ", (int)phase, onoff? "on, " : "off,"); + c->steppers[phase] = onoff; + adjust_track(c); +} + +static inline uint8_t encode4x4(mii_card_disk2_t *c, uint8_t orig) +{ + return (orig | 0xAA); +} + +static void turn_off_motor(mii_card_disk2_t *c) +{ + c->motor_on = false; + DiskFormatDesc *disk = active_disk_obj(c); + disk->spin(disk, false); +// event_fire_disk_active(0); +} + +static int +_mii_disk2_init( + mii_t * mii, + struct mii_slot_t *slot ) +{ + mii_card_disk2_t *c = calloc(1, sizeof(*c)); + + slot->drv_priv = c; + c->disk1 = disk_format_load(NULL); + c->disk2 = disk_format_load(NULL); + printf("%s loading in slot %d\n", __func__, slot->id + 1); + uint16_t addr = 0xc100 + (slot->id * 0x100); + mii_bank_write( + &mii->bank[MII_BANK_CARD_ROM], + addr, mii_rom_disk2, 256); + + return 0; +} + +static void +_mii_disk2_run( + mii_t * mii, + struct mii_slot_t *slot) +{ + mii_card_disk2_t *c = slot->drv_priv; + if (c->timer && c->timer <= mii->video.frame_count) { + printf("%s turning off motor\n", __func__); + c->timer = 0; + turn_off_motor(c); + } +} + +static uint8_t +_mii_disk2_access( + mii_t * mii, struct mii_slot_t *slot, + uint16_t addr, uint8_t byte, bool write) +{ + mii_card_disk2_t *c = slot->drv_priv; + uint8_t ret = 0; + + int psw = addr & 0x0F; + + if (c->timer) + c->timer = mii->video.frame_count + 60; + uint8_t last = -1; + if (disk2_debug && last != psw + (write? 0x10 : 0)) + printf("disk sw $%02X, PC = $%04X\n", psw, mii->cpu.PC); + last = psw + (write? 0x10 : 0); + if (write) + c->data_register = byte; // ANY write sets data register + if (psw < 8) { + stepper_motor(c, psw); + } else switch (psw) { + case 0x08: + if (c->motor_on) { + c->timer = mii->video.frame_count + 60; + //frame_timer(60, turn_off_motor); + } + break; + case 0x09: { +// frame_timer_cancel(turn_off_motor); + c->timer = 0; + c->motor_on = true; + DiskFormatDesc *disk = active_disk_obj(c); + disk->spin(disk, true); + if (disk2_debug) + printf("%s turning on motor %d\n", __func__, c->drive_two); + // event_fire_disk_active(drive_two? 2 : 1); + } break; + case 0x0A: + if (c->motor_on && c->drive_two) { + c->disk2.spin(&c->disk2, false); + c->disk1.spin(&c->disk1, true); + } + c->drive_two = false; + if (c->motor_on) { + // event_fire_disk_active(1); + } + break; + case 0x0B: + if (c->motor_on && !c->drive_two) { + c->disk1.spin(&c->disk1, false); + c->disk2.spin(&c->disk2, true); + } + c->drive_two = true; + if (c->motor_on) { + // event_fire_disk_active(2); + } + break; + case 0x0C: { + DiskFormatDesc *disk = active_disk_obj(c); + if (!c->motor_on) { + // do nothing + } else if (c->write_mode) { + // XXX ignores timing + disk->write_byte(disk, c->data_register); + c->data_register = 0; // "shifted out". + } else { + // XXX any even-numbered switch can be used + // to read a byte. But for now we do so only + // through the sanctioned switch for that purpose. + ret = c->data_register = disk->read_byte(disk); + // printf("read byte %02X\n", ret); + } + } break; + case 0x0D: +#if 0 + if (!motor_on || drive_two) { + // do nothing + } else if (write_mode) { + data_register = (val == -1? 0: val); + } else { + // XXX should return whether disk is write-protected... + } +#endif + break; + case 0x0E: + c->write_mode = false; + if (disk2_debug) + printf("%s write mode off\n", __func__); + break; + case 0x0F: + c->write_mode = true; + if (disk2_debug) + printf("%s write mode on\n", __func__); + break; + default: + ; + } + + D2DBG("\n"); + + return ret; +} + +static int +_mii_disk2_command( + mii_t * mii, + struct mii_slot_t *slot, + uint8_t cmd, + void * param) +{ + mii_card_disk2_t *c = slot->drv_priv; + switch (cmd) { + case MII_SLOT_DRIVE_COUNT: + if (param) + *(int *)param = 2; + break; + case MII_SLOT_DRIVE_LOAD ... MII_SLOT_DRIVE_LOAD + 2 - 1: + if (param) { + int drive = cmd - MII_SLOT_DRIVE_LOAD; + const char *filename = param; + if (c->disk[drive].privdat) { + c->disk[drive].eject(&c->disk[drive]); + } + printf("%s: drive %d loading %s\n", __func__, drive, + filename); + c->disk[drive] = disk_format_load(filename); + return 0; + } + break; + } + return 0; +} + +static mii_slot_drv_t _driver = { + .name = "disk2", + .desc = "Apple Disk ][", + .init = _mii_disk2_init, + .access = _mii_disk2_access, + .run = _mii_disk2_run, + .command = _mii_disk2_command, +}; +MI_DRIVER_REGISTER(_driver); diff --git a/src/drivers/mii_disk2.h b/src/drivers/mii_disk2.h new file mode 100644 index 0000000..a90d993 --- /dev/null +++ b/src/drivers/mii_disk2.h @@ -0,0 +1,9 @@ +/* + * mii_disk2.h + * + * Copyright (C) 2023 Michel Pollet + * + * SPDX-License-Identifier: MIT + */ + +#pragma once diff --git a/src/drivers/mii_epromcard.c b/src/drivers/mii_epromcard.c new file mode 100644 index 0000000..855d6c5 --- /dev/null +++ b/src/drivers/mii_epromcard.c @@ -0,0 +1,89 @@ +/* + * mii_epromcard.c + * + * Copyright (C) 2023 Michel Pollet + * + * SPDX-License-Identifier: MIT + * + * This is a driver for these eprom/flash cards from + * Terence J. Boldt and the likes + */ +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "mii.h" +#include "mii_bank.h" + +typedef struct mii_card_ee_t { + uint8_t * file; + uint16_t latch; +} mii_card_ee_t; + +int mmapfile(const char *fname, uint8_t **buf, size_t *sz, int flags); + +static int +_mii_ee_init( + mii_t * mii, + struct mii_slot_t *slot ) +{ + uint8_t * file; + size_t sz; + const char *fname = "disks/Apple IIe Diagnostic 2.1.po"; + //const char *fname = "disks/GamesWithFirmware.po"; + + if (mmapfile(fname, &file, &sz, O_RDONLY) != 0) { + printf("Failed to load %s\n", fname); + return -1; + } + mii_card_ee_t *c = calloc(1, sizeof(*c)); + + slot->drv_priv = c; + c->file = file; + printf("%s loading in slot %d\n", __func__, slot->id); + uint16_t addr = 0xc100 + (slot->id * 0x100); + mii_bank_write( + &mii->bank[MII_BANK_CARD_ROM], + addr, c->file + 0x300, 256); + + return 0; +} + +static uint8_t +_mii_ee_access( + mii_t * mii, struct mii_slot_t *slot, + uint16_t addr, uint8_t byte, bool write) +{ + mii_card_ee_t *c = slot->drv_priv; + +// printf("%s PC:%04x addr %04x %02x wr:%d\n", __func__, +// mii->cpu.PC, addr, byte, write); + int psw = addr & 0x0F; + if (write) { + switch (psw) { + case 0: + c->latch = (c->latch & 0xff00) | byte; + break; + case 1: + c->latch = (c->latch & 0x00ff) | (byte << 8); + break; + } + } else { + return c->file[(c->latch << 4) + psw]; + } + return 0; +} + +static mii_slot_drv_t _driver = { + .name = "eecard", + .desc = "EEPROM 1MB card", + .init = _mii_ee_init, + .access = _mii_ee_access, +}; +MI_DRIVER_REGISTER(_driver); diff --git a/src/drivers/mii_mouse.c b/src/drivers/mii_mouse.c new file mode 100644 index 0000000..3fe518d --- /dev/null +++ b/src/drivers/mii_mouse.c @@ -0,0 +1,187 @@ + + +#include "mii.h" + +// https://github.com/ivanizag/izapple2/blob/master/cardMouse.go +// https://hackaday.io/project/19925-aiie-an-embedded-apple-e-emulator/log/188017-entry-23-here-mousie-mousie-mousie +// https://github.com/ct6502/apple2ts/blob/main/src/emulator/mouse.ts + +#include +#include +#include +#include +#include +#include + +#include "mii.h" +#include "mii_bank.h" + + +enum { + CLAMP_MIN_LO = 0x478, + CLAMP_MIN_HI = 0x578, + CLAMP_MAX_LO = 0x4F8, + CLAMP_MAX_HI = 0x5F8, + + // RAM Locations + // (Add $Cn where n is slot to these) + MOUSE_X_LO = 0x03B8, + MOUSE_X_HI = 0x04B8, + MOUSE_Y_LO = 0x0438, + MOUSE_Y_HI = 0x0538, + MOUSE_STATUS = 0x06B8, + MOUSE_MODE = 0x0738, +}; + +enum { + mouseEnabled = 1, + mouseIntMoveEnabled = 2, + mouseIntButtonEnabled = 4, + mouseIntVBlankEnabled = 8, +}; + +typedef struct mii_card_mouse_t { + struct mii_slot_t * slot; + uint8_t slot_offset; + uint8_t mode; // cached mode byte + struct { + uint16_t x, y; + bool button; + } last; +} mii_card_mouse_t; + +static int +_mii_mouse_init( + mii_t * mii, + struct mii_slot_t *slot ) +{ + mii_card_mouse_t *c = calloc(1, sizeof(*c)); + c->slot = slot; + slot->drv_priv = c; + + printf("%s loading in slot %d\n", __func__, slot->id + 1); + + c->slot_offset = slot->id + 1 + 0xc0; + uint8_t data[256] = {}; + + // Identification as a mouse card + // From Technical Note Misc #8, "Pascal 1.1 Firmware Protocol ID Bytes": + data[0x05] = 0x38; + data[0x07] = 0x18; + data[0x0b] = 0x01; + data[0x0c] = 0x20; + // From "AppleMouse // User's Manual", Appendix B: + //data[0x0c] = 0x20 + data[0xfb] = 0xd6; + + // Set 8 entrypoints to sofstwitches 2 to 1f + for (int i = 0; i < 14; i++) { + uint8_t base = 0x60 + 0x05 * i; + data[0x12+i] = base; + data[base+0] = 0x8D; // STA $C0x2 + data[base+1] = 0x82 + i + ((slot->id + 1) << 4); + data[base+2] = 0xC0; + data[base+3] = 0x18; // CLC ;no error + data[base+4] = 0x60; // RTS + } + + uint16_t addr = 0xc100 + (slot->id * 0x100); + mii_bank_write( + &mii->bank[MII_BANK_CARD_ROM], + addr, data, 256); + + return 0; +} + +static uint8_t +_mii_mouse_access( + mii_t * mii, + struct mii_slot_t *slot, + uint16_t addr, + uint8_t byte, + bool write) +{ + mii_card_mouse_t *c = slot->drv_priv; + + int psw = addr & 0x0F; + mii_bank_t * main = &mii->bank[MII_BANK_MAIN]; + switch (psw) { + case 2: { + if (write) { + byte &= 0xf; + mii_bank_poke(main, MOUSE_MODE + c->slot_offset, byte); + printf("%s: mouse mode %02x\n", __func__, byte); + mii->mouse.enabled = byte & mouseEnabled; + printf("Mouse %s\n", mii->mouse.enabled ? "enabled" : "disabled"); + printf(" Interupt: %s\n", byte & mouseIntMoveEnabled ? "enabled" : "disabled"); + printf(" Button: %s\n", byte & mouseIntButtonEnabled ? "enabled" : "disabled"); + printf(" VBlank: %s\n", byte & mouseIntVBlankEnabled ? "enabled" : "disabled"); + c->mode = byte; + mii->video.vbl_irq = !!(byte & mouseIntVBlankEnabled); + } + } break; + case 4: {// read mouse + if (!mii->mouse.enabled) + break; + uint8_t status = 0; + if (mii->mouse.button) + status |= 1 << 7; + if (c->last.button) { + status |= 1 << 6; + } + if ((mii->mouse.x != c->last.x) || (mii->mouse.y != c->last.y)) { + status |= 1 << 5; + } + mii_bank_poke(main, MOUSE_X_HI + c->slot_offset, mii->mouse.x >> 8); + mii_bank_poke(main, MOUSE_Y_HI + c->slot_offset, mii->mouse.y >> 8); + mii_bank_poke(main, MOUSE_X_LO + c->slot_offset, mii->mouse.x); + mii_bank_poke(main, MOUSE_Y_LO + c->slot_offset, mii->mouse.y); + mii_bank_poke(main, MOUSE_STATUS + c->slot_offset, status); + // mii_bank_poke(main, MOUSE_MODE + c->slot_offset, 0xf); // already in place + c->last.x = mii->mouse.x; + c->last.y = mii->mouse.y; + c->last.button = mii->mouse.button; + } break; + case 5: // clear mouse + break; + case 7: // set mouse + if (byte == 0) { + mii->mouse.min_x = mii_bank_peek(main, CLAMP_MIN_LO) | + (mii_bank_peek(main, CLAMP_MIN_HI) << 8); + mii->mouse.max_x = mii_bank_peek(main, CLAMP_MAX_LO) | + (mii_bank_peek(main, CLAMP_MAX_HI) << 8); + } else if (byte == 1) { + mii->mouse.min_y = mii_bank_peek(main, CLAMP_MIN_LO) | + (mii_bank_peek(main, CLAMP_MIN_HI) << 8); + mii->mouse.max_y = mii_bank_peek(main, CLAMP_MAX_LO) | + (mii_bank_peek(main, CLAMP_MAX_HI) << 8); + } + printf("Mouse clamp to %d,%d - %d,%d\n", + mii->mouse.min_x, mii->mouse.min_y, + mii->mouse.max_x, mii->mouse.max_y); + break; + case 8: // home mouse + mii->mouse.x = mii->mouse.min_x; + mii->mouse.y = mii->mouse.min_y; + break; + case 0xc: // init mouse + mii->mouse.min_x = mii->mouse.min_y = 0; + mii->mouse.max_x = mii->mouse.max_y = 1023; + mii->mouse.enabled = 0; + mii_bank_poke(main, MOUSE_MODE + c->slot_offset, 0x0); + break; + default: + printf("%s PC:%04x addr %04x %02x wr:%d\n", __func__, + mii->cpu.PC, addr, byte, write); + break; + } + return 0; +} + +static mii_slot_drv_t _driver = { + .name = "mouse", + .desc = "Mouse card", + .init = _mii_mouse_init, + .access = _mii_mouse_access, +}; +MI_DRIVER_REGISTER(_driver); diff --git a/src/drivers/mii_mouse.h b/src/drivers/mii_mouse.h new file mode 100644 index 0000000..b3bd521 --- /dev/null +++ b/src/drivers/mii_mouse.h @@ -0,0 +1,21 @@ +/* + * mii_mouse.h + * + * Copyright (C) 2023 Michel Pollet + * + * SPDX-License-Identifier: MIT + */ + +#pragma once + +#include +#include + + // mins/max are set by the card, x,y,button are set by the UI +typedef struct mii_mouse_t { + bool enabled; // read only, set by driver + uint16_t min_x, max_x, + min_y, max_y; // set by driver when enabled + uint16_t x, y; + bool button; +} mii_mouse_t; diff --git a/src/drivers/mii_noslotclock.c b/src/drivers/mii_noslotclock.c new file mode 100644 index 0000000..64e0ee6 --- /dev/null +++ b/src/drivers/mii_noslotclock.c @@ -0,0 +1,177 @@ +/* + * mii_noslotclock.c + * + * Copyright (C) 2023 Michel Pollet + * + * SPDX-License-Identifier: MIT + * + */ +// http://ctrl.pomme.reset.free.fr/index.php/hardware/no-slot-clock-ds1216e/ +// Disassembly: +// https://gist.github.com/mgcaret/ae2860c754fd029d2640107c4fe0bffd + + +#include +#include +#include +#include +#include +#include +#include +#include "mii.h" +#include "mii_bank.h" +#include "minipt.h" + +const uint64_t nsc_pattern = 0x5CA33AC55CA33AC5ULL; + +typedef struct mii_nsc_t { + mii_t * mii; + uint64_t pattern; + void * state; // protothread state + int bitcount; + int mode; // read or write; +} mii_nsc_t; + +static void +_mii_nsc_maketime( + mii_nsc_t *nsc) +{ + uint64_t ret = 0; + + time_t now = time(NULL); + struct tm t; + localtime_r(&now, &t); + + int year = t.tm_year % 100; + ret = year / 10; + ret <<= 4; + ret += year % 10; + ret <<= 4; + + int month = t.tm_mon + 1; + ret += month / 10; + ret <<= 4; + ret += month % 10; + ret <<= 4; + + int day = t.tm_mday; + ret += day / 10; + ret <<= 4; + ret += day % 10; + ret <<= 4; + + // Bits 4 and 5 of the day ret are used to control the RST and oscillator + // functions. These bits are shipped from the factory set to logic 1. + ret += 0x0; //0x3, but zero on read. + ret <<= 4; + ret += t.tm_wday + 1; // uint64(now.Weekday()) + 1 + ret <<= 4; + + int hour = t.tm_hour; + ret += 0x0; // 0x8 for 24 hour mode, but zero on read. + ret += hour / 10; + ret <<= 4; + ret += hour % 10; + ret <<= 4; + + int minute = t.tm_min; + ret += minute / 10; + ret <<= 4; + ret += minute % 10; + ret <<= 4; + + int second = t.tm_sec; + ret += second / 10; + ret <<= 4; + ret += second % 10; + ret <<= 4; + + int centisecond = 0; + ret += centisecond / 10; + ret <<= 4; + ret += centisecond % 10; + nsc->pattern = ret; +} + +/* + * this is a protothread, so remember no locals that will survive a yield() + */ +static bool +_mii_nsc_access( + struct mii_bank_t *bank, + void *param, + uint16_t addr, + uint8_t * byte, + bool write) +{ + mii_nsc_t * nsc = param; +// printf("%s PC:%04x access %s addr %04x byte %02x write %d\n", +// __func__, nsc->mii->cpu.PC, +// bank->name, addr, *byte, write); + int rd = (addr & 0x4); + int bit = addr & 1; + bool res = false; + pt_start(nsc->state); + do { + if (rd) { + nsc->pattern = 0; + } else { + nsc->pattern = (nsc->pattern >> 1) | ((uint64_t)bit << 63); + int match = nsc->pattern == nsc_pattern; + if (match) { + // printf("pattern %016lx %s\n", nsc->pattern, match ? "match" : ""); + break; + } + } + pt_yield(nsc->state); + } while (1); + nsc->bitcount = 0; + pt_yield(nsc->state); + nsc->mode = rd; +// printf("%s in %s mode\n", __func__, rd ? "read" : "write"); + if (nsc->mode) { + _mii_nsc_maketime(nsc); + // printf("time %016lx\n", nsc->pattern); + } + do { + if (nsc->mode) { + *byte = (nsc->pattern >> nsc->bitcount) & 1; + } else { + nsc->pattern |= ((uint64_t)bit << nsc->bitcount); + } + res = true; // don't call ROM handler + pt_yield(nsc->state); + nsc->bitcount++; + } while (nsc->bitcount < 64 && nsc->mode == rd); +// printf("%s done\n", __func__); + pt_end(nsc->state); + return res; +} + +static int +_mii_nsc_probe( + mii_t *mii, + uint32_t flags) +{ + printf("%s %s\n", __func__, flags & MII_INIT_NSC ? "enabled" : "disabled"); + if (!(flags & MII_INIT_NSC)) + return 0; + mii_nsc_t * nsc = calloc(1, sizeof(*nsc)); + nsc->mii = mii; + // This worked fine with NS.CLOCK.SYSTEM but... +// mii_bank_install_access_cb(&mii->bank[MII_BANK_CARD_ROM], +// _mii_nsc_access, nsc, 0xc1, 0); + /* ... A2Desktop requires the NSC to be on the main rom, the source + * claims it probe the slots, but in fact, it doesnt */ + mii_bank_install_access_cb(&mii->bank[MII_BANK_ROM], + _mii_nsc_access, nsc, 0xc3, 0); + return 1; +} + +static mii_slot_drv_t _driver = { + .name = "nsc", + .desc = "No Slot Clock", + .enable_flag = MII_INIT_NSC, + .probe = _mii_nsc_probe, +}; +MI_DRIVER_REGISTER(_driver); diff --git a/src/drivers/mii_smartport.c b/src/drivers/mii_smartport.c new file mode 100644 index 0000000..2c45081 --- /dev/null +++ b/src/drivers/mii_smartport.c @@ -0,0 +1,342 @@ +/* + * mii_smartport.c + * + * Copyright (C) 2023 Michel Pollet + * + * SPDX-License-Identifier: MIT + * + * This is shamelessly inspired from: + * https:github.com/ct6502/apple2ts/blob/main/src/emulator/harddrivedata.ts + * http://www.1000bit.it/support/manuali/apple/technotes/smpt/tn.smpt.1.html + */ +#define _GNU_SOURCE // for asprintf +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "mii.h" +#include "mii_bank.h" +#include "mii_dd.h" +#include "mii_slot.h" + +#define INCBIN_STYLE INCBIN_STYLE_SNAKE +#define INCBIN_PREFIX mii_ +#include "incbin.h" + +INCBIN(smartport_rom, "test/asm/mii_smartport_driver.bin"); + +extern const unsigned char mii_smartport_rom_data[]; + +#define MII_SM_DRIVE_COUNT 2 + +typedef struct mii_card_sm_t { + struct mii_card_sm_t *next; + mii_dd_t drive[MII_SM_DRIVE_COUNT]; + struct mii_slot_t *slot; + uint8_t * file; +} mii_card_sm_t; + +static void +_mii_hd_callback( + mii_t *mii, + uint8_t trap) +{ + int sid = ((mii->cpu.PC >> 8) & 0xf) - 1; + mii_card_sm_t *c = mii->slot[sid].drv_priv; + + uint8_t command = mii_read_one(mii, 0x42); + uint8_t unit = mii_read_one(mii, 0x43); + uint16_t buffer = mii_read_word(mii, 0x44); + uint16_t blk = mii_read_word(mii, 0x46); + + unit >>= 7; // last bit is the one we want, drive 0/1 + switch (command) { + case 0: { // get status + if (!c->drive[unit].file) { + mii->cpu.X = mii->cpu.Y = 0; + mii->cpu.P.C = 1; + } else { + int nblocks = (c->drive[unit].file->size + 511) / 512; + mii->cpu.X = nblocks & 0xff; + mii->cpu.Y = nblocks >> 8; + mii->cpu.P.C = 0; + } + } break; + case 1: {// read block + if (!c->drive[unit].file) { + mii->cpu.P.C = 1; + break; + } + if (blk >= c->drive[unit].file->size / 512) { + mii->cpu.P.C = 1; + break; + } + mii_bank_t * bank = &mii->bank[mii->mem[buffer >> 8].write]; + mii->cpu.P.C = mii_dd_read( + &c->drive[unit], bank, buffer, blk, 1) != 0; + } break; + case 2: {// write block + if (!c->drive[unit].file) { + mii->cpu.P.C = 1; + break; + } + if (blk >= c->drive[unit].file->size / 512) { + mii->cpu.P.C = 1; + break; + } + mii_bank_t * bank = &mii->bank[mii->mem[buffer >> 8].read]; + mii->cpu.P.C = mii_dd_write( + &c->drive[unit], bank, buffer, blk, 1) != 0; + } break; + default: { + printf("%s cmd %02x unit %02x buffer %04x blk %04x\n", __func__, + command, unit, buffer, blk); + printf("*** %s: unhandled command %02x\n", __func__, command); + mii->cpu.P.C = 1; + } + } +} + +static void +_mii_sm_callback( + mii_t *mii, + uint8_t trap) +{ + printf("%s\n", __func__); + int sid = ((mii->cpu.PC >> 8) & 0xf) - 1; + mii_card_sm_t *c = mii->slot[sid].drv_priv; + + uint16_t sp = 0x100 + mii->cpu.S + 1; + uint16_t call_addr = mii_read_word(mii, sp); + uint8_t spCommand = mii_read_one(mii, call_addr + 1); + uint16_t spParams = mii_read_word(mii, call_addr + 2); + call_addr += 3; + mii_write_word(mii, sp, call_addr); + + uint8_t spPCount = mii_read_one(mii, spParams + 0); + uint8_t spUnit = mii_read_one(mii, spParams + 1); + uint16_t spBuffer = mii_read_word(mii, spParams + 2); + + printf("%s cmd %02x params %04x pcount %d unit %02x buffer %04x\n", __func__, + spCommand, spParams, spPCount, spUnit, spBuffer); + switch (spCommand) { + case 0: { // get status + if (spPCount != 3) { + mii->cpu.P.C = 1; + break; + } + uint8_t status = mii_read_one(mii, spParams + 4); + printf("%s: unit %d status %02x \n", __func__, spUnit, status); + uint8_t st = 0x80 | 0x40 | 0x20; + uint32_t bsize = 0; + if (spUnit) spUnit--; + if (spUnit < MII_SM_DRIVE_COUNT && c->drive[spUnit].file) { + st |= 0x10; + bsize = (c->drive[spUnit].file->size + 511) / 512; + } + if (status == 0) { + mii->cpu.P.C = 0; + /* Apple IIc reference says this ought to be a status byte, + * but practice and A2Desktop says it ought to be a drive + * count, so here goes... */ +// mii_write_one(mii, spBuffer++, st); + mii_write_one(mii, spBuffer++, MII_SM_DRIVE_COUNT); + mii_write_one(mii, spBuffer++, bsize); + mii_write_one(mii, spBuffer++, bsize >> 8); + mii_write_one(mii, spBuffer++, bsize >> 16); + } else if (status == 3 && spUnit < MII_SM_DRIVE_COUNT) { + mii->cpu.P.C = 0; + mii_write_one(mii, spBuffer++, st); + mii_write_one(mii, spBuffer++, bsize); + mii_write_one(mii, spBuffer++, bsize >> 8); + mii_write_one(mii, spBuffer++, bsize >> 16); + char dname[17] = "\x8MII HD 0 "; + dname[8] = '0' + spUnit; + for (int i = 0; i < 17; i++) + mii_write_one(mii, spBuffer++, dname[i]); + mii_write_one(mii, spBuffer++, 0x02); // Profile + mii_write_one(mii, spBuffer++, 0x00); // Profile + mii_write_one(mii, spBuffer++, 0x01); // Version + mii_write_one(mii, spBuffer++, 0x13); + } else { + printf("%s: unit %d bad status %d\n", + __func__, spUnit, status); + mii->cpu.P.C = 1; + } + } break; + case 1: { // read + if (spPCount != 3) { + printf("%s: unit %d bad pcount %d\n", + __func__, spUnit, spPCount); + mii->cpu.P.C = 1; + break; + } + if (spUnit >= MII_SM_DRIVE_COUNT) { + printf("%s: unit %d out of range\n", + __func__, spUnit); + mii->cpu.P.C = 1; + break; + } + uint32_t blk = mii_read_word(mii, spParams + 3) | + (mii_read_one(mii, spParams + 4) << 16) | + (mii_read_one(mii, spParams + 5) << 24); + printf("%s read block %x\n", __func__, blk); + if (!c->drive[spUnit].file) { + mii->cpu.P.C = 1; + break; + } + if (blk >= c->drive[spUnit].file->size / 512) { + printf("%s: block %d out of range\n", + __func__, blk); + mii->cpu.P.C = 1; + break; + } + mii_bank_t * bank = &mii->bank[mii->mem[spBuffer >> 8].write]; + mii->cpu.P.C = mii_dd_read( + &c->drive[spUnit], bank, spBuffer, blk, 1) != 0; + // mii->cpu.P.C = 0; + } break; + case 2: { // write + if (spPCount != 3) { + printf("%s: unit %d bad pcount %d\n", + __func__, spUnit, spPCount); + mii->cpu.P.C = 1; + break; + } + if (spUnit >= MII_SM_DRIVE_COUNT) { + printf("%s: unit %d out of range\n", + __func__, spUnit); + mii->cpu.P.C = 1; + break; + } + uint32_t blk = mii_read_word(mii, spParams + 3) | + (mii_read_one(mii, spParams + 4) << 16) | + (mii_read_one(mii, spParams + 5) << 24); + printf("%s write block %x\n", __func__, blk); + if (!c->drive[spUnit].file) { + mii->cpu.P.C = 1; + break; + } + if (blk >= c->drive[spUnit].file->size / 512) { + printf("%s: block %d out of range\n", + __func__, blk); + mii->cpu.P.C = 1; + break; + } + mii_bank_t * bank = &mii->bank[mii->mem[spBuffer >> 8].read]; + mii->cpu.P.C = mii_dd_write( + &c->drive[spUnit], bank, spBuffer, blk, 1) != 0; + } break; + } +} + +static int +_mii_sm_init( + mii_t * mii, + struct mii_slot_t *slot ) +{ + mii_card_sm_t *c = calloc(1, sizeof(*c)); + c->slot = slot; + slot->drv_priv = c; + + printf("%s loading in slot %d\n", __func__, slot->id); + uint16_t addr = 0xc100 + (slot->id * 0x100); + mii_bank_write( + &mii->bank[MII_BANK_CARD_ROM], + addr, mii_smartport_rom_data, 256); + + uint8_t trap_hd = mii_register_trap(mii, _mii_hd_callback); + uint8_t trap_sm = mii_register_trap(mii, _mii_sm_callback); + printf("%s: traps %02x %02x\n", __func__, trap_hd, trap_sm); + mii_bank_write( + &mii->bank[MII_BANK_CARD_ROM], + addr + 0xd2, &trap_hd, 1); + mii_bank_write( + &mii->bank[MII_BANK_CARD_ROM], + addr + 0xe2, &trap_sm, 1); + + for (int i = 0; i < MII_SM_DRIVE_COUNT; i++) { + mii_dd_t *dd = &c->drive[i]; + dd->slot_id = slot->id + 1; + dd->drive = i + 1; + dd->slot = slot; + asprintf((char **)&dd->name, "SmartPort S:%d D:%d", + dd->slot_id, dd->drive); + } + mii_dd_register_drives(&mii->dd, c->drive, MII_SM_DRIVE_COUNT); + + return 0; +} + +static int +_mii_sm_command( + mii_t * mii, + struct mii_slot_t *slot, + uint8_t cmd, + void * param) +{ + mii_card_sm_t *c = slot->drv_priv; + switch (cmd) { + case MII_SLOT_DRIVE_COUNT: + if (param) + *(int *)param = MII_SM_DRIVE_COUNT; + break; + case MII_SLOT_DRIVE_LOAD ... MII_SLOT_DRIVE_LOAD + MII_SM_DRIVE_COUNT - 1: + if (param) { + int drive = cmd - MII_SLOT_DRIVE_LOAD; + const char *filename = param; + mii_dd_file_t *file = NULL; + if (filename) { + file = mii_dd_file_load(&mii->dd, filename, 0); + if (!file) + return -1; + } + mii_dd_drive_load(&c->drive[drive], file); + return 0; + } + break; + } + return 0; +} + +static uint8_t +_mii_sm_access( + mii_t * mii, struct mii_slot_t *slot, + uint16_t addr, uint8_t byte, bool write) +{ + #if 0 + mii_card_sm_t *c = slot->drv_priv; + + printf("%s PC:%04x addr %04x %02x wr:%d\n", __func__, + mii->cpu.PC, addr, byte, write); + int psw = addr & 0x0F; + if (write) { + switch (psw) { + case 0: + // c->latch = (c->latch & 0xff00) | byte; + break; + case 1: + // c->latch = (c->latch & 0x00ff) | (byte << 8); + break; + } + } else { + // return c->file[(c->latch << 4) + psw]; + } + #endif + return 0; +} + +static mii_slot_drv_t _driver = { + .name = "smartport", + .desc = "SmartPort card", + .init = _mii_sm_init, + .access = _mii_sm_access, + .command = _mii_sm_command, +}; +MI_DRIVER_REGISTER(_driver); diff --git a/src/drivers/mii_titan_iie.c b/src/drivers/mii_titan_iie.c new file mode 100644 index 0000000..ca54a27 --- /dev/null +++ b/src/drivers/mii_titan_iie.c @@ -0,0 +1,79 @@ +/* + * mii_titan_iie.c + * + * Copyright (C) 2023 Michel Pollet + * + * SPDX-License-Identifier: MIT + */ + +#include +#include +#include +#include + +#include "mii.h" +#include "mii_bank.h" + +/* + * This is a mini driver for the Titan Accelerator IIe, not very common, + * but it's a nice card, and it's a good example of a driver that needs + * to use a softswitch ovverride to work. + * Also, I own one of these, and none of the other fancy ones, so this one + * gets the love. + */ +static bool +_mii_titan_access( + struct mii_bank_t *bank, + void *param, + uint16_t addr, + uint8_t * byte, + bool write) +{ + mii_t *mii = param; + bool res = false; + mii_bank_t *main = &mii->bank[MII_BANK_MAIN]; + if (write) { + printf("titan: write %02x to %04x\n", *byte, addr); + switch (*byte) { + case 5: + mii->speed = 3.58; + mii_bank_poke(main, 0xc086, *byte); + break; + case 1: + mii_bank_poke(main, 0xc086, *byte); + mii->speed = 1; + break; + case 0xa: // supposed to lock it too... + mii_bank_poke(main, 0xc086, *byte); + mii->speed = 1; + break; + default: + printf("titan: unknown speed %02x\n", *byte); + break; + } + } + return res; +} + +static int +_mii_titan_probe( + mii_t *mii, + uint32_t flags) +{ + printf("%s %s\n", __func__, flags & MII_INIT_TITAN ? "enabled" : "disabled"); + if (!(flags & MII_INIT_TITAN)) + return 0; + // this override a read-only soft switch, but we only handle writes + // so it's fine + mii_set_sw_override(mii, 0xc086, _mii_titan_access, mii); + mii->speed = 3.58; + return 1; +} + +static mii_slot_drv_t _driver = { + .name = "titan", + .desc = "Titan Accelerator IIe", + .enable_flag = MII_INIT_TITAN, + .probe = _mii_titan_probe, +}; +MI_DRIVER_REGISTER(_driver); diff --git a/src/format/dsk.c b/src/format/dsk.c new file mode 100644 index 0000000..38de340 --- /dev/null +++ b/src/format/dsk.c @@ -0,0 +1,472 @@ +// format/dsk.c +// +// Copyright (c) 2023 Micah John Cowan. +// This code is licensed under the MIT license. +// See the accompanying LICENSE file for details. + +#include +#include +#include +#include +#include +#include + +#include "mii_disk_format.h" + +#define NIBBLE_SECTOR_SIZE 416 +#define NIBBLE_TRACK_SIZE 6656 +#define DSK_SECTOR_SIZE 256 +#define MAX_SECTORS 16 +#define VOLUME_NUMBER 254 +#define DSK_TRACK_SIZE (DSK_SECTOR_SIZE * MAX_SECTORS) + +#define byte uint8_t + +struct dskprivdat { + const char *path; + byte *realbuf; + byte *buf; + const byte *secmap; + int bytenum; + uint64_t dirty_tracks; +}; +static const struct dskprivdat datinit = { 0 }; + +static const size_t nib_disksz = 232960; +static const size_t dsk_disksz = 143360; + +// DOS 3.3 Physical sector order (index is physical sector, +// value is DOS sector) +const byte DO[] = { + 0x0, 0x7, 0xE, 0x6, 0xD, 0x5, 0xC, 0x4, + 0xB, 0x3, 0xA, 0x2, 0x9, 0x1, 0x8, 0xF +}; + +// ProDOS Physical sector order (index is physical sector, +// value is ProDOS sector). +const byte PO[] = { + 0x0, 0x8, 0x1, 0x9, 0x2, 0xa, 0x3, 0xb, + 0x4, 0xc, 0x5, 0xd, 0x6, 0xe, 0x7, 0xf +}; + +const byte TRANS62[] = { + 0x96, 0x97, 0x9a, 0x9b, 0x9d, 0x9e, 0x9f, 0xa6, + 0xa7, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb2, 0xb3, + 0xb4, 0xb5, 0xb6, 0xb7, 0xb9, 0xba, 0xbb, 0xbc, + 0xbd, 0xbe, 0xbf, 0xcb, 0xcd, 0xce, 0xcf, 0xd3, + 0xd6, 0xd7, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, + 0xdf, 0xe5, 0xe6, 0xe7, 0xe9, 0xea, 0xeb, 0xec, + 0xed, 0xee, 0xef, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, + 0xf7, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff +}; + +static const int DETRANS62[] = { + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 0x00, 0x01, + -1, -1, 0x02, 0x03, -1, 0x04, 0x05, 0x06, + -1, -1, -1, -1, -1, -1, 0x07, 0x08, + -1, -1, -1, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, + -1, -1, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, + -1, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 0x1B, -1, 0x1C, 0x1D, 0x1E, + -1, -1, -1, 0x1F, -1, -1, 0x20, 0x21, + -1, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, + -1, -1, -1, -1, -1, 0x29, 0x2A, 0x2B, + -1, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, + -1, -1, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, + -1, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F +}; + +static void realign_tracks(DiskFormatDesc *desc) +{ + /* + When we unpack a .dsk into nibblized form, it's + automatically aligned neatly within our track-storage + boundaries within the disk buffer, because that's how + we laid 'em out. + + When a sector is written or updated, it will + tend to stay aligned, because the program had to + find the existing sector to write to, to keep things + in order. + + However, in the event of reformatting, there are no + guarantees about the track being aligned conveniently. + The formatting program can start at any old position + and just start writing, because no existing data is going + to be preserved. + + To deal with this, we could either: + 1) Be prepared to loop back around our track's buffer, + mid-sector + 2) Re-align the track at our convenience, to start + somewhere that we know for sure can't be the middle of + sector data. + + I've opted for option (2). It would be a bad option if + we're reading and writing a .nib file, because we'd be + unnecessarily altering the file's structure (in cases + where it had NOT been reformatted), but it's perfectly + fine when we'll be discarding the nibblized format anyway. + + We handle this by seeking forward to the first sector-field + start boundary (D5 AA 96) that we can find, and make that + the new "start" of our track. It doesn't matter if it's a + false-start that doesn't start a real sector-field, because one + thing we know for *sure* is that first D5 can't be found + in the middle of a legitimate header or data field. + */ + + struct dskprivdat *dat = desc->privdat; + byte *buf = dat->buf; + byte *secbuf = malloc(NIBBLE_TRACK_SIZE); + for (int t=0; t != NUM_TRACKS; ++t) { + byte *tstart = buf + (t * NIBBLE_TRACK_SIZE); + byte *tend = buf + ((t + 1) * NIBBLE_TRACK_SIZE); + byte *talign; + for (talign = tstart; talign <= (tend - 3); ++talign) { + if (talign[0] == 0xD5 && talign[1] == 0xAA && talign[2] == 0x96) { + if (talign == tstart) { + // Nothing to do, already aligned. + } else { + size_t rollsz = talign - tstart; + memcpy(secbuf, tstart, rollsz); + memmove(tstart, talign, tend-talign); + memcpy(tend - rollsz, secbuf, rollsz); + } + break; // handle next track + } + } + } + free(secbuf); +} + +static void implodeDo(DiskFormatDesc *desc) +{ + struct dskprivdat *dat = desc->privdat; + + realign_tracks(desc); + + const byte *rd = dat->buf; // nibble buf + const byte *end = dat->buf + nib_disksz; + + bool warned = false; + + for (;;) { + // Scan forward for a sector header + const int sector_hdr_sz = 11; // counts prologue, but not epilogue + for (;;) { + // This is the only place we're "allowed" to end processing. + if (rd >= (end - sector_hdr_sz)) goto done; + if (rd[0] == 0xD5 && rd[1] == 0xAA && rd[2] == 0x96) break; + ++rd; + } + +header: + rd += 3; + int v = ((rd[0] << 1) | 0x1) & rd[1]; + rd += 2; + int t = ((rd[0] << 1) | 0x1) & rd[1]; + rd += 2; + int s = ((rd[0] << 1) | 0x1) & rd[1]; + rd += 2; + int checkSum = ((rd[0] << 1) | 0x1) & rd[1]; + rd += 2; + + if (checkSum != (v ^ t ^ s)) { + WARN("Sector header checksum failed, t=%d s=%d" + " at nibblized byte %zu.\n", t, s, rd - dat->buf); + WARN("Probable disk corruption for %s\n", dat->path); + } + + byte truet = (rd - dat->buf)/NIBBLE_TRACK_SIZE; + if (t != truet) { + WARN("Sector header lying about track number" + " at nibblized pos %zu\n", (size_t)(rd - dat->buf)); + WARN(" (says %d but we're on track %d). Skipping sector.\n", + (int)t, (int)truet); + continue; + } + if (s >= MAX_SECTORS) { + WARN("Sector header sec# too high (%d; max is %d).\n", + (int)s, (int)MAX_SECTORS); + WARN(" Skipping sector.\n"); + continue; + } + + const int data_field_sz = 0x15A; //counts prologue, not epilogue + for (;;) { + if (rd >= (end - 0x15A)) goto bail; + if (rd[0] == 0xD5 && rd[1] == 0xAA) { + if (rd[2] == 0x96) goto header; + if (rd[2] == 0xAD) break; + } + ++rd; + } + + rd += 3; + + // Translate sector data field + { + int s_ = dat->secmap[s]; + byte *data = dat->realbuf + (t * DSK_TRACK_SIZE) + + (s_ * DSK_SECTOR_SIZE); + byte data2[0x56]; + byte last = 0; + int val; + + if (0) { + WARN("Translating track %d, phys sec %d (image sec %d)\n", + t, s, s_); + WARN(" starting at dsk pos %zu\n", (size_t)(data - dat->realbuf)); + } + + for (int j = 0x55; j >= 0; --j) { + val = DETRANS62[*rd - 0x80]; + if (val == -1 && !warned) { + warned = true; + WARN("Untranslatable nibble at (nibblized) pos %zu," + " disk %s.\n", (size_t)(rd - dat->buf), dat->path); + if (rd <= end - 4) { + WARN("%02X %02X %02X %02X [%02X] %02X %02X %02X\n", + rd[-4], rd[-3], rd[-2], rd[-1], + rd[0], rd[1], rd[2], rd[3]); + } + WARN("CORRUPT DISK SAVE TO %s\n", dat->path); + } + val ^= last; + data2[j] = val; + last = val; + ++rd; + } + + for (int j = 0; j < 0x100; ++j) { + val = DETRANS62[*rd - 0x80]; + if (val == -1 && !warned) { + warned = true; + WARN("Untranslatable nibble at t=%d, phys s=%d," + " disk %s.\n", t, s, dat->path); + WARN("CORRUPT DISK SAVE TO %s\n", dat->path); + } + val ^= last; + data[j] = val; + last = val; + ++rd; + } + + int checkSum = DETRANS62[*rd++ - 0x80]; + if (checkSum != -1) checkSum ^= last; + if (checkSum != 0) { + WARN("Bad sector data checksum at t=%d, phys s=%d," + " disk %s.\n", t, s, dat->path); + } + + for (int k = 0, j = 0x55; k < 0x100; ++k) { + data[k] <<= 1; + if ((data2[j] & 0x1) != 0) { + data[k] |= 0x01; + } + data2[j] >>= 1; + + data[k] <<= 1; + if ((data2[j] & 0x01) != 0) { + data[k] |= 0x01; + } + data2[j] >>= 0x01; + + if (--j < 0) j = 0x55; + } + } + } + +bail: + WARN("Error translating to dsk: ended mid-sector!\n"); + WARN("Probable disk corruption for %s\n", dat->path); +done: + return; +} + +static void spin(DiskFormatDesc *desc, bool b) +{ + struct dskprivdat *dat = desc->privdat; + if (!b && dat->dirty_tracks != 0) { + implodeDo(desc); + // For now, sync the entire disk + errno = 0; + int err = msync(dat->realbuf, dsk_disksz, MS_SYNC); + if (err < 0) { + DIE(1,"Couldn't sync to disk file %s: %s\n", + dat->path, strerror(errno)); + } + dat->dirty_tracks = 0; + } +} + +static byte read_byte(DiskFormatDesc *desc) +{ + struct dskprivdat *dat = desc->privdat; + size_t pos = (desc->halftrack/2) * NIBBLE_TRACK_SIZE; + pos += (dat->bytenum % NIBBLE_TRACK_SIZE); + byte val = dat->buf[pos]; + dat->bytenum = (dat->bytenum + 1) % NIBBLE_TRACK_SIZE; + return val; +} + +static void write_byte(DiskFormatDesc *desc, byte val) +{ + struct dskprivdat *dat = desc->privdat; + if ((val & 0x80) == 0) { + // D2DBG("dodged write $%02X", val); + return; // must have high bit + } + dat->dirty_tracks |= 1 << (desc->halftrack/2); + size_t pos = (desc->halftrack/2) * NIBBLE_TRACK_SIZE; + pos += (dat->bytenum % NIBBLE_TRACK_SIZE); + + //D2DBG("write byte $%02X at pos $%04zX", (unsigned int)val, pos); + + dat->buf[pos] = val; + dat->bytenum = (dat->bytenum + 1) % NIBBLE_TRACK_SIZE; +} + +static void eject(DiskFormatDesc *desc) +{ + // free dat->path and dat, and unmap disk image + struct dskprivdat *dat = desc->privdat; + (void) munmap(dat->buf, dsk_disksz); + free((void*)dat->path); + free(dat); +} + +// This function is derived from Scullin Steel Co.'s apple2js code +// https://github.com/whscullin/apple2js/blob/e280c3d/js/formats/format_utils.ts#L140 +static void explodeSector(byte vol, byte track, byte sector, + byte **nibSec, const byte *data) +{ + byte *wr = *nibSec; + unsigned int gap; + + // Gap 1/3 (40/0x28 bytes) + + if (sector == 0) // Gap 1 + gap = 0x80; + else { // Gap 3 + gap = track == 0? 0x28 : 0x26; + } + + for (uint8_t i = 0; i != gap; ++i) { + *wr++ = 0xFF; + } + + // Address Field + const byte checksum = vol ^ track ^ sector; + *wr++ = 0xD5; *wr++ = 0xAA; *wr++ = 0x96; // Address Prolog D5 AA 96 + *wr++ = (vol >> 1) | 0xAA; *wr++ = vol | 0xAA; + *wr++ = (track >> 1) | 0xAA; *wr++ = track | 0xAA; + *wr++ = (sector >> 1) | 0xAA; *wr++ = sector | 0xAA; + *wr++ = (checksum >> 1) | 0xAA; *wr++ = checksum | 0xAA; + *wr++ = 0xDE; *wr++ = 0xAA; *wr++ = 0xEB; // Epilogue DE AA EB + + // Gap 2 (5 bytes) + for (int i = 0; i != 5; ++i) { + *wr++ = 0xFF; + } + + // Data Field + *wr++ = 0xD5; *wr++ = 0xAA; *wr++ = 0xAD; // Data Prolog D5 AA AD + + byte *nibbles = wr; + const unsigned ptr2 = 0; + const unsigned ptr6 = 0x56; + + for (int i = 0; i != 0x156; ++i) { + nibbles[i] = 0; + } + + int i2 = 0x55; + for (int i6 = 0x101; i6 >= 0; --i6) { + byte val6 = data[i6 % 0x100]; + byte val2 = nibbles[ptr2 + i2]; + + val2 = (val2 << 1) | (val6 & 1); + val6 >>= 1; + val2 = (val2 << 1) | (val6 & 1); + val6 >>= 1; + + nibbles[ptr6 + i6] = val6; + nibbles[ptr2 + i2] = val2; + + if (--i2 < 0) + i2 = 0x55; + } + + byte last = 0; + for (int i = 0; i != 0x156; ++i) { + const byte val = nibbles[i]; + nibbles[i] = TRANS62[last ^ val]; + last = val; + } + wr += 0x156; // advance write-pointer + *wr++ = TRANS62[last]; + + *wr++ = 0xDE; *wr++ = 0xAA; *wr++ = 0xEB; // Epilogue DE AA EB + + // Gap 3 + *wr++ = 0xFF; + + *nibSec = wr; +} + +static void explodeDsk(byte *nibbleBuf, byte *dskBuf, const byte *secmap) +{ + for (int t = 0; t < NUM_TRACKS; ++t) { + byte *writePtr = nibbleBuf; + for (int phys_sector = 0; phys_sector < MAX_SECTORS; ++phys_sector) { + const byte dos_sector = secmap[phys_sector]; + const size_t off = ((MAX_SECTORS * t + dos_sector) + * DSK_SECTOR_SIZE); + explodeSector(VOLUME_NUMBER, t, phys_sector, + &writePtr, &dskBuf[off]); + } + assert(writePtr - nibbleBuf <= NIBBLE_TRACK_SIZE); + for (; writePtr != (nibbleBuf + NIBBLE_TRACK_SIZE); ++writePtr) { + *writePtr = 0xFF; + } + nibbleBuf += NIBBLE_TRACK_SIZE; + } +} + +DiskFormatDesc dsk_insert(const char *path, byte *buf, size_t sz) +{ + if (sz != dsk_disksz) { + DIE(0,"Wrong disk image size for %s:\n", path); + DIE(1," Expected %zu, got %zu.\n", dsk_disksz, sz); + } + + struct dskprivdat *dat = malloc(sizeof *dat); + *dat = datinit; + dat->realbuf = buf; + dat->path = strdup(path); + dat->buf = calloc(1, nib_disksz); + + const char *ext = rindex(path, '.'); + ext = ext ? ext+1 : ""; + if (!strcasecmp(ext, "PO")) { + INFO("Opening %s as PO.\n", dat->path); + dat->secmap = PO; + } else { + INFO("Opening %s as DO.\n", dat->path); + dat->secmap = DO; + } + explodeDsk(dat->buf, dat->realbuf, dat->secmap); + + return (DiskFormatDesc){ + .privdat = dat, + .spin = spin, + .read_byte = read_byte, + .write_byte = write_byte, + .eject = eject, + }; +} diff --git a/src/format/empty.c b/src/format/empty.c new file mode 100644 index 0000000..6643fe3 --- /dev/null +++ b/src/format/empty.c @@ -0,0 +1,36 @@ +// format/empty.c +// +// Copyright (c) 2023 Micah John Cowan. +// This code is licensed under the MIT license. +// See the accompanying LICENSE file for details. + +#include "mii_disk_format.h" + + +#define byte uint8_t + +void spin(DiskFormatDesc *d, bool b) +{ +} + +byte read_byte(DiskFormatDesc *d) +{ + // A real disk can never send a low byte. + // But an empty disk must never send a legitimate byte. + return 0x00; +} + +void write_byte(DiskFormatDesc *d, byte b) +{ +} + +void eject(DiskFormatDesc *d) +{ +} + +DiskFormatDesc empty_disk_desc = { + .spin = spin, + .read_byte = read_byte, + .write_byte = write_byte, + .eject = eject, +}; diff --git a/src/format/mii_dd.c b/src/format/mii_dd.c new file mode 100644 index 0000000..41f4c9a --- /dev/null +++ b/src/format/mii_dd.c @@ -0,0 +1,399 @@ +/* + * mii_dd.c + * + * Copyright (C) 2023 Michel Pollet + * + * SPDX-License-Identifier: MIT + */ +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include + +#include "mii_bank.h" +#include "mii_dd.h" +#include "md5.h" + +#ifndef FCC +#define FCC(_a,_b,_c,_d) (((_a)<<24)|((_b)<<16)|((_c)<<8)|(_d)) +#endif + +int +mii_dd_overlay_load( + mii_dd_t * dd ); +int +mii_dd_overlay_prepare( + mii_dd_t * dd ); + + +void +mii_dd_system_init( + mii_dd_system_t *dd ) +{ + dd->drive = NULL; + dd->file = NULL; +} + +void +mii_dd_system_dispose( + mii_dd_system_t *dd ) +{ + while (dd->file) + mii_dd_file_dispose(dd, dd->file); + dd->file = NULL; + dd->drive = NULL; +} + +void +mii_dd_register_drives( + mii_dd_system_t *dd, + mii_dd_t * drives, + uint8_t count ) +{ + for (int i = 0; i < count; i++) { + mii_dd_t *d = &drives[i]; + d->dd = dd; + d->next = dd->drive; + dd->drive = d; + } +} + +void +mii_dd_file_dispose( + mii_dd_system_t *dd, + mii_dd_file_t *file ) +{ + // remove it from dd's file queue + if (dd->file == file) + dd->file = file->next; + else { + mii_dd_file_t *f = dd->file; + while (f) { + if (f->next == file) { + f->next = file->next; + break; + } + f = f->next; + } + } + if (file->dd) { + file->dd->file = NULL; + file->dd = NULL; + } + if (file->fd >= 0) { + close(file->fd); + file->fd = -1; + file->map = NULL; + } + if (file->map) { + free(file->map); + file->map = NULL; + } + if (file->pathname) { + free(file->pathname); + file->pathname = NULL; + } + free(file); +} + +int +mii_dd_drive_load( + mii_dd_t *dd, + mii_dd_file_t *file ) +{ + if (dd->file == file) + return 0; + if (dd->file) { + printf("%s: %s unloading %s\n", __func__, + dd->name, + dd->file->pathname); + mii_dd_file_dispose(dd->dd, dd->file); + dd->file = NULL; + } + if (!file) + return 0; + dd->file = file; + printf("%s: %s loading %s\n", __func__, + dd->name, file->pathname); + if (mii_dd_overlay_load(dd) < 0) { + printf("%s: No overlay to load, we're fine for now\n", __func__); + // no overlay.. what to do? + } + return 0; +} + +mii_dd_file_t * +mii_dd_file_load( + mii_dd_system_t *dd, + const char *pathname, + uint16_t flags) +{ + if (!flags) + flags = O_RDONLY; + int err; + int fd = open(pathname, flags); + if (fd < 0) { + perror(pathname); + return NULL; + } + struct stat st; + err = fstat(fd, &st); + if (err < 0) { + perror(pathname); + goto bail; + } + int protect = PROT_READ; + int mflags = MAP_PRIVATE; + if (flags & (O_RDWR | O_WRONLY)) { + protect |= PROT_WRITE; + mflags = MAP_SHARED; + } + uint8_t *buf = mmap(NULL, st.st_size, protect, mflags, fd, 0); + if (buf == NULL || buf == MAP_FAILED) { + perror(pathname); + // err = errno; + goto bail; + } + mii_dd_file_t * res = calloc(1, sizeof(*res)); + res->pathname = strdup(pathname); + res->fd = fd; + res->map = buf; + res->start = buf; + res->size = st.st_size; + res->dd = NULL; + res->next = dd->file; + dd->file = res; + char *suffix = strrchr(pathname, '.'); + if (suffix && !strcasecmp(suffix, ".2mg")) { + res->format = MII_DD_FILE_2MG; + res->map += 64; + } + return res; +bail: + close(fd); + return NULL; +} + +mii_dd_file_t * +mii_dd_file_in_ram( + mii_dd_system_t *dd, + const char *pathname, + uint32_t size, + uint16_t flags) +{ + mii_dd_file_t * res = calloc(1, sizeof(*res)); + res->pathname = strdup(pathname); + res->fd = -1; + res->map = calloc(1, size); + res->start = res->map; + res->size = size; + res->dd = NULL; + res->next = dd->file; + dd->file = res; + res->format = MII_DD_FILE_RAM; + return res; +} + +int +mii_dd_overlay_load( + mii_dd_t * dd ) +{ + if (dd->overlay.file) + return 0; + if (!dd->file) + return -1; + + char *filename = NULL; + char *suffix = strrchr(dd->file->pathname, '.'); + if (suffix) { + asprintf(&filename, "%.*s.miov", (int)(suffix - dd->file->pathname), dd->file->pathname); + } else { + asprintf(&filename, "%s.miov", dd->file->pathname); + } + int fd = open(filename, O_RDWR, 0666); + if (fd == -1) { + fprintf(stderr, "%s: overlay %s: %s\n", __func__, + filename, strerror(errno)); + free(filename); + return -1; + } + mii_dd_file_t * file = mii_dd_file_load(dd->dd, filename, O_RDWR); + close(fd); + if (!file) + return -1; + mii_dd_overlay_header_t * h = (mii_dd_overlay_header_t *)file->start; + + if (h->magic != FCC('M','I','O','V')) { + fprintf(stderr, "Overlay file %s has invalid magic\n", filename); + mii_dd_file_dispose(dd->dd, file); + return -1; + } + if (h->version != 1) { + fprintf(stderr, "Overlay file %s has invalid version\n", filename); + mii_dd_file_dispose(dd->dd, file); + return -1; + } + if (h->size != dd->file->size / 512) { + fprintf(stderr, "Overlay file %s has invalid size\n", filename); + mii_dd_file_dispose(dd->dd, file); + return -1; + } + + MD5_CTX d5 = {}; + MD5_Init(&d5); + MD5_Update(&d5, dd->file->start, dd->file->size); + uint8_t md5[16]; + MD5_Final(md5, &d5); + + if (memcmp(md5, h->src_md5, 16)) { + fprintf(stderr, "Overlay file %s has mismatched HASH!\n", filename); + mii_dd_file_dispose(dd->dd, file); + return -1; + } + uint32_t bitmap_size = (h->size + 63) / 64; + dd->overlay.file = file; + dd->overlay.file->map += sizeof(*h) + bitmap_size; + dd->overlay.header = (mii_dd_overlay_header_t *)dd->overlay.file->start; + dd->overlay.bitmap = (uint64_t*)(dd->overlay.file->start + sizeof(*h)); + dd->overlay.blocks = dd->overlay.file->map; + + return 0; +} + +int +mii_dd_overlay_prepare( + mii_dd_t * dd ) +{ + if (dd->overlay.file) + return 0; + if (!dd->file) + return -1; + printf("%s: %s Preparing Overlay file\n", __func__, dd->name); + uint32_t src_blocks = dd->file->size / 512; + uint32_t bitmap_size = (src_blocks + 63) / 64; + uint32_t blocks_size = src_blocks * 512; + uint32_t size = sizeof(mii_dd_overlay_header_t) + bitmap_size + blocks_size; + + char *filename = NULL; + char *suffix = strrchr(dd->file->pathname, '.'); + if (suffix) { + asprintf(&filename, "%.*s.miov", (int)(suffix - dd->file->pathname), dd->file->pathname); + } else { + asprintf(&filename, "%s.miov", dd->file->pathname); + } + int fd = open(filename, O_RDWR | O_CREAT | O_TRUNC, 0666); + if (fd == -1) { + fprintf(stderr, "%s: Failed to create overlay file %s: %s\n", __func__, + filename, strerror(errno)); + fprintf(stderr, "%s: Allocating a RAM one, lost on quit!\n", __func__); + dd->overlay.file = mii_dd_file_in_ram(dd->dd, filename, size, O_RDWR); + } else { + ftruncate(fd, size); + dd->overlay.file = mii_dd_file_load(dd->dd, filename, O_RDWR); + } + if (fd != -1) + close(fd); + free(filename); + mii_dd_overlay_header_t h = { + .magic = FCC('M','I','O','V'), + .version = 1, + .size = src_blocks, + }; + // hash the whole of the file, including header + MD5_CTX d5 = {}; + MD5_Init(&d5); + MD5_Update(&d5, dd->file->start, dd->file->size); + MD5_Final(h.src_md5, &d5); + *((mii_dd_overlay_header_t *)dd->overlay.file->start) = h; + dd->overlay.file->map += sizeof(h) + bitmap_size; + dd->overlay.header = (mii_dd_overlay_header_t *)dd->overlay.file->start; + dd->overlay.bitmap = (uint64_t*)(dd->overlay.file->start + sizeof(h)); + dd->overlay.blocks = dd->overlay.file->map; + return 0; +} + +int +mii_dd_read( + mii_dd_t * dd, + struct mii_bank_t *bank, + uint16_t addr, + uint32_t blk, + uint16_t blockcount) +{ + if (!dd || !dd->file || !dd->file->map) + return -1; + +// printf("%s: %s read %d blocks at %d\n", +// __func__, dd->name, blockcount, blk); + if (dd->overlay.file) { + uint64_t *bitmap = dd->overlay.bitmap; + for (int i = 0; i < blockcount; i++) { + uint32_t b = blk + i; +// printf(" overlay block %4d : %016llx\n", b, +// (unsigned long long)be64toh(bitmap[b/64])); + if (b >= dd->overlay.header->size) + break; + if (be64toh(bitmap[b / 64]) & (1ULL << (63 - (b & 63)))) { +// printf("%s: reading %4d from overlay\n", __func__, b); + mii_bank_write( bank, + addr + (i * 512), + dd->overlay.blocks + (b * 512), + 512); + } else { + mii_bank_write( bank, + addr + (i * 512), + dd->file->map + (b * 512), + 512); + } + } + } else { + mii_bank_write( + bank, + addr, dd->file->map + blk * 512, + blockcount * 512); + } + return 0; +} + +int +mii_dd_write( + mii_dd_t * dd, + struct mii_bank_t *bank, + uint16_t addr, + uint32_t blk, + uint16_t blockcount) +{ + if (!dd || !dd->file || !dd->file->map) + return -1; +// printf("%s: %s write %d blocks at %d\n", +// __func__, dd->name, blockcount, blk); + mii_dd_overlay_prepare(dd); + if (dd->overlay.file) { + uint64_t *bitmap = dd->overlay.bitmap; + for (int i = 0; i < blockcount; i++) { + uint32_t b = blk + i; + if (b >= dd->overlay.header->size) + break; + bitmap[b / 64] = htobe64( + be64toh(bitmap[b/64]) | (1ULL << (63 - (b & 63)))); +// printf("%s: writing %d to overlay map: %016llx\n", __func__, b, +// (unsigned long long)be64toh(bitmap[b/64])); + } + mii_bank_read( + bank, + addr, dd->overlay.blocks + blk * 512, + blockcount * 512); + } else { + mii_bank_read( + bank, + addr, dd->file->map + blk * 512, + blockcount * 512); + } + return 0; +} + diff --git a/src/format/mii_dd.h b/src/format/mii_dd.h new file mode 100644 index 0000000..dbaf828 --- /dev/null +++ b/src/format/mii_dd.h @@ -0,0 +1,124 @@ +/* + * mii_dd.h + * + * Copyright (C) 2023 Michel Pollet + * + * SPDX-License-Identifier: MIT + */ + +#pragma once + +#include + +struct mii_dd_t; + +enum { + MII_DD_FILE_OVERLAY = 1, + MII_DD_FILE_RAM, + MII_DD_FILE_2MG = 5, +}; + +// a disk image file (or chunck of ram, if ramdisk is used) +typedef struct mii_dd_file_t { + struct mii_dd_file_t *next; + char * pathname; + uint8_t format; + uint8_t * start; // start of the file + uint8_t * map; // start of the blocks + + int fd; // if fd >= 0, map is mmaped, otherwise it's malloced + uint32_t size; + struct mii_dd_t * dd; +} mii_dd_file_t; + +/* + * Overlays are made to provide what looks like read/write on files, but + * without commiting any of the changes to the real primary file, instead + * alld the changed blocks are kept into a sparse file and reloaded when + * the 'real' block is read. + * That way you can keep your disk images fresh and clean, while having + * multiple version of them if you like. + */ +typedef union mii_dd_overlay_header_t { + struct { + uint32_t magic; // 'MIOV' + uint32_t version; // 1 for now + uint32_t flags; // unused for now + uint32_t size; // size in blocks of original file + uint8_t src_md5[16]; // md5 of the SOURCE disk + }; + uint32_t raw[16]; +} mii_dd_overlay_header_t; + +typedef struct mii_dd_overlay_t { + mii_dd_overlay_header_t *header; // points to the file mapped in memory + uint64_t * bitmap; // usage bitmap + uint8_t * blocks; // raw block data + mii_dd_file_t *file; // overlay file mapping +} mii_dd_overlay_t; + +struct mii_slot_t; +struct mii_dd_system_t; + +// a disk drive, with a slot, a drive number, and a file +typedef struct mii_dd_t { + struct mii_dd_t *next; + struct mii_dd_system_t *dd; + const char * name; // ie "Disk ][ D:2" + uint8_t slot_id : 4, drive : 4; + struct mii_slot_t *slot; + unsigned int ro : 1, wp : 1, can_eject : 1; + mii_dd_file_t * file; + mii_dd_overlay_t overlay; +} mii_dd_t; + +typedef struct mii_dd_system_t { + mii_dd_t * drive; // list of all drives on all slots + mii_dd_file_t * file; // list of all open files (inc overlays) +} mii_dd_system_t; + +/* + * register drives with the system -- these are not allocated, they are + * statically defined in the driver code in their own structures + */ +void +mii_dd_register_drives( + mii_dd_system_t *dd, + mii_dd_t * drives, + uint8_t count ); +int +mii_dd_drive_load( + mii_dd_t *dd, + mii_dd_file_t *file ); + +/* + * unmap, close and dispose of 'file', clear it from the drive, if any + */ +void +mii_dd_file_dispose( + mii_dd_system_t *dd, + mii_dd_file_t *file ); +mii_dd_file_t * +mii_dd_file_load( + mii_dd_system_t *dd, + const char *filename, + uint16_t flags); + +struct mii_bank_t; +// read blocks from blk into bank's address 'addr' +int +mii_dd_read( + mii_dd_t * dd, + struct mii_bank_t *bank, + uint16_t addr, + uint32_t blk, + uint16_t blockcount); + +int +mii_dd_write( + mii_dd_t * dd, + struct mii_bank_t *bank, + uint16_t addr, + uint32_t blk, + uint16_t blockcount); + diff --git a/src/format/mii_disk_format.c b/src/format/mii_disk_format.c new file mode 100644 index 0000000..af99174 --- /dev/null +++ b/src/format/mii_disk_format.c @@ -0,0 +1,95 @@ +/* + * mii_disk_format.c + * + * Copyright (C) 2023 Michel Pollet + * + * SPDX-License-Identifier: MIT + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "mii_disk_format.h" + + +#define byte uint8_t + +static const size_t nib_disksz = 232960; +static const size_t dsk_disksz = 143360; + +extern DiskFormatDesc nib_insert(const char*, byte *, size_t); +extern DiskFormatDesc dsk_insert(const char *, byte *, size_t); +extern DiskFormatDesc empty_disk_desc; + +int mmapfile(const char *fname, byte **buf, size_t *sz, int flags); + +DiskFormatDesc disk_format_load(const char *path) +{ + if (path == NULL) { + return empty_disk_desc; + } + byte *buf; + size_t sz; + int err = mmapfile(path, &buf, &sz, O_RDWR); + if (buf == NULL) { + DIE(1,"Couldn't load/mmap disk %s: %s\n", + path, strerror(err)); + } + printf("%s loaded %s dz = %d\n", __func__, path, (int)sz); + if (sz == nib_disksz) { + return nib_insert(path, buf, sz); + } else if (sz == dsk_disksz) { + return dsk_insert(path, buf, sz); + } else { + DIE(2,"Unrecognized disk format for %s.\n", path); + } +} + +int mmapfile(const char *fname, byte **buf, size_t *sz, int flags) +{ + int err; + int fd; + + *buf = NULL; + + errno = 0; + fd = open(fname, flags); + if (fd < 0) { + return errno; + } + + struct stat st; + errno = 0; + err = fstat(fd, &st); + if (err < 0) { + goto bail; + } + + errno = 0; + int protect = PROT_READ; + int mflags = MAP_PRIVATE; + if (flags & O_RDWR || flags & O_WRONLY) { + protect |= PROT_WRITE; + mflags = MAP_SHARED; + } + *buf = mmap(NULL, st.st_size, protect, mflags, fd, 0); + if (*buf == NULL) { + err = errno; + goto bail; + } + close(fd); // safe to close now. + + *sz = st.st_size; + return 0; +bail: + close(fd); + return err; +} diff --git a/src/format/mii_disk_format.h b/src/format/mii_disk_format.h new file mode 100644 index 0000000..e157189 --- /dev/null +++ b/src/format/mii_disk_format.h @@ -0,0 +1,35 @@ +/* + * mii_disk_format.h + * + * Copyright (C) 2023 Michel Pollet + * + * SPDX-License-Identifier: MIT + */ +#pragma once + +#include +#include +#include + +/********** FORMATS **********/ +#define NUM_TRACKS 35 +#define SECTOR_SIZE 256 +typedef struct DiskFormatDesc DiskFormatDesc; +typedef struct DiskFormatDesc { + void *privdat; + bool writeprot; + unsigned int halftrack; + void (*spin)(DiskFormatDesc *, bool); + uint8_t (*read_byte)(DiskFormatDesc *); + void (*write_byte)(DiskFormatDesc *, uint8_t); + void (*eject)(DiskFormatDesc *); +} DiskFormatDesc; + +DiskFormatDesc disk_format_load(const char *path); + +#define WARN(...) fprintf(stderr, __VA_ARGS__) +#define INFO(...) fprintf(stderr, __VA_ARGS__) +#define DIE(code, ...) do { \ + WARN(__VA_ARGS__); \ + if (code) exit(code); \ + } while(0) diff --git a/src/format/nib.c b/src/format/nib.c new file mode 100644 index 0000000..d2be1db --- /dev/null +++ b/src/format/nib.c @@ -0,0 +1,100 @@ +// format/nib.c +// +// Copyright (c) 2023 Micah John Cowan. +// This code is licensed under the MIT license. +// See the accompanying LICENSE file for details. + +#include "mii_disk_format.h" + +#include +#include +#include +#include + +#define byte uint8_t + +#define NIBBLE_TRACK_SIZE 6656 +#define NIBBLE_SECTOR_SIZE 416 +#define MAX_SECTORS 16 + +struct nibprivdat { + const char *path; + byte *buf; + int bytenum; + uint64_t dirty_tracks; +}; +static const struct nibprivdat datinit = { 0 }; + +static const size_t nib_disksz = 232960; + +static void spin(DiskFormatDesc *desc, bool b) +{ + struct nibprivdat *dat = desc->privdat; + if (!b && dat->dirty_tracks != 0) { + // For now, sync the entire disk + errno = 0; + int err = msync(dat->buf, nib_disksz, MS_SYNC); + if (err < 0) { + DIE(1,"Couldn't sync to disk file %s: %s\n", + dat->path, strerror(errno)); + } + dat->dirty_tracks = 0; + } +} + +static byte read_byte(DiskFormatDesc *desc) +{ + struct nibprivdat *dat = desc->privdat; + size_t pos = (desc->halftrack/2) * NIBBLE_TRACK_SIZE; + pos += (dat->bytenum % NIBBLE_TRACK_SIZE); + byte val = dat->buf[pos]; + dat->bytenum = (dat->bytenum + 1) % NIBBLE_TRACK_SIZE; + return val; +} + +static void write_byte(DiskFormatDesc *desc, byte val) +{ + struct nibprivdat *dat = desc->privdat; + if ((val & 0x80) == 0) { + // D2DBG("dodged write $%02X", val); + return; // must have high bit + } + dat->dirty_tracks |= 1 << (desc->halftrack/2); + size_t pos = (desc->halftrack/2) * NIBBLE_TRACK_SIZE; + pos += (dat->bytenum % NIBBLE_TRACK_SIZE); + + //D2DBG("write byte $%02X at pos $%04zX", (unsigned int)val, pos); + + dat->buf[pos] = val; + dat->bytenum = (dat->bytenum + 1) % NIBBLE_TRACK_SIZE; +} + +static void eject(DiskFormatDesc *desc) +{ + // free dat->path and dat, and unmap disk image + struct nibprivdat *dat = desc->privdat; + (void) munmap(dat->buf, nib_disksz); + free((void*)dat->path); + free(dat); +} + +DiskFormatDesc nib_insert(const char *path, byte *buf, size_t sz) +{ + if (sz != nib_disksz) { + DIE(0,"Wrong disk image size for %s:\n", path); + DIE(1," Expected %zu, got %zu.\n", nib_disksz, sz); + } + + struct nibprivdat *dat = malloc(sizeof *dat); + *dat = datinit; + dat->buf = buf; + dat->path = strdup(path); + + return (DiskFormatDesc){ + .privdat = dat, + .spin = spin, + .read_byte = read_byte, + .write_byte = write_byte, + .eject = eject, + }; +} diff --git a/src/mii.c b/src/mii.c new file mode 100644 index 0000000..43e142c --- /dev/null +++ b/src/mii.c @@ -0,0 +1,714 @@ +/* + * mii.c + * + * Copyright (C) 2023 Michel Pollet + * + * SPDX-License-Identifier: MIT + */ + +#include +#include +#include +#include + +#include "mii_rom_iiee.h" +#include "mii.h" +#include "mii_bank.h" +#include "mii_video.h" +#include "mii_sw.h" +#include "mii_65c02.h" +#include "minipt.h" + + +mii_slot_drv_t * mii_slot_drv_list = NULL; + +static const mii_bank_t _mii_banks_init[MII_BANK_COUNT] = { + [MII_BANK_MAIN] = { + .name = "MAIN", + .base = 0x0000, + .size = 0xd0, // 208 pages, 48KB + }, + [MII_BANK_BSR] = { + .name = "BSR", + .base = 0xd000, + .size = 64, + }, + [MII_BANK_BSR_P2] = { + .name = "BSR P2", + .base = 0xd000, + .size = 16, + }, + [MII_BANK_AUX] = { + .name = "AUX", + .base = 0x0000, + .size = 0xd0, // 208 pages, 48KB + }, + [MII_BANK_AUX_BSR] = { + .name = "AUX BSR", + .base = 0xd000, + .size = 64, + }, + [MII_BANK_AUX_BSR_P2] = { + .name = "AUX BSR P2", + .base = 0xd000, + .size = 16, + }, + [MII_BANK_ROM] = { + .name = "ROM", + .base = 0xc000, + .size = 0x40, // 64 pages, 16KB + .ro = 1, + }, + [MII_BANK_CARD_ROM] = { + .name = "CARD ROM", + .base = 0xc100, + .size = 15, + .ro = 1, + }, +}; + + +#include "mii_65c02_ops.h" +#include "mii_65c02_disasm.h" + +void +mii_dump_trace_state( + mii_t *mii) +{ + mii_cpu_t * cpu = &mii->cpu; + mii_cpu_state_t s = mii->cpu_state; + printf("PC:%04X A:%02X X:%02X Y:%02X S:%02x #%d %c AD:%04X D:%02x %c ", + cpu->PC, cpu->A, cpu->X, cpu->Y, cpu->S, cpu->cycle, + s.sync ? 'I' : ' ', s.addr, s.data, s.w ? 'W' : 'R'); + // display the S flags + static const char *s_flags = "CZIDBRVN"; + for (int i = 0; i < 8; i++) + printf("%c", cpu->P.P[7-i] ? s_flags[7-i] : tolower(s_flags[7-i])); + if (s.sync) { + uint8_t op[16]; + for (int i = 0; i < 4; i++) { + mii_mem_access(mii, mii->cpu.PC + i, op + i, false, false); + } + mii_op_t d = mii_cpu_op[op[0]]; + printf(" "); + char dis[32]; + mii_cpu_disasm_one(op, cpu->PC, dis, sizeof(dis), + MII_DUMP_DIS_DUMP_HEX); + printf(": %s", dis); + if (d.desc.branch) { + if (cpu->P.P[d.desc.s_bit] == d.desc.s_bit_value) + printf(" ; taken"); + } + printf("\n"); + } else + printf("\n"); +} + +void +mii_dump_run_trace( + mii_t *mii) +{ + // walk all the previous PC values in mii->trace, and display a line + // of disassebly for all of them + for (int li = 0; li < MII_PC_LOG_SIZE; li++) { + int idx = (mii->trace.idx + li) & (MII_PC_LOG_SIZE - 1); + uint16_t pc = mii->trace.log[idx]; + uint8_t op[16]; + for (int i = 0; i < 4; i++) + mii_mem_access(mii, pc + i, op + i, false, false); +// mii_op_t d = mii_cpu_op[op[0]]; + char dis[64]; + mii_cpu_disasm_one(op, pc, dis, sizeof(dis), + MII_DUMP_DIS_PC | MII_DUMP_DIS_DUMP_HEX); + printf("%s\n", dis); + } +} + +#define _SAME 0xf + +static inline void +mii_page_set( + mii_t * mii, + uint8_t read, + uint8_t write, + uint8_t bank, + uint8_t end ) +{ + for (int i = bank; i <= end; i++) { + if (read != _SAME) + mii->mem[i].read = read; + if (write != _SAME) + mii->mem[i].write = write; + } +} + +static inline uint8_t +mii_sw( + mii_t *mii, + uint16_t sw) +{ + return mii_bank_peek(&mii->bank[MII_BANK_MAIN], sw); +} + +static void +mii_page_table_update( + mii_t *mii) +{ + if (!mii->mem_dirty) + return; + mii->mem_dirty = 0; + int altzp = mii_sw(mii, SWALTPZ); + int page2 = mii_sw(mii, SWPAGE2); + int store80 = mii_sw(mii, SW80STORE); + int hires = mii_sw(mii, SWHIRES); + int ramrd = mii_sw(mii, SWRAMRD); + int ramwrt = mii_sw(mii, SWRAMWRT); + int intcxrom = mii_sw(mii, SWINTCXROM); + int slotc3rom = mii_sw(mii, SWSLOTC3ROM); + + if (mii->trace_cpu) + printf("%04x: page table update altzp:%02x page2:%02x store80:%02x hires:%02x ramrd:%02x ramwrt:%02x intcxrom:%02x slotc3rom:%02x\n", + mii->cpu.PC, + altzp, page2, store80, hires, ramrd, ramwrt, intcxrom, slotc3rom); + // clean slate + mii_page_set(mii, MII_BANK_MAIN, MII_BANK_MAIN, 0x00, 0xc0); + mii_page_set(mii, MII_BANK_ROM, MII_BANK_ROM, 0xc1, 0xff); + if (altzp) + mii_page_set(mii, MII_BANK_AUX, MII_BANK_AUX, 0x00, 0x01); + mii_page_set(mii, + ramrd ? MII_BANK_AUX : MII_BANK_MAIN, + ramwrt ? MII_BANK_AUX : MII_BANK_MAIN, 0x02, 0xbf); + if (store80) { + mii_page_set(mii, + page2 ? MII_BANK_AUX : MII_BANK_MAIN, + page2 ? MII_BANK_AUX : MII_BANK_MAIN, 0x04, 0x07); + if (hires) + mii_page_set(mii, + page2 ? MII_BANK_AUX : MII_BANK_MAIN, + page2 ? MII_BANK_AUX : MII_BANK_MAIN, 0x20, 0x3f); + } + if (!intcxrom) + mii_page_set(mii, MII_BANK_CARD_ROM, _SAME, 0xc1, 0xc7); + mii_page_set(mii, + slotc3rom ? MII_BANK_CARD_ROM : MII_BANK_ROM, _SAME, 0xc3, 0xc3); + mii_page_set(mii, + mii->bsr_mode.read ? + altzp ? MII_BANK_AUX_BSR : MII_BANK_BSR : + MII_BANK_ROM, + mii->bsr_mode.write ? + altzp ? MII_BANK_AUX_BSR : MII_BANK_BSR : + MII_BANK_ROM, + 0xd0, 0xff); + // BSR P2 + mii_page_set(mii, + mii->bsr_mode.read ? + (altzp ? MII_BANK_AUX_BSR : MII_BANK_BSR) + + mii->bsr_mode.page2 : MII_BANK_ROM, + mii->bsr_mode.write ? + (altzp ? MII_BANK_AUX_BSR : MII_BANK_BSR) + + mii->bsr_mode.page2 : MII_BANK_ROM, + 0xd0, 0xdf); +} + +void +mii_set_sw_override( + mii_t *mii, + uint16_t sw_addr, + mii_bank_access_cb cb, + void *param) +{ + if (!mii->soft_switches_override) + mii->soft_switches_override = calloc(256, + sizeof(*mii->soft_switches_override)); + sw_addr &= 0xff; + mii->soft_switches_override[sw_addr].cb = cb; + mii->soft_switches_override[sw_addr].param = param; +} + +static bool +mii_access_soft_switches( + mii_t *mii, + uint16_t addr, + uint8_t * byte, + bool write) +{ + if (!(addr >= 0xc000 && addr <= 0xc0ff) || addr == 0xcfff) + return false; + bool res = false; + uint8_t on = 0; + mii_bank_t * main = &mii->bank[MII_BANK_MAIN]; + + /* + * This allows driver (titan accelerator etc) to have their own + * soft switches, and override/supplement any default ones. + */ + if (mii->soft_switches_override && mii->soft_switches_override[addr & 0xff].cb) { + res = mii->soft_switches_override[addr & 0xff].cb( + main, mii->soft_switches_override[addr & 0xff].param, + addr, byte, write); + if (res) + return res; + } + switch (addr) { + case 0xc090 ... 0xc0ff: { + res = true; + int slot = ((addr >> 4) & 7) - 1; +#if 0 + printf("SLOT %d addr %04x write %d %02x drv %s\n", + slot, addr, write, *byte, + mii->slot[slot].drv ? mii->slot[slot].drv->name : "none"); +#endif + if (mii->slot[slot].drv) { + on = mii->slot[slot].drv->access(mii, + &mii->slot[slot], addr, *byte, write); + if (!write) + *byte = on; + } + } break; + case 0xc080 ... 0xc08f: { + res = true; + uint8_t mode = addr & 0x0f; + static const int write_modes[4] = { 0, 1, 0, 1, }; + static const int read_modes[4] = { 1, 0, 0, 1, }; + uint8_t rd = read_modes[mode & 3]; + uint8_t wr = write_modes[mode & 3]; + mii->bsr_mode.write = wr; + mii->bsr_mode.read = rd; + mii->bsr_mode.page2 = mode & 0x08 ? 0 : 1; + mii->mem_dirty = 1; + if (mii->trace_cpu) + printf("%04x: BSR mode addr %04x:%02x read:%s write:%s %s altzp:%02x\n", + mii->cpu.PC, addr, + mode, + rd ? "BSR" : "ROM", + wr ? "BSR" : "ROM", + mii->bsr_mode.page2 ? "page2" : "page1", + mii_sw(mii, SWALTPZ)); + } break; + case 0xcfff: + res = true; + mii->mem_dirty = 1; + printf("%s TODO reset SLOT roms\n", __func__); + break; + case SWPAGE2OFF: + case SWPAGE2ON: + res = true; + mii_bank_poke(main, SWPAGE2, (addr & 1) << 7); + mii->mem_dirty = 1; + break; + case SWHIRESOFF: + case SWHIRESON: + res = true; + mii_bank_poke(main, SWHIRES, (addr & 1) << 7); + mii->mem_dirty = 1; + // printf("HIRES %s\n", (addr & 1) ? "ON" : "OFF"); + break; + case SWSPEAKER: + res = true; + mii_speaker_click(&mii->speaker); + break; + case 0xc068: + res = true; + // IIgs register, read by prodos tho + break; + } + if (res && !mii->mem_dirty) + return res; + if (write) { + switch (addr) { + case SW80STOREOFF: + case SW80STOREON: + res = true; + mii_bank_poke(main, SW80STORE, (addr & 1) << 7); + mii->mem_dirty = 1; + break; + case SWRAMRDOFF: + case SWRAMRDON: + res = true; + mii_bank_poke(main, SWRAMRD, (addr & 1) << 7); + mii->mem_dirty = 1; + break; + case SWRAMWRTOFF: + case SWRAMWRTON: + res = true; + mii_bank_poke(main, SWRAMWRT, (addr & 1) << 7); + mii->mem_dirty = 1; + break; + case SWALTPZOFF: + case SWALTPZON: + res = true; + mii_bank_poke(main, SWALTPZ, (addr & 1) << 7); + mii->mem_dirty = 1; + break; + case SWINTCXROMOFF: + case SWINTCXROMON: + res = true; + mii_bank_poke(main, SWINTCXROM, (addr & 1) << 7); + mii->mem_dirty = 1; + break; + case SWSLOTC3ROMOFF: + case SWSLOTC3ROMON: + res = true; + mii_bank_poke(main, SWSLOTC3ROM, (addr & 1) << 7); + mii->mem_dirty = 1; + break; + } + } else { + switch (addr) { + case SWBSRBANK2: + *byte = mii->bsr_mode.page2 ? 0x80 : 0; + res = true; + break; + case SWBSRREADRAM: + *byte = mii->bsr_mode.read ? 0x80 : 0; + res = true; + break; + case SWRAMRD: + case SWRAMWRT: + case SW80STORE: + case SWINTCXROM: + case SWALTPZ: + case SWSLOTC3ROM: + res = true; + *byte = mii_bank_peek(main, addr); + break; + case 0xc020: // toggle TAPE output ?!?! + case 0xc064: // Analog Input 0 (paddle 0) + case 0xc065: // Analog Input 1 (paddle 1) + case 0xc079: // Analog Input Reset + res = true; + break; + case 0xc068: + res = true; + // IIgs register, read by prodos tho + break; + } + } + if (!res) { + // printf("%s addr %04x write %d %02x\n", __func__, addr, write, *byte); + // mii->state = MII_STOPPED; + } + mii_page_table_update(mii); + return res; +} + +static bool +mii_access_keyboard( + mii_t *mii, + uint16_t addr, + uint8_t * byte, + bool write) +{ + bool res = false; + mii_bank_t * main = &mii->bank[MII_BANK_MAIN]; + switch (addr) { + case SWKBD: + if (!write) { + /* If fifo not empty, peek at the next key to process, it already + * has the 0x80 bit on -- otherwise, return 0 */ + res = true; + #if 1 + *byte = mii_bank_peek(main, SWKBD); + #else + if (mii_key_fifo_isempty(&mii->keys)) + *byte = 0; + else + *byte = mii_key_fifo_read_at(&mii->keys, 0).key; + #endif + } + break; + case SWAKD: + res = true; +#if 1 + { + uint8_t r = mii_bank_peek(main, SWAKD); + if (!write) + *byte = r; + r &= 0x7f; + mii_bank_poke(main, SWAKD, r); + mii_bank_poke(main, SWKBD, r); + } +#else + // if (write) { + /* clear latch, and replace it immediately with the new key + * if there's one in the FIFO */ + if (!mii_key_fifo_isempty(&mii->keys)) { + mii_key_t k = mii_key_fifo_read(&mii->keys); + mii_bank_poke(main, SWAKD, k.key); + } else + mii_bank_poke(main, SWAKD, + mii_bank_peek(main, SWAKD) & ~0x80); + // } else + if (!write) + *byte = mii_bank_peek(main, SWAKD); +#endif + break; + case 0xc061 ... 0xc063: // Push Button 0, 1, 2 (Apple Keys) + res = true; + if (!write) + *byte = mii_bank_peek(main, addr); + break; + } + return res; +} + +void +mii_keypress( + mii_t *mii, + uint8_t key) +{ + mii_bank_t * main = &mii->bank[MII_BANK_MAIN]; + key |= 0x80; + mii_bank_poke(main, SWAKD, key); + mii_bank_poke(main, SWKBD, key); +#if 0 + mii_key_t k = { + .key = key | 0x80, + }; + if (!mii_key_fifo_isfull(&mii->keys)) + mii_key_fifo_write(&mii->keys, k); + else { + printf("%s key fifo full\n", __func__); + } +#endif +} + + +void +mii_init( + mii_t *mii ) +{ + memset(mii, 0, sizeof(*mii)); + mii->speed = 1.0; + for (int i = 0; i < MII_BANK_COUNT; i++) + mii->bank[i] = _mii_banks_init[i]; + mii->bank[MII_BANK_ROM].mem = (uint8_t*)&iie_enhanced_rom_bin[0]; + mii->cpu.trap = MII_TRAP; + mii_reset(mii, true); + mii_speaker_init(mii, &mii->speaker); + mii->cpu_state = mii_cpu_init(&mii->cpu); + for (int i = 0; i < 7; i++) + mii->slot[i].id = i; +} + +void +mii_prepare( + mii_t *mii, + uint32_t flags ) +{ + printf("%s driver table\n", __func__); + mii_slot_drv_t * drv = mii_slot_drv_list; + while (drv) { + printf("%s driver: %s\n", __func__, drv->name); + if (drv->probe && drv->probe(mii, flags)) { + printf("%s %s probe done\n", __func__, drv->name); + } + drv = drv->next; + } +} + +void +mii_reset( + mii_t *mii, + bool cold) +{ +// printf("%s cold %d\n", __func__, cold); + mii->cpu_state.reset = 1; + mii->bsr_mode.write = 1; + mii->bsr_mode.read = 0; + mii->bsr_mode.page2 = 1; + mii_bank_t * main = &mii->bank[MII_BANK_MAIN]; + mii_bank_poke(main, SWSLOTC3ROM, 0); + mii_bank_poke(main, SWRAMRD, 0); + mii_bank_poke(main, SWRAMWRT, 0); + mii_bank_poke(main, SWALTPZ, 0); + mii_bank_poke(main, SW80STORE, 0); + mii_bank_poke(main, SW80COL, 0); + mii->mem_dirty = 1; + if (cold) { + /* these HAS to be reset in that state somehow */ + mii_bank_poke(main, SWINTCXROM, 0); + uint8_t z[2] = {0x55,0x55}; + mii_bank_write(main, 0x3f2, z, 2); + } + mii->mem_dirty = 1; + mii_page_table_update(mii); + for (int i = 0; i < 7; i++) { + if (mii->slot[i].drv && mii->slot[i].drv->reset) + mii->slot[i].drv->reset(mii, &mii->slot[i]); + } +} + +void +mii_mem_access( + mii_t *mii, + uint16_t addr, + uint8_t * d, + bool wr, + bool do_sw) +{ + if (!do_sw && addr >= 0xc000 && addr <= 0xc0ff) + return; + uint8_t done = + mii_access_keyboard(mii, addr, d, wr) || + mii_access_video(mii, addr, d, wr) || + mii_access_soft_switches(mii, addr, d, wr); + if (!done) { + uint8_t page = addr >> 8; + if (wr) { + uint8_t m = mii->mem[page].write; + mii_bank_t * b = &mii->bank[m]; + if (b->ro) { + // printf("%s write to RO bank %s %04x:%02x\n", + // __func__, b->name, addr, *d); + } else + mii_bank_write(b, addr, d, 1); + } else { + uint8_t m = mii->mem[page].read; + mii_bank_t * b = &mii->bank[m]; + *d = mii_bank_peek(b, addr); + } + } +} + +static void +_mii_handle_trap( + mii_t *mii) +{ +// printf("%s TRAP hit PC: %04x\n", __func__, mii->cpu.PC); + mii->cpu_state.sync = 1; + mii->cpu_state.trap = 0; + mii->cpu.state = NULL; + uint8_t trap = mii_read_one(mii, mii->cpu.PC); + mii->cpu.PC += 1; +// printf("%s TRAP %02x return PC %04x\n", __func__, trap, mii->cpu.PC); + if (mii->trap.map & (1 << trap)) { + if (mii->trap.trap[trap].cb) + mii->trap.trap[trap].cb(mii, trap); + } else { + printf("%s TRAP %02x not handled\n", __func__, trap); + mii->state = MII_STOPPED; + } +// mii->state = MII_STOPPED; +} + +uint8_t +mii_register_trap( + mii_t *mii, + mii_trap_handler_cb cb) +{ + if (mii->trap.map == 0xffff) { + printf("%s no more traps!!\n", __func__); + return 0xff; + } + for (int i = 0; i < (int)sizeof(mii->trap.map) * 8; i++) { + if (!(mii->trap.map & (1 << i))) { + mii->trap.map |= 1 << i; + mii->trap.trap[i].cb = cb; + return i; + } + } + return 0xff; +} + +void +mii_run( + mii_t *mii) +{ + /* this runs all cycles for one instruction */ + do { + if (mii->trace_cpu) + mii_dump_trace_state(mii); + mii->cpu_state = mii_cpu_run(&mii->cpu, mii->cpu_state); + mii_video_run(mii); + mii_speaker_run(&mii->speaker); + // extract 16-bit address from pin mask + const uint16_t addr = mii->cpu_state.addr; + const uint8_t data = mii->cpu_state.data; + int wr = mii->cpu_state.w; + uint8_t d = data; + if (mii->debug.bp_map) { + for (int i = 0; i < (int)sizeof(mii->debug.bp_map) * 8; i++) { + if (!(mii->debug.bp_map & (1 << i))) + continue; + if (addr >= mii->debug.bp[i].addr && + addr < mii->debug.bp[i].addr + mii->debug.bp[i].size) { + if (((mii->debug.bp[i].kind & MII_BP_R) && !wr) || + ((mii->debug.bp[i].kind & MII_BP_W) && wr)) { + + if (1 || !mii->debug.bp[i].silent) { + printf("BREAKPOINT %d at %04x PC:%04x\n", + i, addr, mii->cpu.PC); + mii_dump_run_trace(mii); + mii_dump_trace_state(mii); + mii->state = MII_STOPPED; + } + } + if (!(mii->debug.bp[i].kind & MII_BP_STICKY)) + mii->debug.bp_map &= ~(1 << i); + mii->debug.bp[i].kind |= MII_BP_HIT; + } + } + } + mii_mem_access(mii, addr, &d, wr, true); + if (!wr) + mii->cpu_state.data = d; + if (mii->cpu_state.trap) { + _mii_handle_trap(mii); + } + } while (!(mii->cpu_state.sync)); + mii->cycles += mii->cpu.cycle; + // log PC for the running disassembler display + mii->trace.log[mii->trace.idx] = mii->cpu.PC; + mii->trace.idx = (mii->trace.idx + 1) & (MII_PC_LOG_SIZE - 1); + for (int i = 0; i < 7; i++) { + if (mii->slot[i].drv && mii->slot[i].drv->run) + mii->slot[i].drv->run(mii, &mii->slot[i]); + } +} + +//! Read one byte from and addres, using the current memory mapping +uint8_t +mii_read_one( + mii_t *mii, + uint16_t addr) +{ + uint8_t d = 0; + mii_mem_access(mii, addr, &d, 0, false); + return d; +} +//! Read a word from addr, using current memory mapping (little endian) +uint16_t +mii_read_word( + mii_t *mii, + uint16_t addr) +{ + uint8_t d = 0; + uint16_t res = 0; + mii_mem_access(mii, addr, &d, 0, false); + res = d; + mii_mem_access(mii, addr + 1, &d, 0, false); + res |= d << 8; + return res; +} +/* same accessors, for write + */ +void +mii_write_one( + mii_t *mii, + uint16_t addr, + uint8_t d) +{ + mii_mem_access(mii, addr, &d, 1, false); +} +void +mii_write_word( + mii_t *mii, + uint16_t addr, + uint16_t w) +{ + uint8_t d = w; + mii_mem_access(mii, addr, &d, 1, false); + d = w >> 8; + mii_mem_access(mii, addr + 1, &d, 1, false); +} diff --git a/src/mii.h b/src/mii.h new file mode 100644 index 0000000..b403a05 --- /dev/null +++ b/src/mii.h @@ -0,0 +1,274 @@ +/* + * mii.h + * + * Copyright (C) 2023 Michel Pollet + * + * SPDX-License-Identifier: MIT + */ +#pragma once + +#include +#include + +#include "mii_65c02.h" +#include "fifo_declare.h" +#include "mii_dd.h" +#include "mii_bank.h" +#include "mii_slot.h" +#include "mii_video.h" +#include "mii_speaker.h" +#include "mii_mouse.h" + +enum { + MII_BANK_MAIN = 0, // main 48K address space + MII_BANK_BSR, // 0xd000 - 0xffff bank switched RAM 16KB + MII_BANK_BSR_P2, // 0xd000 - 0xe000 bank switched RAM aux 4KB + + MII_BANK_AUX, // aux 48K address space (80 cols card) + MII_BANK_AUX_BSR, // 0xd000 - 0xffff bank switched RAM aux 16KB + MII_BANK_AUX_BSR_P2, // 0xd000 - 0xe000 bank switched RAM aux 4KB (aux bank) + + MII_BANK_ROM, // 0xc000 - 0xffff 16K ROM + MII_BANK_CARD_ROM, // 0xc100 - 0xcfff Card ROM access + MII_BANK_COUNT, +}; + + +typedef void (*mii_trap_handler_cb)( + mii_t * mii, + uint8_t trap); +typedef struct mii_trap_t { + uint16_t map; + struct { + mii_trap_handler_cb cb; + } trap[16]; +} mii_trap_t; + +// state of the emulator +enum { + MII_RUNNING = 0, // default + MII_STOPPED, + MII_STEP, +}; + +enum { + MII_BP_PC = (1 << 0), // breakpoint on PC + MII_BP_W = (1 << 1), // breakpoint on write + MII_BP_R = (1 << 2), // breakpoint on read + MII_BP_HIT = (1 << 3), // breakpoint was hit + MII_BP_SILENT = (1 << 4), // don't dump state (used for the 'next' command) + MII_BP_STICKY = (1 << 7), // breakpoint is sticky (rearms itself) +}; + +#define MII_PC_LOG_SIZE 16 + +/* + * this keeps track of the last few PC values, for the debugger + */ +typedef struct mii_trace_t { + uint16_t log[MII_PC_LOG_SIZE]; + uint8_t idx; + // when in MII_STEP, do not fall back to MII_STOPPED until these + // run out + uint32_t step_inst; +} mii_trace_t; + +/* + * principal emulator state, for a faceless emulation + */ +typedef struct mii_t { + unsigned int state; + __uint128_t cycles; + /* this is the video frame/VBL rate vs 60hz, default to 1.0 */ + float speed; + float speed_current; // calculated speed + mii_cpu_t cpu; + mii_cpu_state_t cpu_state; + /* + * bank index for each memory page number, this is recalculated + * everytime a soft switch is triggered + */ + struct { + uint8_t read : 4, write : 4; + } mem[256]; + int mem_dirty; // recalculate mem[] on next access + struct { + int write, read, page2; + } bsr_mode; + + mii_trace_t trace; + int trace_cpu; + mii_trap_t trap; + /* + * Used for debugging only + */ + struct { + uint16_t bp_map; + struct { + uint32_t kind : 8, + addr : 16, + size : 8, + silent : 1; + } bp[16]; + } debug; + mii_bank_t bank[MII_BANK_COUNT]; + // the page c000 can have individual callbacks to override/supplement + // existing default behaviour. This is currently used for the titan + // accelerator 'card' + mii_bank_access_t * soft_switches_override; + mii_slot_t slot[7]; + mii_video_t video; + mii_speaker_t speaker; + mii_mouse_t mouse; + mii_dd_system_t dd; +} mii_t; + +enum { + MII_INIT_NSC = (1 << 0), // Install no slot clock + MII_INIT_TITAN = (1 << 1), // Install Titan 'card' + MII_INIT_DEFAULT = MII_INIT_NSC, +}; + +/* + * Call this first, to initialize the emulator state + * This doesn't initializes any driver. + */ +void +mii_init( + mii_t *mii ); + +/* + * Call this to prepare the emulator, instantiate and install drivers + * etc. Presumably after you have used mii_argv_parse or loaded a config + * file to set up the drivers. + * flags is a combination of MII_INIT_* + */ +void +mii_prepare( + mii_t *mii, + uint32_t flags ); + +/* + * Parses arguments until in finds one that isn't for mii, and returns + * the index of that argument in *index. + * Return value is 0 if there's an argument that wasn't handled or 1 + * if all the arguments were parsed (and *index == argc) + * mii parameter is the state AFTER mii_init() has been called. + * + * ioFlags is a combination of MII_INIT_*, it will be updated with the + * flags found in the arguments. Pass this to mii_prepare() + */ +int +mii_argv_parse( + mii_t *mii, + int argc, + const char *argv[], + int *index, + uint32_t *ioFlags ); +/* + * Locate driver_name, and attempt to register it with slot_id slot. + * Returns 0 on success, -1 on failure + */ +int +mii_slot_drv_register( + mii_t *mii, + uint8_t slot_id, + const char *driver_name); +/* returns the driver registered for slot slot_id (or NULL) */ +mii_slot_drv_t * +mii_slot_drv_get( + mii_t *mii, + uint8_t slot_id); + +/* + * Reset the emulator, cold reset if cold is true, otherwise warm reset + */ +void +mii_reset( + mii_t *mii, + bool cold); +/* Execute one instruction, respecting breakpoints, runs the video code, + * Check for traps and other associated debug stuff. + */ +void +mii_run( + mii_t *mii); +// this one is thread safe, there's a FIFO behind it. +void +mii_keypress( + mii_t *mii, + uint8_t key); + +/* read a byte as the processor would (ex softwitches!), this will + * respect the status of slot ROMs, language card, 80 columns etc */ +uint8_t +mii_read_one( + mii_t *mii, + uint16_t addr); +/* write a byte as the processor would (ex softwitches!), this will + * respect the status of slot ROMs, language card, 80 columns etc */ +void +mii_write_one( + mii_t *mii, + uint16_t addr, + uint8_t d); +/* read a word as the processor would (ex softwitches!), this will + * respect the status of slot ROMs, language card, 80 columns etc */ +uint16_t +mii_read_word( + mii_t *mii, + uint16_t addr); +/* write a word as the processor would (ex softwitches!), this will + * respect the status of slot ROMs, language card, 80 columns etc */ +void +mii_write_word( + mii_t *mii, + uint16_t addr, + uint16_t w); + +/* lower level call to access memory -- this one can trigger softswitches + * if specified. Otherwise behaves as the previous ones, one byte at a time + */ +void +mii_mem_access( + mii_t *mii, + uint16_t addr, + uint8_t * byte, + bool write, + bool do_sw); +/* register a callback to call when a specific soft switches is hit, + * this allows overriding/supplementing/tracing access to sw. + */ +void +mii_set_sw_override( + mii_t *mii, + uint16_t sw_addr, + mii_bank_access_cb cb, + void *param); + +void +mii_dump_trace_state( + mii_t *mii); +void +mii_dump_run_trace( + mii_t *mii); + +extern mii_slot_drv_t * mii_slot_drv_list; + +#define MI_DRIVER_REGISTER(_mii_driver)\ + __attribute__((constructor,unused)) \ + static void _mii_register_##_mii_driver() { \ + _mii_driver.next = mii_slot_drv_list; \ + mii_slot_drv_list = &_mii_driver; \ + } + +#define MII_TRAP 0xdbfb +/* + * Request a trap ID for the given callback. Calling code is responsible + * for setting up the trap using the 2 magic NOPs in sequence. See mii_smartport.c + * for an example. + */ +uint8_t +mii_register_trap( + mii_t *mii, + mii_trap_handler_cb cb); diff --git a/src/mii_65c02.c b/src/mii_65c02.c new file mode 100644 index 0000000..53a9cff --- /dev/null +++ b/src/mii_65c02.c @@ -0,0 +1,581 @@ + +#include +#include +#include + +#include "minipt.h" +#include "mii_65c02.h" +#define MII_CPU_65C02_IMPL +#include "mii_65c02_ops.h" + +mii_cpu_state_t +mii_cpu_init( + mii_cpu_t *cpu ) +{ + mii_cpu_state_t s = { + .addr = 0, + .reset = 1, + }; + cpu->state = NULL; + return s; +} + +#define _FETCH(_val) { \ + s.addr = _val; s.w = 0; cpu->cycle++; \ + pt_yield(cpu->state); \ + } while (0); +#define _STORE(_addr, _val) { \ + s.addr = _addr; s.data = _val; s.w = 1; cpu->cycle++; \ + pt_yield(cpu->state); \ + } while (0); + +#define _SET_P(_byte) { \ + for (int _pi = 0; _pi < 8; _pi++) \ + cpu->P.P[_pi] = _pi == B_B || _pi == B_X || \ + ((_byte) & (1 << _pi)); \ + } +#define _NZC(_val) { \ + uint16_t v = (_val); \ + cpu->P.N = !!(v & 0x80); \ + cpu->P.Z = (v & 0xff) == 0; \ + cpu->P.C = !!(v & 0xff00); \ + } while (0) +#define _NZ(_val) { \ + uint16_t v = (_val); \ + cpu->P.N = !!(v & 0x80); \ + cpu->P.Z = (v & 0xff) == 0; \ + } while (0) +#define _C(_val) { \ + cpu->P.C = !!(_val); \ + } while (0) + +mii_cpu_state_t +mii_cpu_run( + mii_cpu_t *cpu, + mii_cpu_state_t s) +{ + mii_op_desc_t d = mii_cpu_op[cpu->IR].desc; + pt_start(cpu->state); +next_instruction: + if (s.reset) { + s.reset = 0; + _FETCH(0xfffc); cpu->_P = s.data; + _FETCH(0xfffd); cpu->_P |= s.data << 8; + cpu->PC = cpu->_P; + cpu->S = 0xFF; + _SET_P(0); + } + if (s.irq) { + s.irq = 0; + cpu->P.P[B_B] = cpu->IRQ == 2; + cpu->IRQ = 1; + cpu->_D = cpu->PC + 1; + _STORE(0x0100 | cpu->S--, cpu->_D >> 8); + _STORE(0x0100 | cpu->S--, cpu->_D & 0xff); + uint8_t p = 0; + for (int i = 0; i < 8; i++) + p |= (i == B_X || cpu->P.P[i]) << i; + _STORE(0x0100 | cpu->S--, p); + cpu->P.P[B_I] = 1; + } + if (cpu->IRQ) { + cpu->IRQ = 0; + _FETCH(0xfffe); cpu->_P = s.data; + _FETCH(0xffff); cpu->_P |= s.data << 8; + cpu->PC = cpu->_P; + } + s.sync = 1; + // we dont' reset the cycle here, that way calling code has a way of knowing + // how many cycles were used by the previous instruction + _FETCH(cpu->PC); + s.sync = 0; + cpu->cycle = 0; + cpu->PC++; + cpu->IR = s.data; + d = mii_cpu_op[cpu->IR].desc; + cpu->ir_log = (cpu->ir_log << 8) | cpu->IR; + s.trap = cpu->trap && (cpu->ir_log & 0xffff) == cpu->trap; + if (s.trap) + cpu->ir_log = 0; + switch (d.mode) { + case IMM: + _FETCH(cpu->PC++); cpu->_D = s.data; + break; + case BRANCH: // BEQ/BNE etc + case ZP_REL: // $(xx) + _FETCH(cpu->PC++); cpu->_P = s.data; + break; + case ZP_X: // $xx,X + _FETCH(cpu->PC++); cpu->_P = (s.data + cpu->X) & 0xff; + break; + case ZP_Y: // $xx,Y + _FETCH(cpu->PC++); cpu->_P = (s.data + cpu->Y) & 0xff; + break; + case ABS: { // $xxxx + _FETCH(cpu->PC++); cpu->_P = s.data; + _FETCH(cpu->PC++); cpu->_P |= s.data << 8; + } break; + case ABS_X: { // $xxxx,X + _FETCH(cpu->PC++); cpu->_P = s.data; + _FETCH(cpu->PC++); cpu->_P |= s.data << 8; + cpu->_P += cpu->X; + if ((cpu->_P & 0xff00) != (s.data << 8)) + cpu->cycle++; + } break; + case ABS_Y: { // $xxxx,Y + _FETCH(cpu->PC++); cpu->_P = s.data; + _FETCH(cpu->PC++); cpu->_P |= s.data << 8; + cpu->_P += cpu->Y; + if ((cpu->_P & 0xff00) != (s.data << 8)) + cpu->cycle++; + } break; + case IND_X: { // ($xx,X) + _FETCH(cpu->PC++); cpu->_D = s.data; + cpu->_D += cpu->X; + _FETCH(cpu->_D & 0xff); cpu->_P = s.data; + cpu->_D++; + _FETCH(cpu->_D & 0xff); cpu->_P |= s.data << 8; + } break; + case IND_Y: { // ($xx),Y + _FETCH(cpu->PC++); cpu->_D = s.data; + _FETCH(cpu->_D); cpu->_P = s.data; + _FETCH((cpu->_D + 1) & 0xff); + cpu->_P |= s.data << 8; + cpu->_P += cpu->Y; + } break; + case IND: { // ($xxxx) + _FETCH(cpu->PC++); cpu->_D = s.data; + _FETCH(cpu->PC++); cpu->_D |= s.data << 8; + _FETCH(cpu->_D); cpu->_P = s.data; + _FETCH(cpu->_D + 1); cpu->_P |= s.data << 8; + } break; + case IND_Z: { // ($xx) + _FETCH(cpu->PC++); cpu->_D = s.data; + _FETCH(cpu->_D); cpu->_P = s.data; + _FETCH(cpu->_D + 1); cpu->_P |= s.data << 8; + } break; + case IND_AX: { // ($xxxx,X) + _FETCH(cpu->PC++); cpu->_D = s.data; + _FETCH(cpu->PC++); cpu->_D |= s.data << 8; + cpu->_D += cpu->X; + if ((cpu->_D & 0xff00) != (s.data << 8)) + cpu->cycle++; + _FETCH(cpu->_D); cpu->_P = s.data; + _FETCH(cpu->_D + 1); cpu->_P |= s.data << 8; + } break; + } + if (d.r) { + _FETCH(cpu->_P); + cpu->_D = s.data; + } + switch (cpu->IR) { + case 0x69: case 0x65: case 0x75: case 0x6D: case 0x7D: + case 0x79: case 0x61: case 0x71: case 0x72: + { // ADC + // Handle adding in BCD with bit D + if (cpu->P.D) { + uint8_t lo = (cpu->A & 0x0f) + (cpu->_D & 0x0f) + !!cpu->P.C; + if (lo > 9) lo += 6; + uint8_t hi = (cpu->A >> 4) + (cpu->_D >> 4) + (lo > 0x0f); + cpu->P.Z = ((uint8_t)(cpu->A + cpu->_D + cpu->P.C)) == 0; + // that is 6502 behaviour +// cpu->P.N = !!(hi & 0xf8); + cpu->P.V = !!((!((cpu->A ^ cpu->_D) & 0x80) && + ((cpu->A ^ (hi << 4))) & 0x80)); + if (hi > 9) hi += 6; + cpu->P.C = hi > 15; + cpu->A = (hi << 4) | (lo & 0x0f); + // THAT is 65c02 behaviour + cpu->P.N = !!(cpu->A & 0x80); + } else { + uint16_t sum = cpu->A + cpu->_D + !!cpu->P.C; + cpu->P.V = cpu->P.C = 0; + if (~(cpu->A ^ cpu->_D) & (cpu->A ^ sum) & 0x80) + cpu->P.V = 1; + _NZC(sum); + cpu->A = sum; + } + } break; + case 0x29: case 0x25: case 0x35: case 0x2D: case 0x3D: + case 0x39: case 0x21: case 0x31: case 0x32: + { // AND + cpu->A &= cpu->_D; + _NZ(cpu->A); + } break; + case 0x0A: + { // ASL + cpu->P.C = !!(cpu->A & 0x80); + cpu->A <<= 1; + _NZ(cpu->A); + } break; + case 0x06: case 0x16: case 0x0E: case 0x1E: + { // ASL + cpu->P.C = !!(cpu->_D & 0x80); + cpu->_D <<= 1; + _NZ(cpu->_D); + } break; + case 0x0f: case 0x1f: case 0x2f: case 0x3f: case 0x4f: + case 0x5f: case 0x6f: case 0x7f: case 0x8f: case 0x9f: + case 0xaf: case 0xbf: case 0xcf: case 0xdf: case 0xef: + case 0xff: + { // BBR/BBS + _FETCH(cpu->PC++); // relative branch + if (((cpu->_D >> d.s_bit) & 1) == d.s_bit_value) { + cpu->_P = cpu->PC + (int8_t)cpu->_P; + if ((cpu->_P & 0xff00) != (cpu->PC & 0xff00)) + cpu->cycle++; + cpu->PC = cpu->_P; + cpu->cycle++; + } + } break; + case 0x90: case 0xB0: case 0xF0: case 0x30: + case 0xD0: case 0x10: case 0x50: case 0x70: + { // BCC, BCS, BEQ, BMI, BNE, BPL, BVC, BVS + if (d.s_bit_value == cpu->P.P[d.s_bit]) { + cpu->_P = cpu->PC + (int8_t)cpu->_P; + if ((cpu->_P & 0xff00) != (cpu->PC & 0xff00)) + cpu->cycle++; + cpu->PC = cpu->_P; + cpu->cycle++; + } + } break; + case 0x80: + { // BRA + cpu->PC = cpu->PC + (int8_t)cpu->_P; cpu->cycle++; + } break; + case 0x89: + { // BIT immediate -- does not change N & V! + cpu->P.Z = !(cpu->A & cpu->_D); + } break; + case 0x24: case 0x2C: case 0x34: case 0x3C: + { // BIT + cpu->P.Z = !(cpu->A & cpu->_D); + cpu->P.N = !!(cpu->_D & 0x80); + cpu->P.V = !!(cpu->_D & 0x40); + } break; + case 0x00: + { // BRK + s.irq = 1; + cpu->IRQ = 2; // IRQ interrupt + // cpu->P.P[B_D] = 0; // 65c02 clears this + } break; + case 0x18: case 0xD8: case 0x58: case 0xB8: + { // CLC, CLD, CLI, CLV + cpu->P.P[d.s_bit] = 0; + } break; + case 0xC9: case 0xC5: case 0xD5: case 0xCD: case 0xDD: + case 0xD9: case 0xC1: case 0xD1: case 0xD2: + { // CMP + cpu->P.C = !!(cpu->A >= cpu->_D); + uint8_t d = cpu->A - cpu->_D; + _NZ(d); + } break; + case 0xE0: case 0xE4: case 0xEC: + { // CPX + cpu->P.C = !!(cpu->X >= cpu->_D); + uint8_t d = cpu->X - cpu->_D; + _NZ(d); + } break; + case 0xC0: case 0xC4: case 0xCC: + { // CPY + cpu->P.C = !!(cpu->Y >= cpu->_D); + uint8_t d = cpu->Y - cpu->_D; + _NZ(d); + } break; + case 0x3A: + { // DEC + _NZ(--cpu->A); + } break; + case 0xC6: case 0xD6: case 0xCE: case 0xDE: + { // DEC + _NZ(--cpu->_D); + } break; + case 0xCA: + { // DEX + _NZ(--cpu->X); + } break; + case 0x88: + { // DEY + _NZ(--cpu->Y); + } break; + case 0x49: case 0x45: case 0x55: case 0x4D: case 0x5D: + case 0x59: case 0x41: case 0x51: case 0x52: + { // EOR + cpu->A ^= cpu->_D; + _NZ(cpu->A); + } break; + case 0x1A: + { // INC + _NZ(++cpu->A); + } break; + case 0xE6: case 0xF6: case 0xEE: case 0xFE: + { // INC + _NZ(++cpu->_D); + } break; + case 0xE8: + { // INX + _NZ(++cpu->X); + } break; + case 0xC8: + { // INY + _NZ(++cpu->Y); + } break; + case 0x4C: case 0x6C: case 0x7C: + { // JMP + cpu->PC = cpu->_P; + } break; + case 0x20: + { // JSR + cpu->_D = cpu->PC - 1; + _STORE(0x0100 | cpu->S--, cpu->_D >> 8); + _STORE(0x0100 | cpu->S--, cpu->_D & 0xff); + cpu->PC = cpu->_P; + } break; + case 0xA9: case 0xA5: case 0xB5: case 0xAD: case 0xBD: + case 0xB9: case 0xA1: case 0xB1: case 0xB2: + { // LDA + cpu->A = cpu->_D; + _NZ(cpu->A); + } break; + case 0xA2: case 0xA6: case 0xB6: case 0xAE: case 0xBE: + { // LDX + cpu->X = cpu->_D; + _NZ(cpu->X); + } break; + case 0xA0: case 0xA4: case 0xB4: case 0xAC: case 0xBC: + { // LDY + cpu->Y = cpu->_D; + _NZ(cpu->Y); + } break; + case 0x4A: + { // LSR + cpu->P.C = !!(cpu->A & 0x01); + cpu->A >>= 1; + _NZ(cpu->A); + } break; + case 0x46: case 0x56: case 0x4E: case 0x5E: + { // LSR + cpu->P.C = !!(cpu->_D & 0x01); + cpu->_D >>= 1; + _NZ(cpu->_D); + } break; + case 0xEA: + { // NOP + } break; + case 0x09: case 0x05: case 0x15: case 0x0D: case 0x1D: + case 0x19: case 0x01: case 0x11: case 0x12: + { // ORA + cpu->A |= cpu->_D; + _NZ(cpu->A); + } break; + case 0x48: + { // PHA + _STORE(0x0100 | cpu->S--, cpu->A); cpu->cycle++; + } break; + case 0x08: + { // PHP + uint8_t p = 0; + for (int i = 0; i < 8; i++) + p |= (i == B_X || cpu->P.P[i]) << i; + p |= (1 << B_B); + _STORE(0x0100 | cpu->S--, p); cpu->cycle++; + } break; + case 0xDA: + { // PHX + _STORE(0x0100 | cpu->S--, cpu->X);cpu->cycle++; + } break; + case 0x5A: + { // PHY + _STORE(0x0100 | cpu->S--, cpu->Y);cpu->cycle++; + } break; + case 0x68: + { // PLA + _FETCH(0x0100 | ++cpu->S);cpu->cycle++; + cpu->A = s.data;cpu->cycle++; + _NZ(cpu->A); + } break; + case 0x28: + { // PLP + _FETCH(0x0100 | ++cpu->S);cpu->cycle++; + _SET_P(s.data);cpu->cycle++; + } break; + case 0xFA: + { // PLX + _FETCH(0x0100 | ++cpu->S); + cpu->X = s.data; + _NZ(cpu->X); + } break; + case 0x7A: + { // PLY + _FETCH(0x0100 | ++cpu->S); + cpu->Y = s.data; + _NZ(cpu->Y); + } break; + case 0x2A: + { // ROL + uint8_t c = cpu->P.C; + cpu->P.C = !!(cpu->A & 0x80); + cpu->A <<= 1; + cpu->A |= c; + _NZ(cpu->A); + } break; + case 0x26: case 0x36: case 0x2E: case 0x3E: + { // ROL + uint8_t c = cpu->P.C; + cpu->P.C = !!(cpu->_D & 0x80); + cpu->_D <<= 1; + cpu->_D |= c; + _NZ(cpu->_D); + } break; + case 0x6A: + { // ROR + uint8_t c = cpu->P.C; + cpu->P.C = !!(cpu->A & 0x01); + cpu->A >>= 1; + cpu->A |= c << 7; + _NZ(cpu->A); + } break; + case 0x66: case 0x76: case 0x6E: case 0x7E: + { // ROR + uint8_t c = cpu->P.C; + cpu->P.C = !!(cpu->_D & 0x01); + cpu->_D >>= 1; + cpu->_D |= c << 7; + _NZ(cpu->_D); + } break; + case 0x40: + { // RTI + _FETCH(0x0100 | ((++cpu->S) & 0xff)); + for (int i = 0; i < 8; i++) + cpu->P.P[i] = i == B_B || (s.data & (1 << i)); + cpu->P._R = 1; + _FETCH(0x0100 | ((++cpu->S) & 0xff)); + cpu->_P = s.data; + _FETCH(0x0100 | ((++cpu->S) & 0xff)); + cpu->_P = (s.data << 8) | (cpu->_P ); + cpu->PC = cpu->_P; + } break; + case 0x60: + { // RTS + _FETCH(0x0100 | ((++cpu->S) & 0xff));cpu->cycle++; + cpu->_P = s.data; + _FETCH(0x0100 | ((++cpu->S) & 0xff));cpu->cycle++; + cpu->_P |= s.data << 8; + cpu->PC = cpu->_P + 1; cpu->cycle++; + } break; + case 0xE9: case 0xE5: case 0xF5: case 0xED: case 0xFD: + case 0xF9: case 0xE1: case 0xF1: case 0xF2: + { // SBC + // Handle subbing in BCD with bit D + if (cpu->P.D) { + uint8_t lo = (cpu->A & 0x0f) - (cpu->_D & 0x0f) - !cpu->P.C; + if (lo & 0x10) lo -= 6; + uint8_t hi = (cpu->A >> 4) - (cpu->_D >> 4) - (lo & 0x10); + if (hi & 0x10) hi -= 6; + cpu->P.Z = ((uint8_t)(cpu->A - cpu->_D - !cpu->P.C)) == 0; + cpu->P.N = !!(hi & 0x8); + cpu->P.V = !!(((cpu->A ^ cpu->_D) & + ((cpu->A ^ (hi << 4))) & 0x80)); + cpu->P.C = !(hi & 0x10); + cpu->A = (hi << 4) | (lo & 0x0f); + } else { + cpu->_D = (~cpu->_D) & 0xff; + uint16_t sum = cpu->A + cpu->_D + !!cpu->P.C; + cpu->P.V = cpu->P.C = 0; + if (~(cpu->A ^ cpu->_D) & (cpu->A ^ sum) & 0x80) + cpu->P.V = 1; + _NZC(sum); + cpu->A = sum; + } + } break; + case 0x38: case 0xF8: case 0x78: + { // SEC, SED, SEI + cpu->P.P[d.s_bit] = 1; + } break; + case 0x85: case 0x95: case 0x8D: case 0x9D: + case 0x99: case 0x81: case 0x91: case 0x92: + { // STA + cpu->_D = cpu->A; + } break; + case 0x86: case 0x96: case 0x8E: + { // STX + cpu->_D = cpu->X; + } break; + case 0x84: case 0x94: case 0x8C: + { // STY + cpu->_D = cpu->Y; + } break; + case 0x64: case 0x74: case 0x9C: case 0x9E: + { // STZ + cpu->_D = 0; + } break; + case 0x14: case 0x1c: + { // TRB + cpu->P.Z = !(cpu->A & cpu->_D); + cpu->_D &= ~cpu->A; + } break; + case 0x04: case 0x0c: + { // TSB + cpu->P.Z = !(cpu->A & cpu->_D); + cpu->_D |= cpu->A; + } break; + case 0xAA: + { // TAX + cpu->X = cpu->A; + _NZ(cpu->X); + } break; + case 0xA8: + { // TAY + cpu->Y = cpu->A; + _NZ(cpu->Y); + } break; + case 0xBA: + { // TSX + cpu->X = cpu->S; + _NZ(cpu->X); + } break; + case 0x8A: + { // TXA + cpu->A = cpu->X; + _NZ(cpu->A); + } break; + case 0x9A: + { // TXS + cpu->S = cpu->X; + } break; + case 0x98: + { // TYA + cpu->A = cpu->Y; + _NZ(cpu->A); + } break; + case 0x07: case 0x17: case 0x27: case 0x37: case 0x47: + case 0x57: case 0x67: case 0x77: case 0x87: case 0x97: + case 0xA7: case 0xB7: case 0xC7: case 0xD7: case 0xE7: + case 0xF7: + { // RMB/SMB + cpu->_D = (cpu->_D & ~(1 << d.s_bit)) | (d.s_bit_value << d.s_bit); + } break; + /* Apparently these NOPs use 3 bytes, according to the tests */ + case 0x5c: case 0xdc: case 0xfc: + _FETCH(cpu->PC++); + /* Apparently these NOPs use 2 bytes, according to the tests */ + case 0x02: case 0x22: case 0x42: case 0x62: case 0x82: + case 0xC2: case 0xE2: case 0x44: case 0x54: case 0xD4: + case 0xF4: + _FETCH(cpu->PC++); // consume that byte + break; + case 0xdb: case 0xfb: + // trap NOPs + break; + default: + printf("%04x %02x UNKNOWN INSTRUCTION\n", cpu->PC, cpu->IR); + // exit(1); + break; + } + if (d.w) { + _STORE(cpu->_P, cpu->_D); + } + goto next_instruction; + pt_end(cpu->state); + return s; +} diff --git a/src/mii_65c02.h b/src/mii_65c02.h new file mode 100644 index 0000000..7d370b7 --- /dev/null +++ b/src/mii_65c02.h @@ -0,0 +1,88 @@ +#pragma once + +#include + +/* + * State structure used to 'talk' to the CPU emulator. + * It works like this: + * mii_cpu_state_t s = { .reset = 1 }; + * do { + * s = mii_cpu_run(cpu, s); + * if (s.w) + * write_memory(s.addr, s.data); + * else + * s.data = read_memory(s.addr); + * } while (1); + * s.sync will be 1 when we are fetching a new instruction + * s.reset will be 1 when the CPU is in reset (fetching vector) + * will turn to zero when done + * You check then the cpu->cycle to know what cycle you're in the current + * instruction. + * + * If you want to 'jump' to a new PC, you need to + * s.addr = new_pc; + * s.sync = 1; + * this will stop the current instruction and start fetching at new_pc + * + */ +typedef union mii_cpu_state_t { + struct { + uint32_t addr : 16, + data : 8, + w : 1, + sync : 1, + reset : 1, + irq : 1, + nmi : 1, + trap : 1; + }; + uint32_t raw; +} mii_cpu_state_t; + +/* CPU state machine */ +typedef struct mii_cpu_t { + uint8_t A, X, Y, S; + /* internal 16bit registers for fetch etc + * _D is the 'data' register, used for 16bit operations + * _P is the 'pointer' register, used for 16bit addressing + * This is not set hard in stone, but typically addressing modes that + * are 'indirect' and load from memory will set _P and read in _D + * so the opcode doesn't have to handle s.data at all */ + uint16_t _D, _P; + /* My experience with simavr shows that maintaining a 8 bits bitfield + * for a status register is a lot slower than having discrete flags + * and 'constructing' the matching 8 biots register when needed */ + union { + struct { + uint8_t C, Z, I, D, B, _R, V, N; + }; + uint8_t P[8]; + } P; + uint16_t PC; + uint8_t IR; + uint8_t IRQ; // IRQ (0) or NMI (1) or BRK (2) + uint8_t cycle; // for current instruction + /* State of the CPU state machine */ + void * state; + + /* sequence of instruction that will trigger a trap flag. + * this is used to trigger 'call backs' to the main code + * typically use a pair of NOPs sequence that is unlikely to exist in + * real code. */ + uint16_t trap; + // last 4 instructions, as a shift register, used for traps or debug + uint32_t ir_log; + + /* Debug only; the callback is called every cycles, with the current + * state of the cpu. */ + uint8_t * ram; // DEBUG +} mii_cpu_t; + +mii_cpu_state_t +mii_cpu_init( + mii_cpu_t *cpu ); + +mii_cpu_state_t +mii_cpu_run( + mii_cpu_t *cpu, + mii_cpu_state_t s); diff --git a/src/mii_65c02_asm.c b/src/mii_65c02_asm.c new file mode 100644 index 0000000..c31cf61 --- /dev/null +++ b/src/mii_65c02_asm.c @@ -0,0 +1,503 @@ +/* + * mii_65c02_asm.c + * + * Copyright (C) 2023 Michel Pollet + * + * SPDX-License-Identifier: MIT + */ + +#include +#include +#include +#include + +#include "mii_65c02.h" +#include "mii_65c02_ops.h" +#include "mii_65c02_asm.h" + +static char * +_mii_extract_token( + char *position, + char *dst, + int dst_len) +{ + if (!position) + return NULL; + while (*position == ' ' || *position == '\t') + position++; + char *kw = strsep(&position, " \t"); + if (kw) + strncpy(dst, kw, dst_len); + return position; +} + + +static char * +_mii_extract_name( + char *src, + char *dst, + int dst_len) +{ + char *end = src; + while (isalnum(*end) || *end == '_') + *dst++ = *end++; + *dst = 0; + return end; +} + +static char * +_mii_extract_value_or_name( + mii_cpu_asm_line_t *l, + char *src) +{ + static const char * const hex = "0123456789abcdef"; + char *end = src; + l->op_value = 0; + if (*end == '<') { + l->op_low = 1; + end++; + } else if (*end == '>') { + l->op_high = 1; + end++; + } + if (*end == '$') { + end++; + while (isxdigit(*end)) + l->op_value = (l->op_value << 4) + + (strchr(hex, tolower(*end++)) - hex); + } else if (isdigit(*end)) { + while (isdigit(*end)) + l->op_value = (l->op_value << 4) + + (strchr(hex, tolower(*end++)) - hex); + } else { + end = _mii_extract_name(end, l->op_name, sizeof(l->op_name)); + l->label_resolved = 0; + } + return end; +} + +static int +_mii_resolve_symbol( + mii_cpu_asm_program_t *p, + mii_cpu_asm_line_t *l, + int optional) +{ + if (!l->op_name[0] || l->label_resolved) + return 1; + mii_cpu_asm_line_t *l2 = p->sym; + while (l2) { + if (!strcasecmp(l->op_name, l2->label)) { + l->op_value = l2->op_value; + l->label_resolved = 1; + goto found; + } + l2 = l2->sym_next; + } + if (!optional) + printf("%s symbol %s not found\n", __func__, l->op_name); + return 0; +found: + if (l->op_low) + l->op_value &= 0xff; + else if (l->op_high) + l->op_value >>= 8; + return 1; +} + +void +mii_cpu_asm_load( + mii_cpu_asm_program_t *p, + const char *prog) +{ + const char *current = prog; + int line_count = 0; + do { + const char *lend = strchr(current, '\n'); + int len = lend ? (int)(lend - current) : (int)strlen(current); + + mii_cpu_asm_line_t *l = calloc(1, sizeof(mii_cpu_asm_line_t) + len + 1); + l->line_index = line_count++; + sprintf(l->line, "%.*s", len, current); + if (p->prog_tail) { + p->prog_tail->next = l; + p->prog_tail = l; + } else { + p->prog = p->prog_tail = l; + } + char *dup = strdup(l->line); + char * comment = strrchr(dup, ';'); + if (comment) + *comment = 0; + if (!*dup) { + goto next_line; + } + char * position = dup; + if (position[0] != ' ' && position[0] != '\t') { + char *start = position; + char *kw = strsep(&position, " \t="); + if (kw) { + // strip spaces + char *ke = kw + strlen(kw); + while (ke > start && (ke[-1] <= ' ' || ke[-1] == ':')) + *--ke = 0; + strncpy(l->label, kw, sizeof(l->label)-1); + } + } + position = _mii_extract_token(position, l->mnemonic, sizeof(l->mnemonic)); + + if (!strcmp(l->mnemonic, ".db") || !strcmp(l->mnemonic, "byte")) { + /* remaining of the line is comma separated hex values OR symbols + * that can be resolved immediately */ + char *kw = position; + while (*kw == ' ' || *kw == '\t') kw++; + char *cur = kw; + while ((cur = strsep(&kw, ",")) != NULL) { + while (*cur == ' ' || *cur == '\t') cur++; + char *ke = cur + strlen(cur); + while (ke > cur && (ke[-1] <= ' ' || ke[-1] == ':')) + *--ke = 0; + if (!*cur) + break; + _mii_extract_value_or_name(l, cur); + if (_mii_resolve_symbol(p, l, 0) == 0) + printf("ERROR -- sorry code symbols don't work, just EQUs\n"); + else + l->opcodes[l->opcode_count++] = l->op_value; + } + goto next_line; + } + position = _mii_extract_token(position, l->operand, sizeof(l->operand)); + if (l->operand[0] == '.' || l->operand[0] == '=') { + // a directive that has been not aligned on the first line, re-adjust + snprintf(l->label, sizeof(l->label), "%s", l->mnemonic); + snprintf(l->mnemonic, sizeof(l->mnemonic), "%s", l->operand); + position = _mii_extract_token(position, l->operand, sizeof(l->operand)); + } + if (l->mnemonic[0] == '=' || + !strcasecmp(l->mnemonic, "equ") || + !strcasecmp(l->mnemonic, ".equ")) { + l->symbol = 1; + if (p->sym_tail) + p->sym_tail->sym_next = l; + else + p->sym = l; + _mii_extract_value_or_name(l, l->operand); + if (_mii_resolve_symbol(p, l, 0) == 0) + printf("ERROR -- sorry code symbols don't work, just EQUs\n"); + } + // printf(">L:%s M:%s O:%s\n", l->label, l->mnemonic, l->operand); +next_line: + free(dup); + current = lend ? lend+1 : NULL; + } while (current); + +} + + +static int +mii_cpu_opcode_has_mode( + const char *mnemonic, + int mode) +{ + for (int i = 0; i < 256; i++) { + if (!strncasecmp(mnemonic, mii_cpu_op[i].name, 4)) { + if (mode == mii_cpu_op[i].desc.mode) { + return i; + } + } + } + return -1; +} + +static int +_mii_cpu_asm_parse_operand( + mii_cpu_asm_program_t *p, + mii_cpu_asm_line_t *l) +{ + l->mode = IMPLIED; + if (!l->operand[0]) + return 0; + + char sep = 0; // (parenthesis) + char *src = l->operand; + switch (*src) { + case '#': + l->mode = IMM; + src = _mii_extract_value_or_name(l, src + 1); + break; + case '$': + l->mode = ABS; + src = _mii_extract_value_or_name(l, src); + break; + case '(': + l->mode = IND; + sep = ')'; + src = _mii_extract_value_or_name(l, src + 1); + break; + default: { + l->mode = ABS; + src = _mii_extract_value_or_name(l, src); + _mii_resolve_symbol(p, l, 1); + } break; + } + while (*src == ' ' || *src == '\t') src++; + switch (*src) { + case ',': + src++; + while (*src == ' ' || *src == '\t') src++; + switch (tolower(*src)) { + case 'x': + l->mode = ABS_X; + if (sep) { + // special case for JMP ($xxxx,x) + if (!strcasecmp(l->mnemonic, "JMP")) + l->mode = IND_AX; + else + l->mode = IND_X; + break; + } + break; + case 'y': + l->mode = ABS_Y; + break; + default: + l->mode = ABS; + break; + } + break; + case ')': + src++; + switch (*src) { + case ',': + src++; + while (*src == ' ' || *src == '\t') src++; + switch (tolower(*src)) { + case 'x': + l->mode = IND_X; + break; + default: + l->mode = IND_Y; + break; + } + break; + default: + l->mode = IND; + break; + } + break; + } + switch (l->mode) { + case ABS: { + if (l->op_value < 0x100) { + int newo = mii_cpu_opcode_has_mode(l->mnemonic, ZP_REL); + if (newo != -1) { + l->mode = ZP_REL; + l->opcodes[0] = mii_cpu_op[newo].desc.op; + l->opcode_count = mii_cpu_op[newo].desc.pc; + } + } + } break; + case ABS_X: { + if (l->op_value < 0x100) { + int newo = mii_cpu_opcode_has_mode(l->mnemonic, ZP_X); + if (newo != -1) { + l->mode = ZP_X; + l->opcodes[0] = mii_cpu_op[newo].desc.op; + l->opcode_count = mii_cpu_op[newo].desc.pc; + } + } + } break; + case ABS_Y: { + if (l->op_value < 0x100) { + int newo = mii_cpu_opcode_has_mode(l->mnemonic, ZP_Y); + if (newo != -1) { + l->mode = ZP_Y; + l->opcodes[0] = mii_cpu_op[newo].desc.op; + l->opcode_count = mii_cpu_op[newo].desc.pc; + } + } + } break; + case IND: if (1) { + if (l->op_value < 0x100) { + // printf("Testing if IND opcode %s can be IND_Z operand %s (%04x)\n", + // l->mnemonic, l->operand, l->op_value); + int newo = mii_cpu_opcode_has_mode(l->mnemonic, IND_Z); + if (newo != -1) { + // printf("YES replace %02x with %02x\n", + // l->opcodes[0], newo); + l->mode = IND_Z; + l->opcodes[0] = mii_cpu_op[newo].desc.op; + l->opcode_count = mii_cpu_op[newo].desc.pc; + } + } + } break; + } + return 0; +} + +int +mii_cpu_asm_assemble( + mii_cpu_asm_program_t *p ) +{ + mii_cpu_asm_line_t *l = p->prog; + int error = 0; + + // fix symbols + l = p->sym; + while (l) { + _mii_extract_value_or_name(l, l->operand); + // printf("SYM %s = %04x\n", l->label, l->op_value); + l = l->sym_next; + } + l = p->prog; + while (l) { + if (!l->mnemonic[0] || l->symbol) { + l = l->next; + continue; + } + l->mode = IMPLIED; + _mii_cpu_asm_parse_operand(p, l); + if (!strcasecmp(l->mnemonic, ".org")) { + if (p->verbose) + printf("%s origin set to $%04x\n", __func__, l->op_value); + if (l->mode == ABS) { + if (!p->org) + p->org = l->op_value; + l->addr_set = 1; + l->addr = l->op_value; + } + l = l->next; + continue; + } else if (!strcasecmp(l->mnemonic, ".verbose")) { + p->verbose = 1; + l = l->next; + continue; + } else if (l->mnemonic[0] == '.') { + l = l->next; + continue; + } + int found = -1; + for (int i = 0; i < 256; i++) { + if (!strncasecmp(l->mnemonic, mii_cpu_op[i].name, 4)) { + if (mii_cpu_op[i].desc.branch) { + l->mode = mii_cpu_op[i].desc.mode; + found = i; + break; + } else if (l->mode == mii_cpu_op[i].desc.mode) { + found = i; + break; + } + } + } + if (found == -1) { + printf("ERROR: %d: %s %s %s\n", + l->line_index, l->label, l->mnemonic, l->operand); + printf(" Missing opcode for %s %d\n", l->mnemonic, l->mode); + error = 1; + break; + } + // printf("FOUND %02x for '%s' '%s' '%s' name:'%s'\n", + // found, l->label, l->mnemonic, l->operand, l->op_name); + l->opcodes[0] = mii_cpu_op[found].desc.op; + l->opcode_count = mii_cpu_op[found].desc.pc; + l = l->next; + } + if (error) + return error; + uint16_t pc = p->org; + /* + * We (should) know all instruction size by now, so lets sets + * the addresses for all the lines + */ + l = p->prog; + while (l) { + if (l->addr_set) + pc = l->addr; + else + l->addr = pc; + if (l->mnemonic[0] != '.') { + // this sets the ones we know about, and clears the ones we dont + for (int i = 1; i < l->opcode_count; i++) + l->opcodes[i] = l->op_value >> (8 * (i - 1)); + } + pc += l->opcode_count; + l = l->next; + } + /* + * Now resolve all the operand labels + */ + l = p->prog; + while (l) { + if (l->op_name[0] && !l->label_resolved) { + mii_cpu_asm_line_t *l2 = p->prog; + while (l2) { + int32_t value = 0; + if (!strcasecmp(l->op_name, l2->label)) { + value = l2->op_value; + if (!l2->symbol) + value = l2->addr; + else + value = l2->op_value; + l->op_value = value; + l->label_resolved = 1; + if (mii_cpu_op[l->opcodes[0]].desc.branch) + l->op_value = l2->addr - l->addr - 2; + else if (l->op_low) + l->op_value &= 0xff; + else if (l->op_high) + l->op_value >>= 8; + for (int i = 1; i < l->opcode_count; i++) + l->opcodes[i] = l->op_value >> (8 * (i - 1)); + break; + } + l2 = l2->next; + } + if (!l->label_resolved) { + printf("ERROR: Missing label %d: %s %s %s\n", + l->line_index, l->label, l->mnemonic, l->operand); + error = 1; + break; + } + } + l = l->next; + } + if (error) + return error; + p->output_len = p->prog_tail->addr + p->prog_tail->opcode_count - p->org; + if (p->verbose) + printf("%s program at $%04x size %d bytes\n", __func__, + p->org, p->output_len); + p->output = calloc(1, p->output_len); + l = p->prog; + while (l) { + for (int i = 0; i < l->opcode_count; i++) + p->output[l->addr - p->org + i] = l->opcodes[i]; + l = l->next; + } + return error; +} + +int +mii_cpu_asm( + mii_cpu_asm_program_t *p, + const char *prog) +{ + mii_cpu_asm_load(p, prog); + + return mii_cpu_asm_assemble(p); +} + +void +mii_cpu_asm_free( + mii_cpu_asm_program_t *p) +{ + mii_cpu_asm_line_t *l = p->prog; + while (l) { + mii_cpu_asm_line_t *next = l->next; + free(l); + l = next; + } + if (p->output) + free(p->output); + memset(p, 0, sizeof(*p)); +} diff --git a/src/mii_65c02_asm.h b/src/mii_65c02_asm.h new file mode 100644 index 0000000..72b7dec --- /dev/null +++ b/src/mii_65c02_asm.h @@ -0,0 +1,47 @@ +#pragma once + +#include + + +typedef struct mii_cpu_asm_line_t { + struct mii_cpu_asm_line_t *next; + struct mii_cpu_asm_line_t *sym_next; + uint16_t line_index; + uint8_t symbol : 1, + label_resolved : 1, + addr_set : 1, op_low : 1, op_high : 1; + uint16_t addr; // address of the instruction (if resolved) + uint8_t mode; // mode of the instruction + uint8_t opcode_count; // number of bytes for the opcode + uint8_t opcodes[32]; // or .byte statements + + char label[64]; + char mnemonic[64]; + char operand[64]; + + char op_name[64]; + int op_value; + + char line[]; // actual line read ends up here, untouched +} mii_cpu_asm_line_t; + +typedef struct mii_cpu_asm_program_t { + uint8_t verbose; + uint16_t org; // origin, can be set before, or with .org + mii_cpu_asm_line_t *sym; + mii_cpu_asm_line_t *sym_tail; + + mii_cpu_asm_line_t *prog; + mii_cpu_asm_line_t *prog_tail; + + uint8_t * output; + uint16_t output_len; +} mii_cpu_asm_program_t; + +int +mii_cpu_asm( + mii_cpu_asm_program_t *p, + const char *prog); +void +mii_cpu_asm_free( + mii_cpu_asm_program_t *p); diff --git a/src/mii_65c02_disasm.c b/src/mii_65c02_disasm.c new file mode 100644 index 0000000..703c70f --- /dev/null +++ b/src/mii_65c02_disasm.c @@ -0,0 +1,124 @@ + +#include +#include +#include +#include "mii_65c02.h" +#include "mii_65c02_ops.h" +#include "mii_65c02_disasm.h" + +int +mii_cpu_disasm_one( + const uint8_t *prog, + uint16_t addr, + char *out, + size_t out_len, + uint16_t flags) +{ + uint16_t pc = addr; + int i = 0; + + uint8_t op = prog[i]; + mii_op_desc_t d = mii_cpu_op[op].desc; + if (!d.pc) + d.pc = 1; + *out = 0; + int len = out_len; + if (flags & MII_DUMP_DIS_PC) + len -= snprintf(out + strlen(out), len, "%04X: ", pc + i); + if (flags & MII_DUMP_DIS_DUMP_HEX) { + char hex[32] = {0}; + for (int oi = 0; oi < d.pc; oi++) + sprintf(hex + (oi * 3), "%02X ", prog[i + oi]); + len -= snprintf(out + strlen(out), len, "%-9s ", hex); + } + len -= snprintf(out + strlen(out), len, "%.4s ", + mii_cpu_op[op].name[0] ? + mii_cpu_op[op].name : "???"); + i++; + switch (d.mode) { + case IMM: + len -= snprintf(out + strlen(out), len, + "#$%02X", prog[i++]); + break; + case BRANCH: + case ZP_REL: + if ((op & 0xf) == 0xf) { + uint16_t base = pc + i + 1; + uint16_t dest = base + (int8_t)prog[i++]; + len -= snprintf(out + strlen(out), len, + "%d,$%04X", d.s_bit, dest); + } else if (d.branch) { + uint16_t base = pc + i + 1; + uint16_t dest = base + (int8_t)prog[i++]; + len -= snprintf(out + strlen(out), len, + "$%04X", dest); + } else + len -= snprintf(out + strlen(out), len, + "$%02X", prog[i++]); + break; + case ZP_X: + len -= snprintf(out + strlen(out), len, + "$%02X,X", prog[i++]); + break; + case ZP_Y: + len -= snprintf(out + strlen(out), len, + "$%02X,Y", prog[i++]); + break; + case ABS: + len -= snprintf(out + strlen(out), len, + "$%02X%02X", prog[i + 1], prog[i]); + i += 2; + break; + case ABS_X: + len -= snprintf(out + strlen(out), len, + "$%02X%02X,X", prog[i + 1], prog[i]); + i += 2; + break; + case ABS_Y: + len -= snprintf(out + strlen(out), len, + "$%02X%02X,Y", prog[i + 1], prog[i]); + i += 2; + break; + case IND_X: + len -= snprintf(out + strlen(out), len, + "($%02X,X)", prog[i++]); + break; + case IND_AX: + len -= snprintf(out + strlen(out), len, + "($%02X%02X,X)", prog[i + 1], prog[i]); + i += 2; + break; + case IND_Y: + len -= snprintf(out + strlen(out), len, + "($%02X),Y", prog[i++]); + break; + case IND_Z: + len -= snprintf(out + strlen(out), len, + "($%02X)", prog[i++]); + break; + case IND: + len -= snprintf(out + strlen(out), len, + "($%02X%02X)", prog[i + 1], prog[i]); + i += 2; + break; + case IMPLIED: + break; + } + return d.pc; +} + +void +mii_cpu_disasm( + const uint8_t *prog, + uint16_t addr, + uint16_t len) +{ + uint16_t pc = addr; + int i = 0; + while (i < len) { + char out[256] = {0}; + i += mii_cpu_disasm_one(prog + i, pc + i, out, sizeof(out), + MII_DUMP_DIS_PC | MII_DUMP_DIS_DUMP_HEX); + printf("%s\n", out); + } +} diff --git a/src/mii_65c02_disasm.h b/src/mii_65c02_disasm.h new file mode 100644 index 0000000..f32fa9e --- /dev/null +++ b/src/mii_65c02_disasm.h @@ -0,0 +1,24 @@ +#pragma once + +#include + + +enum { + MII_DUMP_DIS_PC = (1 << 0), + MII_DUMP_DIS_DUMP_HEX = (1 << 1), +}; + + +int +mii_cpu_disasm_one( + const uint8_t *prog, + uint16_t addr, + char *out, + size_t out_len, + uint16_t flags); + +void +mii_cpu_disasm( + const uint8_t *prog, + uint16_t addr, + uint16_t len); diff --git a/src/mii_65c02_ops.h b/src/mii_65c02_ops.h new file mode 100644 index 0000000..a66a418 --- /dev/null +++ b/src/mii_65c02_ops.h @@ -0,0 +1,308 @@ +#pragma once + +#include + +typedef struct mii_op_desc_t { + uint32_t op : 8, + mode : 4, + pc : 2, + branch : 1, // relative branch + ch_pc : 1, // change PC + s_bit : 3, + s_bit_value : 1, + r : 1, + w : 1; +} mii_op_desc_t; + +typedef struct mii_op_t { + char name[4]; + mii_op_desc_t desc; +} mii_op_t; + +enum { + B_C = 0, + B_Z, + B_I, + B_D, + B_B, + B_X, + B_V, + B_N, +}; + +enum { + IMPLIED, // BRK + IMM, // LDA #$01 + ZP_REL, // LDA $C0 or BCC $FF + ZP_X, // LDA $C0,X + ZP_Y, // LDX $C0,Y + ABS, // LDA $1234 + ABS_X, // LDA $1234,X + ABS_Y, // LDA $1234,Y + IND_X, // LDA ($FF,X) + IND_AX, // JMP ($1234,X) + IND_Y, // LDA ($FF),Y + IND, // JMP ($1234) + IND_Z, // LDA ($C0) + BRANCH, // BEQ/BNE etc +}; + +#define PCODE_(_name, _mode, _op, _pc, _r, _w, _br, _sb, _sv, _cpc) \ + [_op] = { \ + .name = #_name, \ + .desc = { \ + .op = _op, .mode = _mode, .pc = _pc, .r = _r, .w = _w, \ + .branch = _br, .s_bit = _sb, .s_bit_value = _sv, .ch_pc = _cpc } \ + }, + +#ifndef MII_CPU_65C02_IMPL +extern const mii_op_t mii_cpu_op[256]; + +#else // MII_CPU_65C02_IMPL + +#define PCODE_R_(_name, _mode, _op, _pc) \ + PCODE_(_name, _mode, _op, _pc, 1, 0, 0, 0, 0, 0) +#define PCODE__W(_name, _mode, _op, _pc) \ + PCODE_(_name, _mode, _op, _pc, 0, 1, 0, 0, 0, 0) + +#define PCODE___(_name, _mode, _op, _pc) \ + PCODE_(_name, _mode, _op, _pc, 0, 0, 0, 0, 0, 0) + +#define PCODE_RW(_name, _mode, _op, _pc) \ + PCODE_(_name, _mode, _op, _pc, 1, 1, 0, 0, 0, 0) +#define PCODE__W(_name, _mode, _op, _pc) \ + PCODE_(_name, _mode, _op, _pc, 0, 1, 0, 0, 0, 0) + +#define PCODE_BR(_name, _op, _pc, _sb, _sv) \ + PCODE_(_name, BRANCH, _op, _pc, 0, 0, 1, B_##_sb, _sv, 1) +#define PCODE_PC(_name, _mode, _op, _pc) \ + PCODE_(_name, _mode, _op, _pc, 1, 0, 0, 0, 0, 1) +#define PCODE_RT(_name, _mode, _op, _pc) \ + PCODE_(_name, _mode, _op, _pc, 0, 0, 0, 0, 0, 1) + +#define PCODE_SB(_name, _mode, _op, _pc, _sb, _sv) \ + PCODE_(_name, _mode, _op, _pc, 0, 0, 0, B_##_sb, _sv, 0) +// for RMBx SMBx +#define PCODE_MB(_name, _op, _sb, _sv) \ + PCODE_(_name, ZP_REL, _op, 2, 1, 1, 0, _sb, _sv, 0) +// for BBRx BBSx +#define PCODE_BB(_name, _op, _sb, _sv) \ + PCODE_(_name, ZP_REL, _op, 3, 1, 0, 1, _sb, _sv, 0) + +const mii_op_t mii_cpu_op[256] = { + PCODE___(ADC, IMM, 0x69, 2) + PCODE_R_(ADC, ZP_REL, 0x65, 2) + PCODE_R_(ADC, ZP_X, 0x75, 2) + PCODE_R_(ADC, ABS, 0x6D, 3) + PCODE_R_(ADC, ABS_X, 0x7D, 3) + PCODE_R_(ADC, ABS_Y, 0x79, 3) + PCODE_R_(ADC, IND_X, 0x61, 2) + PCODE_R_(ADC, IND_Y, 0x71, 2) + PCODE_R_(ADC, IND_Z, 0x72, 2) + PCODE___(AND, IMM, 0x29, 2) + PCODE_R_(AND, ZP_REL, 0x25, 2) + PCODE_R_(AND, ZP_X, 0x35, 2) + PCODE_R_(AND, ABS, 0x2D, 3) + PCODE_R_(AND, ABS_X, 0x3D, 3) + PCODE_R_(AND, ABS_Y, 0x39, 3) + PCODE_R_(AND, IND_X, 0x21, 2) + PCODE_R_(AND, IND_Y, 0x31, 2) + PCODE_R_(AND, IND_Z, 0x32, 2) + PCODE___(ASL, IMPLIED, 0x0A, 1) + PCODE_RW(ASL, ZP_REL, 0x06, 2) + PCODE_RW(ASL, ZP_X, 0x16, 2) + PCODE_RW(ASL, ABS, 0x0E, 3) + PCODE_RW(ASL, ABS_X, 0x1E, 3) + PCODE_BB(BBR0, 0x0F, 0, 0) + PCODE_BB(BBR1, 0x1F, 1, 0) + PCODE_BB(BBR2, 0x2F, 2, 0) + PCODE_BB(BBR3, 0x3F, 3, 0) + PCODE_BB(BBR4, 0x4F, 4, 0) + PCODE_BB(BBR5, 0x5F, 5, 0) + PCODE_BB(BBR6, 0x6F, 6, 0) + PCODE_BB(BBR7, 0x7F, 7, 0) + PCODE_BB(BBS0, 0x8F, 0, 1) + PCODE_BB(BBS1, 0x9F, 1, 1) + PCODE_BB(BBS2, 0xAF, 2, 1) + PCODE_BB(BBS3, 0xBF, 3, 1) + PCODE_BB(BBS4, 0xCF, 4, 1) + PCODE_BB(BBS5, 0xDF, 5, 1) + PCODE_BB(BBS6, 0xEF, 6, 1) + PCODE_BB(BBS7, 0xFF, 7, 1) + PCODE_BR(BCC, 0x90, 2, C, 0) + PCODE_BR(BCS, 0xB0, 2, C, 1) + PCODE_BR(BEQ, 0xF0, 2, Z, 1) + PCODE_BR(BMI, 0x30, 2, N, 1) + PCODE_BR(BNE, 0xD0, 2, Z, 0) + PCODE_BR(BPL, 0x10, 2, N, 0) + PCODE_BR(BVC, 0x50, 2, V, 0) + PCODE_BR(BVS, 0x70, 2, V, 1) + PCODE_BR(BRA, 0x80, 2, X, 1) + PCODE_R_(BIT, ZP_REL, 0x24, 2) + PCODE_R_(BIT, ABS, 0x2C, 3) + PCODE___(BIT, IMM, 0x89, 2) + PCODE_R_(BIT, ZP_X, 0x34, 2) + PCODE_R_(BIT, ABS_X, 0x3C, 3) + PCODE_RT(BRK, IMPLIED, 0x00, 1) + PCODE_SB(CLC, IMPLIED, 0x18, 1, C, 0) + PCODE_SB(CLD, IMPLIED, 0xD8, 1, D, 0) + PCODE_SB(CLI, IMPLIED, 0x58, 1, I, 0) + PCODE_SB(CLV, IMPLIED, 0xB8, 1, V, 0) + PCODE___(CMP, IMM, 0xC9, 2) + PCODE_R_(CMP, ZP_REL, 0xC5, 2) + PCODE_R_(CMP, ZP_X, 0xD5, 2) + PCODE_R_(CMP, ABS_X, 0xDD, 3) + PCODE_R_(CMP, ABS, 0xCD, 3) + PCODE_R_(CMP, ABS_Y, 0xD9, 3) + PCODE_R_(CMP, IND_X, 0xC1, 2) + PCODE_R_(CMP, IND_Y, 0xD1, 2) + PCODE_R_(CMP, IND_Z, 0xD2, 2) + PCODE___(CPX, IMM, 0xE0, 2) + PCODE_R_(CPX, ZP_REL, 0xE4, 2) + PCODE_R_(CPX, ABS, 0xEC, 3) + PCODE___(CPY, IMM, 0xC0, 2) + PCODE_R_(CPY, ZP_REL, 0xC4, 2) + PCODE_R_(CPY, ABS, 0xCC, 3) + PCODE___(DEC, IMPLIED, 0x3A, 1) + PCODE_RW(DEC, ZP_REL, 0xC6, 2) + PCODE_RW(DEC, ZP_X, 0xD6, 2) + PCODE_RW(DEC, ABS, 0xCE, 3) + PCODE_RW(DEC, ABS_X, 0xDE, 3) + PCODE___(DEX, IMPLIED, 0xCA, 1) + PCODE___(DEY, IMPLIED, 0x88, 1) + PCODE___(EOR, IMM, 0x49, 2) + PCODE_R_(EOR, ZP_REL, 0x45, 2) + PCODE_R_(EOR, ZP_X, 0x55, 2) + PCODE_R_(EOR, ABS, 0x4D, 3) + PCODE_R_(EOR, ABS_X, 0x5D, 3) + PCODE_R_(EOR, ABS_Y, 0x59, 3) + PCODE_R_(EOR, IND_X, 0x41, 2) + PCODE_R_(EOR, IND_Y, 0x51, 2) + PCODE_R_(EOR, IND_Z, 0x52, 2) + PCODE___(INC, IMPLIED, 0x1A, 1) + PCODE_RW(INC, ZP_REL, 0xE6, 2) + PCODE_RW(INC, ZP_X, 0xF6, 2) + PCODE_RW(INC, ABS, 0xEE, 3) + PCODE_RW(INC, ABS_X, 0xFE, 3) + PCODE___(INX, IMPLIED, 0xE8, 1) + PCODE___(INY, IMPLIED, 0xC8, 1) + PCODE_PC(JMP, ABS, 0x4C, 3) + PCODE_PC(JMP, IND, 0x6C, 3) + PCODE_PC(JMP, IND_AX, 0x7C, 3) + PCODE_PC(JSR, ABS, 0x20, 3) + PCODE___(LDA, IMM, 0xA9, 2) + PCODE_R_(LDA, ZP_REL, 0xA5, 2) + PCODE_R_(LDA, ZP_X, 0xB5, 2) + PCODE_R_(LDA, ABS, 0xAD, 3) + PCODE_R_(LDA, ABS_X, 0xBD, 3) + PCODE_R_(LDA, ABS_Y, 0xB9, 3) + PCODE_R_(LDA, IND_X, 0xA1, 2) + PCODE_R_(LDA, IND_Y, 0xB1, 2) + PCODE_R_(LDA, IND_Z, 0xB2, 2) + PCODE___(LDX, IMM, 0xA2, 2) + PCODE_R_(LDX, ZP_REL, 0xA6, 2) + PCODE_R_(LDX, ZP_Y, 0xB6, 2) + PCODE_R_(LDX, ABS, 0xAE, 3) + PCODE_R_(LDX, ABS_Y, 0xBE, 3) + PCODE___(LDY, IMM, 0xA0, 2) + PCODE_R_(LDY, ZP_REL, 0xA4, 2) + PCODE_R_(LDY, ZP_X, 0xB4, 2) + PCODE_R_(LDY, ABS, 0xAC, 3) + PCODE_R_(LDY, ABS_X, 0xBC, 3) + PCODE___(LSR, IMPLIED, 0x4A, 1) + PCODE_RW(LSR, ZP_REL, 0x46, 2) + PCODE_RW(LSR, ZP_X, 0x56, 2) + PCODE_RW(LSR, ABS, 0x4E, 3) + PCODE_RW(LSR, ABS_X, 0x5E, 3) + PCODE___(NOP, IMPLIED, 0xEA, 1) + PCODE___(ORA, IMM, 0x09, 2) + PCODE_R_(ORA, ZP_REL, 0x05, 2) + PCODE_R_(ORA, ZP_X, 0x15, 2) + PCODE_R_(ORA, ABS, 0x0D, 3) + PCODE_R_(ORA, ABS_X, 0x1D, 3) + PCODE_R_(ORA, ABS_Y, 0x19, 3) + PCODE_R_(ORA, IND_X, 0x01, 2) + PCODE_R_(ORA, IND_Y, 0x11, 2) + PCODE_R_(ORA, IND_Z, 0x12, 2) + PCODE___(PHA, IMPLIED, 0x48, 1) + PCODE___(PHP, IMPLIED, 0x08, 1) + PCODE___(PHX, IMPLIED, 0xDA, 1) + PCODE___(PHY, IMPLIED, 0x5A, 1) + PCODE___(PLA, IMPLIED, 0x68, 1) + PCODE___(PLP, IMPLIED, 0x28, 1) + PCODE___(PLX, IMPLIED, 0xFA, 1) + PCODE___(PLY, IMPLIED, 0x7A, 1) + // these fill the opcode name without terminating zero + PCODE_MB(RMB0, 0x07, 0, 0) + PCODE_MB(RMB1, 0x17, 1, 0) + PCODE_MB(RMB2, 0x27, 2, 0) + PCODE_MB(RMB3, 0x37, 3, 0) + PCODE_MB(RMB4, 0x47, 4, 0) + PCODE_MB(RMB5, 0x57, 5, 0) + PCODE_MB(RMB6, 0x67, 6, 0) + PCODE_MB(RMB7, 0x77, 7, 0) + PCODE___(ROL, IMPLIED, 0x2A, 1) + PCODE_RW(ROL, ZP_REL, 0x26, 2) + PCODE_RW(ROL, ZP_X, 0x36, 2) + PCODE_RW(ROL, ABS, 0x2E, 3) + PCODE_RW(ROL, ABS_X, 0x3E, 3) + PCODE___(ROR, IMPLIED, 0x6A, 1) + PCODE_RW(ROR, ZP_REL, 0x66, 2) + PCODE_RW(ROR, ZP_X, 0x76, 2) + PCODE_RW(ROR, ABS, 0x6E, 3) + PCODE_RW(ROR, ABS_X, 0x7E, 3) + PCODE_RT(RTI, IMPLIED, 0x40, 1) + PCODE_RT(RTS, IMPLIED, 0x60, 1) + PCODE___(SBC, IMM, 0xE9, 2) + PCODE_R_(SBC, ZP_REL, 0xE5, 2) + PCODE_R_(SBC, ZP_X, 0xF5, 2) + PCODE_R_(SBC, ABS, 0xED, 3) + PCODE_R_(SBC, ABS_X, 0xFD, 3) + PCODE_R_(SBC, ABS_Y, 0xF9, 3) + PCODE_R_(SBC, IND_X, 0xE1, 2) + PCODE_R_(SBC, IND_Y, 0xF1, 2) + PCODE_R_(SBC, IND_Z, 0xF2, 2) + PCODE_SB(SEC, IMPLIED, 0x38, 1, C, 1) + PCODE_SB(SED, IMPLIED, 0xF8, 1, D, 1) + PCODE_SB(SEI, IMPLIED, 0x78, 1, I, 1) + // these fill the opcode name without terminating zero + PCODE_MB(SMB0, 0x87, 0, 1) + PCODE_MB(SMB1, 0x97, 1, 1) + PCODE_MB(SMB2, 0xa7, 2, 1) + PCODE_MB(SMB3, 0xb7, 3, 1) + PCODE_MB(SMB4, 0xc7, 4, 1) + PCODE_MB(SMB5, 0xd7, 5, 1) + PCODE_MB(SMB6, 0xe7, 6, 1) + PCODE_MB(SMB7, 0xf7, 7, 1) + PCODE__W(STA, ZP_REL, 0x85, 2) + PCODE__W(STA, ZP_X, 0x95, 2) + PCODE__W(STA, ABS, 0x8D, 3) + PCODE__W(STA, ABS_X, 0x9D, 3) + PCODE__W(STA, ABS_Y, 0x99, 3) + PCODE__W(STA, IND_X, 0x81, 2) + PCODE__W(STA, IND_Y, 0x91, 2) + PCODE__W(STA, IND_Z, 0x92, 2) + PCODE__W(STX, ZP_REL, 0x86, 2) + PCODE__W(STX, ZP_Y, 0x96, 2) + PCODE__W(STX, ABS, 0x8E, 3) + PCODE__W(STY, ZP_REL, 0x84, 2) + PCODE__W(STY, ZP_X, 0x94, 2) + PCODE__W(STY, ABS, 0x8C, 3) + PCODE__W(STZ, ZP_REL, 0x64, 2) + PCODE__W(STZ, ZP_X, 0x74, 2) + PCODE__W(STZ, ABS, 0x9C, 3) + PCODE__W(STZ, ABS_X, 0x9E, 3) + PCODE___(TAX, IMPLIED, 0xAA, 1) + PCODE___(TAY, IMPLIED, 0xA8, 1) + PCODE_RW(TRB, ZP_REL, 0x14, 2) + PCODE_RW(TRB, ABS, 0x1c, 3) + PCODE___(TSX, IMPLIED, 0xBA, 1) + PCODE_RW(TSB, ZP_REL, 0x04, 2) + PCODE_RW(TSB, ABS, 0x0c, 3) + PCODE___(TXA, IMPLIED, 0x8A, 1) + PCODE___(TXS, IMPLIED, 0x9A, 1) + PCODE___(TYA, IMPLIED, 0x98, 1) +}; + + +#endif // MII_CPU_65C02_IMPL diff --git a/src/mii_argv.c b/src/mii_argv.c new file mode 100644 index 0000000..514c208 --- /dev/null +++ b/src/mii_argv.c @@ -0,0 +1,199 @@ +/* + * mii_argv.c + * + * Copyright (C) 2023 Michel Pollet + * + * SPDX-License-Identifier: MIT + */ + +#include +#include +#include +#include + +#include "mii.h" + +extern mii_slot_drv_t * mii_slot_drv_list; + +static void +_mii_usage( + const char *progname) +{ + printf("Usage: %s [options]\n", progname); + printf("Options:\n"); + printf(" -h, --help\tThis help\n"); + printf(" -v, --verbose\tVerbose output\n"); + printf(" -m, --mute\tMute the speaker\n"); + printf(" -vol, --volume \tSet speaker volume (0.0 to 10.0)\n"); + printf(" -speed, --speed \tSet the CPU speed in MHz\n"); + printf(" -s, --slot :\tSpecify a slot and driver\n"); + printf("\t\tSlot id is 1..7\n"); + printf(" -d, --drive ::\tLoad a drive\n"); + printf("\t\tSlot id is 1..7, drive is 1..2\n"); + printf("\t\tAlternate syntax: : \n"); + printf(" -L, --list-drivers\tList available drivers, exit\n"); + printf(" -def, --default\tUse a set of default cards:\n"); + printf("\t\tSlot 4: mouse\n"); + printf("\t\tSlot 6: disk2\n"); + printf("\t\tSlot 7: smartport\n"); + printf(" -nsc[=0|1]\tEnable/Disable No Slot Clock:\n"); + printf("\t\t0: disable\n"); + printf("\t\t1: enable [Enabled by default]\n"); + printf(" -titan[=0|1]\tEnable/Disable Titan Accelerator IIe:\n"); + printf("\t\t0: disable [default]\n"); + printf("\t\t1: enable [Start at 3.58MHz]\n"); +} + +int +mii_argv_parse( + mii_t *mii, + int argc, + const char *argv[], + int *index, + uint32_t *ioFlags) +{ + if (*index == 0) + *index += 1; + for (int i = *index; i < argc; i++) { + const char *arg = argv[i]; + + if (!strcmp(arg, "-h") || !strcmp(arg, "--help")) { + _mii_usage(argv[0]); + exit(0); + } else if (!strcmp(arg, "-v") || !strcmp(arg, "--verbose")) { + // mii->verbose++; + // continue; + } else if ((!strcmp(arg, "-s") || !strcmp(arg, "--slot")) && i < argc-1) { + // for mat for slot is 1..8: where name is the driver name + const char *p = argv[++i]; + int slot = 0; + char *drv = NULL; + if (sscanf(p, "%d:%ms", &slot, &drv) != 2) { + printf("mii: invalid slot specification %s\n", p); + return 1; + } + if (slot < 1 || slot > 8) { + printf("mii: invalid slot number %d\n", slot); + return 1; + } + if (drv == NULL) { + printf("mii: missing driver name for slot %d\n", slot); + return 1; + } + if (mii_slot_drv_register(mii, slot, drv) < 0) { + printf("mii: failed to register driver %s for slot %d\n", drv, slot); + return 1; + } + } else if ((!strcmp(arg, "-d") || !strcmp(arg, "--drive")) && i < argc-1) { + // drive takes 2 following arguments, the : and a filename + const char *p = argv[++i]; + int slot = 0; + int drive = 0; + const char *filename = NULL; + int got = sscanf(p, "%d:%d:%ms", &slot, &drive, &filename); + if (got == 2) { + if (i < argc-1) { + filename = argv[++i]; + got = 3; + } else { + printf("mii: missing filename for drive %d:%d\n", slot, drive); + return 1; + } + } else if (got != 3) { + printf("mii: invalid drive specification %s\n", p); + return 1; + } + if (slot < 1 || slot > 8) { + printf("mii: invalid slot number %d\n", slot); + return 1; + } + if (drive < 1 || drive > 2) { + printf("mii: invalid drive number %d\n", drive); + return 1; + } + if (filename == NULL) { + printf("mii: missing filename for drive %d:%d\n", slot, drive); + return 1; + } + mii_slot_command(mii, slot, + MII_SLOT_DRIVE_LOAD + drive - 1, + (void*)filename); + } else if (!strcmp(arg, "-def") || !strcmp(arg, "--default")) { + mii_slot_drv_register(mii, 4, "mouse"); + mii_slot_drv_register(mii, 6, "disk2"); + mii_slot_drv_register(mii, 7, "smartport"); + } else if (!strcmp(arg, "-L") || !strcmp(arg, "--list-drivers")) { + mii_slot_drv_t * drv = mii_slot_drv_list; + printf("mii: available drivers:\n"); + while (drv) { + printf("%10.10s - %s\n", drv->name, drv->desc); + drv = drv->next; + } + exit(0); + } else if (!strcmp(arg, "-m") || !strcmp(arg, "--mute")) { + mii->speaker.muted = true; + } else if (!strcmp(arg, "-vol") || !strcmp(arg, "--volume")) { + if (i < argc-1) { + float vol = atof(argv[++i]); + if (vol < 0) vol = 0; + else if (vol > 10) vol = 10; + mii_speaker_volume(&mii->speaker, vol); + } else { + printf("mii: missing volume value\n"); + return 1; + } + } else if (!strcmp(arg, "-speed") || !strcmp(arg, "--speed")) { + if (i < argc-1) { + mii->speed = atof(argv[++i]); + if (mii->speed < 0.0) + mii->speed = 1.0; + } else { + printf("mii: missing speed value\n"); + return 1; + } + } else { + if (argv[i][0] == '-') { + char dup[128]; + snprintf(dup, sizeof(dup), "%s", argv[i] + 1); + char *equal = dup; + char *name = strsep(&equal, "="); + int enable = 1; + if (equal && *equal) { + if (!strcmp(equal, "0")) + enable = 0; + else if (!strcmp(equal, "1")) + enable = 1; + else { + printf("mii: invalid flag %s\n", argv[i]); + return 1; + } + } + // printf("%s lookup driver %s to %s\n", __func__, + // name, enable ? "enable" : "disable"); + mii_slot_drv_t * drv = mii_slot_drv_list; + int done = 0; + while (drv) { + printf("%10.10s - %s\n", drv->name, drv->desc); + if (drv->enable_flag) { + if (!strcmp(name, drv->name)) { + *ioFlags = (*ioFlags & ~drv->enable_flag) | + (enable ? drv->enable_flag : 0); + printf("mii: %s %s\n", name, enable ? "enabled" : "disabled"); + break; + } + } + drv = drv->next; + } + if (!done && equal) { + printf("mii: no driver found %s\n", argv[i]); + return 1; + } + continue; + } + printf("mii: unknown argument %s\n", argv[i]); + return 1; + } + } + *index = argc; + return 1; +} \ No newline at end of file diff --git a/src/mii_bank.c b/src/mii_bank.c new file mode 100644 index 0000000..51fcf9c --- /dev/null +++ b/src/mii_bank.c @@ -0,0 +1,105 @@ +/* + * mii_bank.c + * + * Copyright (C) 2023 Michel Pollet + * + * SPDX-License-Identifier: MIT + */ + +#include +#include +#include +#include + +#include "mii.h" +#include "mii_bank.h" + + +void +mii_bank_write( + mii_bank_t *bank, + uint16_t addr, + const uint8_t *data, + uint16_t len) +{ + if ((addr < bank->base) || + ((addr + len) > (uint32_t)(bank->base + (bank->size * 256)))) { + printf("%s %s INVALID write addr %04x len %d %04x:%04x\n", + __func__, bank->name, addr, (int)len, + bank->base, bank->base + (bank->size * 256)); + return; + } + uint8_t page_index = (addr - bank->base) >> 8; + if (bank->access && bank->access[page_index].cb) { + if (bank->access[page_index].cb(bank, bank->access[page_index].param, + addr, (uint8_t *)data, true)) + return; + } + if (!bank->mem) { + bank->alloc = 1; + bank->mem = calloc(1, bank->size * 256); + } + addr -= bank->base; + for (uint16_t i = 0; i < len; i++, addr++) { + bank->mem[addr] = data[i]; + } +} + +void +mii_bank_read( + mii_bank_t *bank, + uint16_t addr, + uint8_t *data, + uint16_t len) +{ + if (addr < bank->base || + (addr + len) > (uint32_t)(bank->base + (bank->size * 256))) { + printf("%s %s INVALID read addr %04x len %d %04x-%04x\n", + __func__, bank->name, addr, (int)len, + bank->base, bank->base + (bank->size * 256)); + return; + } + uint8_t page_index = (addr - bank->base) >> 8; + if (bank->access && bank->access[page_index].cb) { + if (bank->access[page_index].cb(bank, bank->access[page_index].param, + addr, data, false)) + return; + } + if (!bank->mem) { + bank->alloc = 1; + bank->mem = calloc(1, bank->size * 256); + } + addr -= bank->base; + for (uint16_t i = 0; i < len; i++, addr++) { + data[i] = bank->mem[addr]; + } +} + + +void +mii_bank_install_access_cb( + mii_bank_t *bank, + mii_bank_access_cb cb, + void *param, + uint8_t page, + uint8_t end) +{ + if (!end) + end = page; + if ((page << 8) < bank->base || (end << 8) > (bank->base + bank->size * 256)) { + printf("%s %s INVALID install access cb %p param %p page %02x-%02x\n", + __func__, bank->name, cb, param, page, end); + return; + } + page -= bank->base >> 8; + end -= bank->base >> 8; + if (!bank->access) { + bank->access = calloc(1, bank->size * sizeof(bank->access[0])); + } + printf("%s %s install access cb page %02x:%02x\n", + __func__, bank->name, page, end); + for (int i = page; i <= end; i++) { + bank->access[i].cb = cb; + bank->access[i].param = param; + } +} diff --git a/src/mii_bank.h b/src/mii_bank.h new file mode 100644 index 0000000..4c7c509 --- /dev/null +++ b/src/mii_bank.h @@ -0,0 +1,81 @@ +/* + * mii_bank.h + * + * Copyright (C) 2023 Michel Pollet + * + * SPDX-License-Identifier: MIT + */ + +#pragma once +#include +#include + +struct mii_bank_t; +typedef bool (*mii_bank_access_cb)( + struct mii_bank_t *bank, + void *param, + uint16_t addr, + uint8_t * byte, + bool write); + +typedef struct mii_bank_access_t { + mii_bank_access_cb cb; + void *param; +} mii_bank_access_t; + +typedef struct mii_bank_t { + uint64_t base : 16, // base address + size : 9, // in pages + alloc : 1, // been calloced() + ro : 1; // read only + char * name; + mii_bank_access_t * access; + uint8_t *mem; +} mii_bank_t; + +void +mii_bank_write( + mii_bank_t *bank, + uint16_t addr, + const uint8_t *data, + uint16_t len); +void +mii_bank_read( + mii_bank_t *bank, + uint16_t addr, + uint8_t *data, + uint16_t len); + +/* return the number of pages dirty (written into since last time) between + * addr1 and addr2 (inclusive) */ +uint8_t +mii_bank_is_dirty( + mii_bank_t *bank, + uint16_t addr1, + uint16_t addr2); +void +mii_bank_install_access_cb( + mii_bank_t *bank, + mii_bank_access_cb cb, + void *param, + uint8_t page, + uint8_t end); + +static inline void +mii_bank_poke( + mii_bank_t *bank, + uint16_t addr, + const uint8_t data) +{ + mii_bank_write(bank, addr, &data, 1); +} + +static inline uint8_t +mii_bank_peek( + mii_bank_t *bank, + uint16_t addr) +{ + uint8_t res = 0; + mii_bank_read(bank, addr, &res, 1); + return res; +} diff --git a/src/mii_slot.c b/src/mii_slot.c new file mode 100644 index 0000000..eeaa785 --- /dev/null +++ b/src/mii_slot.c @@ -0,0 +1,86 @@ +/* + * mii_slot.c + * + * Copyright (C) 2023 Michel Pollet + * + * SPDX-License-Identifier: MIT + */ +#include +#include +#include +#include + +#include "mii.h" + +mii_slot_drv_t * +mii_slot_drv_find( + mii_t *mii, + const char * name) +{ + mii_slot_drv_t * drv = mii_slot_drv_list; + while (drv) { + if (!strcmp(drv->name, name)) + return drv; + drv = drv->next; + } + return NULL; +} + +int +mii_slot_drv_register( + mii_t *mii, + uint8_t slot_id, + const char *driver_name) +{ + if (!mii || !driver_name) { + printf("%s invalid args\n", __func__); + return -1; + } + if (slot_id < 1 || slot_id > 7) { + printf("%s invalid slot id %d\n", __func__, slot_id); + return -1; + } + if (mii->slot[slot_id - 1].drv) { + printf("%s slot %d already has a driver (%s)\n", + __func__, slot_id, mii->slot[slot_id - 1].drv->name); + return -1; + } + mii_slot_drv_t * drv = mii_slot_drv_find(mii, driver_name); + if (!drv) { + printf("%s driver %s not found\n", __func__, driver_name); + return -1; + } + if (drv->init) { + if (drv->init(mii, &mii->slot[slot_id - 1]) != 0) { + printf("%s driver %s init failed\n", __func__, driver_name); + return -1; + } + } + mii->slot[slot_id - 1].drv = drv; + return 0; +} + +mii_slot_drv_t * +mii_slot_drv_get( + mii_t *mii, + uint8_t slot_id) +{ + if (!mii || slot_id < 1 || slot_id > 7) + return NULL; + return (mii_slot_drv_t *)mii->slot[slot_id - 1].drv; +} + +int +mii_slot_command( + mii_t *mii, + uint8_t slot_id, + uint8_t cmd, + void * param) +{ + mii_slot_drv_t * drv = mii_slot_drv_get(mii, slot_id); + if (!drv) + return -1; + if (drv->command) + return drv->command(mii, &mii->slot[slot_id - 1], cmd, param); + return -1; +} diff --git a/src/mii_slot.h b/src/mii_slot.h new file mode 100644 index 0000000..6d2a621 --- /dev/null +++ b/src/mii_slot.h @@ -0,0 +1,74 @@ +/* + * mii_slot.h + * + * Copyright (C) 2023 Michel Pollet + * + * SPDX-License-Identifier: MIT + */ +#pragma once + +#include + +typedef struct mii_slot_drv_t mii_slot_drv_t; + +typedef struct mii_slot_t { + uint8_t id; + void * drv_priv; // for driver use + const mii_slot_drv_t * drv; +} mii_slot_t; + +typedef struct mii_t mii_t; + +/* + * That won't handle secondary ROM banks, we'll do that if we ever need it + */ +typedef struct mii_slot_drv_t { + struct mii_slot_drv_t *next; // in global driver queue + uint32_t enable_flag; // if there is a MII_INIT_xxx flag + const char * name; + const char * desc; + int (*probe)(mii_t * mii, uint32_t flags); + int (*init)(mii_t * mii, struct mii_slot_t *slot); + void (*reset)(mii_t * mii, struct mii_slot_t *slot); /* optional */ + void (*run)(mii_t * mii, struct mii_slot_t *slot); /* optional */ + uint8_t (*access)( + mii_t * mii, + struct mii_slot_t *slot, + uint16_t addr, uint8_t data, bool write); + // arbitrary command for load/save etc /* optional */ + int (*command)( + mii_t * mii, + struct mii_slot_t *slot, + uint8_t cmd, + void * param); +} mii_slot_drv_t; + +// get driver installed in slot_id +mii_slot_drv_t * +mii_slot_drv_get( + mii_t *mii, + uint8_t slot_id); +// install driver 'driver_name' in slot_id slot +int +mii_slot_drv_register( + mii_t *mii, + uint8_t slot_id, + const char *driver_name); +// find a driver 'name' in the global list +mii_slot_drv_t * +mii_slot_drv_find( + mii_t *mii, + const char * name); + +enum { + MII_SLOT_DRIVE_COUNT = 0x01, + MII_SLOT_DRIVE_LOAD = 0x20, // + drive index 0...n +}; + +// send a command to a slot/driver. Return >=0 if ok, -1 if error +int +mii_slot_command( + mii_t *mii, + uint8_t slot_id, + uint8_t cmd, + void * param); diff --git a/src/mii_speaker.c b/src/mii_speaker.c new file mode 100644 index 0000000..d98833e --- /dev/null +++ b/src/mii_speaker.c @@ -0,0 +1,212 @@ +/* + * mii_speaker.c + * + * Copyright (C) 2023 Michel Pollet + * + * SPDX-License-Identifier: MIT + */ + +#include +#include +#include +#include + +#include "mii.h" +#include "mii_speaker.h" + +// one frame of audio per frame of video? +#define MII_SPEAKER_FRAME_SIZE (MII_SPEAKER_FREQ / 60) + +// TODO Make some sort of driver for audio and move alsa code there +#ifdef HAS_ALSA +#include + +#define PCM_DEVICE "default" + +static int +_alsa_init( + mii_speaker_t *s) +{ + int pcm; + unsigned int rate = 44100, channels = 1; + snd_pcm_t *alsa; + snd_pcm_hw_params_t *params; + snd_pcm_uframes_t frames; + + /* Open the PCM device in playback mode */ + if ((pcm = snd_pcm_open(&alsa, PCM_DEVICE, + SND_PCM_STREAM_PLAYBACK, 0)) < 0) + printf("ERROR: Can't open \"%s\" PCM device. %s\n", + PCM_DEVICE, snd_strerror(pcm)); + + /* Allocate parameters object and fill it with default values*/ + snd_pcm_hw_params_alloca(¶ms); + snd_pcm_hw_params_any(alsa, params); + + /* Set parameters */ + if ((pcm = snd_pcm_hw_params_set_access(alsa, params, + SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) + printf("ERROR: Can't set interleaved mode. %s\n", + snd_strerror(pcm)); + + if ((pcm = snd_pcm_hw_params_set_format(alsa, params, + SND_PCM_FORMAT_S16_LE)) < 0) + printf("ERROR: Can't set format. %s\n", + snd_strerror(pcm)); + if ((pcm = snd_pcm_hw_params_set_channels(alsa, params, channels)) < 0) + printf("ERROR: Can't set channels number. %s\n", snd_strerror(pcm)); + + if ((pcm = snd_pcm_hw_params_set_rate_near(alsa, params, &rate, 0)) < 0) + printf("ERROR: Can't set rate. %s\n", + snd_strerror(pcm)); + frames = MII_SPEAKER_FRAME_SIZE; + /* Write parameters */ + if ((pcm = snd_pcm_hw_params(alsa, params)) < 0) + printf("ERROR: Can't set harware parameters. %s\n", + snd_strerror(pcm)); +// printf("%s frames want %d got %ld\n", +// __func__, MII_SPEAKER_FRAME_SIZE, frames); + + snd_pcm_sw_params_t *sw_params; + snd_pcm_sw_params_alloca (&sw_params); + snd_pcm_sw_params_current (alsa, sw_params); + snd_pcm_sw_params_set_start_threshold(alsa, sw_params, frames * 4); + snd_pcm_sw_params_set_avail_min(alsa, sw_params, frames*4); + snd_pcm_sw_params(alsa, sw_params); + + s->fsize = frames; + s->alsa_pcm = alsa; + snd_pcm_prepare(s->alsa_pcm); + return 0; +} +#endif + +// Initialize the speaker with the frame size in samples +void +mii_speaker_init( + struct mii_t * mii, + mii_speaker_t *s) +{ + s->mii = mii; + s->fsize = MII_SPEAKER_FRAME_SIZE; +#ifdef HAS_ALSA + _alsa_init(s); // this can/will change fsize +#endif + s->vol_multiplier = 0.2; + s->sample = 0x8000; + s->findex = 0; + for (int i = 0; i < MII_SPEAKER_FRAME_COUNT; i++) + s->frame[i].audio = calloc(sizeof(s->frame[i].audio[0]), s->fsize); + s->frame[0].start = mii->cycles; +} + +// Called when $c030 is touched, place a sample at the 'appropriate' time +void +mii_speaker_click( + mii_speaker_t *s) +{ + // if CPU speed has changed, recalculate the number of cycles per sample + if (s->cpu_speed != s->mii->speed) { + s->cpu_speed = s->mii->speed; + s->clk_per_sample = ((1000000.0 /* / s->mii->speed */) / + (float)MII_SPEAKER_FREQ) + 0.5f; + printf("%s: %d cycles per sample\n", __func__, s->clk_per_sample); + } + mii_audio_frame_t *f = &s->frame[s->findex]; + // if we had stopped playing for 2 frames, restart + if (f->start == 0 || + (s->mii->cycles - f->start) > (2 * s->fsize * s->clk_per_sample)) { + // printf("Restarting playback\n"); +#ifdef HAS_ALSA + snd_pcm_prepare(s->alsa_pcm); +#endif + f->start = s->mii->cycles - (s->clk_per_sample * 8); + f->fill = 0; + // add a small attack to the start of the frame to soften the beeps + // we are going to flip the sample, so we need to preemptively + // flip the attack as well + mii_audio_sample_t attack = s->sample ^ 0xffff; + for (int i = 8; i >= 1; i--) + f->audio[f->fill++] = (attack / i) * s->vol_multiplier; + s->fplay = s->findex; // restart here + } + + long sample_index = (s->mii->cycles - f->start) / s->clk_per_sample; + // fill from last sample to here with the current sample + for (; f->fill < sample_index && f->fill < s->fsize; f->fill++) + f->audio[f->fill] = s->sample * s->vol_multiplier; + + // if we've gone past the end of the frame, switch to the next one + if (sample_index >= s->fsize) { + sample_index = sample_index % s->fsize; + __uint128_t newstart = s->mii->cycles - (sample_index * s->clk_per_sample); + s->findex = (s->findex + 1) % MII_SPEAKER_FRAME_COUNT; + f = &s->frame[s->findex]; + f->start = newstart; + f->fill = 0; + // fill from start of this frame to newly calculated sample_index + for (; f->fill < sample_index && f->fill < s->fsize; f->fill++) + f->audio[f->fill] = s->sample * s->vol_multiplier; + } + s->sample ^= 0xffff; + f->audio[sample_index] = s->sample * s->vol_multiplier; +} + +int g_mii_audio_record_fd = -1; + +// Check to see if there's a new frame to send, send it +void +mii_speaker_run( + mii_speaker_t *s) +{ + mii_audio_frame_t *f = &s->frame[s->fplay]; + + // here we check if the frame we want to play is filled, and if it's + // been long enough since we started filling it to be sure we have + // enough samples to play. + // There's also the case were we stopped playing and the last frame + // wasn't complete, in which case we flush it as well + if (f->fill && ((s->mii->cycles - f->start) > + (s->fsize * s->clk_per_sample * 2))) { + s->fplaying = s->fplay; + s->fplay = (s->fplay + 1) % MII_SPEAKER_FRAME_COUNT; + f = &s->frame[s->fplaying]; + if (!s->muted) { +#ifdef HAS_ALSA + int pcm; + if (g_mii_audio_record_fd != -1) + write(g_mii_audio_record_fd, f->audio, + f->fill * sizeof(s->frame[0].audio[0])); + if ((pcm = snd_pcm_writei(s->alsa_pcm, + f->audio, f->fill)) == -EPIPE) { + printf("%s Underrun.\n", __func__); + snd_pcm_recover(s->alsa_pcm, pcm, 1); + } +#endif + } + f->fill = 0; + } +} + +// this is here so we dont' have to drag in libm math library. +double fastPow(double a, double b) { + union { double d; int32_t x[2]; } u = { .d = a }; + u.x[1] = (int)(b * (u.x[1] - 1072632447) + 1072632447); + u.x[0] = 0; + return u.d; +} + +// take the volume from 0 to 10, save it, convert it to a multiplier +void +mii_speaker_volume( + mii_speaker_t *s, + float volume) +{ + if (volume < 0) volume = 0; + else if (volume > 10) volume = 10; + double mul = (fastPow(10.0, volume / 10.0) / 10.0) - 0.09; + s->vol_multiplier = mul; + s->volume = volume; + +// printf("audio: speaker volume set to %.3f (%.4f)\n", volume, mul); +} \ No newline at end of file diff --git a/src/mii_speaker.h b/src/mii_speaker.h new file mode 100644 index 0000000..25b0ecc --- /dev/null +++ b/src/mii_speaker.h @@ -0,0 +1,58 @@ +/* + * mii_speaker.h + * + * Copyright (C) 2023 Michel Pollet + * + * SPDX-License-Identifier: MIT + */ + +#pragma once +#include + +#define MII_SPEAKER_FREQ (44100) +#define MII_SPEAKER_FRAME_COUNT 4 + +struct mii_t; +struct snd_pcm_t; +typedef int16_t mii_audio_sample_t; + +typedef struct mii_audio_frame_t { + __uint128_t start; + uint16_t fill; + mii_audio_sample_t * audio; +} mii_audio_frame_t; + +typedef struct mii_speaker_t { + struct mii_t * mii; + void * alsa_pcm; // alsa pcm handle + bool muted; // if true, don't play anything + float volume; // volume, 0.0 to 10.0 + float vol_multiplier; // sample multiplier, 0.0 to 1.0 + float cpu_speed; // CPU speed in MHz, to calculate clk_per_sample + uint8_t fplay; // frame we want to play + uint8_t fplaying; // index of the current playing frame + uint16_t fsize; // size in samples of a frame + uint8_t findex; // frame we are currently filling + uint16_t clk_per_sample; // number of cycles per sample (at current CPU speed) + mii_audio_sample_t sample; // current value for the speaker output + mii_audio_frame_t frame[MII_SPEAKER_FRAME_COUNT]; +} mii_speaker_t; + +// Initialize the speaker with the frame size in samples +void +mii_speaker_init( + struct mii_t * mii, + mii_speaker_t *speaker); +// Called when $c030 is touched, place a sample at the 'appropriate' time +void +mii_speaker_click( + mii_speaker_t *speaker); +// Check to see if there's a new frame to send, send it +void +mii_speaker_run( + mii_speaker_t *speaker); +// volume from 0 to 10, sets the audio sample multiplier. +void +mii_speaker_volume( + mii_speaker_t *s, + float volume); diff --git a/src/mii_sw.h b/src/mii_sw.h new file mode 100644 index 0000000..88efa76 --- /dev/null +++ b/src/mii_sw.h @@ -0,0 +1,59 @@ + + +#pragma once + +enum { + SW80STOREOFF = 0xc000, + SW80STOREON = 0xc001, + SWALTCHARSETOFF = 0xc00e, + SWALTCHARSETON = 0xc00f, + + SW80STORE = 0xc018, + SWVBL = 0xc019, + SW80COL = 0xc01f, + SWTEXT = 0xc01a, + SWMIXED = 0xc01b, + SWPAGE2 = 0xc01c, + SWHIRES = 0xc01d, + SWALTCHARSET = 0xc01e, + + SW80COLOFF = 0xc00c, + SW80COLON = 0xc00d, + SWTEXTOFF = 0xc050, // (AKA LORES ON) + SWTEXTON = 0xc051, + SWMIXEDOFF = 0xc052, + SWMIXEDON = 0xc053, + SWPAGE2OFF = 0xc054, + SWPAGE2ON = 0xc055, + SWHIRESOFF = 0xc056, + SWHIRESON = 0xc057, + + // this one is inverted, the ON is the even address + SWDHIRESOFF = 0xc05f, // AN3_ON + SWDHIRESON = 0xc05e, // AN3_OFF + SWAN3 = 0xc05e, // AN3 status + SWAN3_REGISTER = 0xc05f, // AN3 register for video mode + SWRDDHIRES = 0xc07f, + + SWRAMRDOFF = 0xc002, + SWRAMRDON = 0xc003, + SWRAMWRTOFF = 0xc004, + SWRAMWRTON = 0xc005, + SWALTPZOFF = 0xc008, + SWALTPZON = 0xc009, + SWINTCXROMOFF = 0xc006, + SWINTCXROMON = 0xc007, + SWSLOTC3ROMOFF = 0xc00a, + SWSLOTC3ROMON = 0xc00b, + SWBSRBANK2 = 0xc011, + SWBSRREADRAM = 0xc012, + SWRAMRD = 0xc013, + SWRAMWRT = 0xc014, + SWINTCXROM = 0xc015, + SWALTPZ = 0xc016, + SWSLOTC3ROM = 0xc017, + SWSPEAKER = 0xc030, + SWKBD = 0xc000, + SWAKD = 0xc010, + +}; diff --git a/src/mii_video.c b/src/mii_video.c new file mode 100644 index 0000000..8494551 --- /dev/null +++ b/src/mii_video.c @@ -0,0 +1,415 @@ +/* + * mii_video.c + * + * Copyright (C) 2023 Michel Pollet + * + * SPDX-License-Identifier: MIT + */ + +#include +#include +#include +#include + +#include "mii.h" +#include "mii_bank.h" +#include "mii_rom_iiee_video.h" +#include "mii_sw.h" +#include "minipt.h" + +#define VIDEO_RESOLUTION_X 280 +#define VIDEO_RESOLUTION_Y 192 + +#define VIDEO_BYTES_PER_LINE 40 +#define SCREEN_LINE_OFFSET 0x80 +#define VIDEO_SEGMENT_OFFSET 0x28 + + +enum { + // https://rich12345.tripod.com/aiivideo/vbl.html + MII_VBL_DOWN_CYCLES = 12480, + MII_VBL_UP_CYCLES = 4550, + MII_VIDEO_H_CYCLES = 40, + MII_VIDEO_HB_CYCLES = 25, +}; + +/* + * Colors were lifted from + * https://comp.sys.apple2.narkive.com/lTSrj2ZI/apple-ii-colour-rgb + */ +#define HI_RGB(r,g,b) (0xff000000 | ((b) << 16) | ((g) << 8) | (r)) +static const uint32_t lores_colors[] = { + [0x0] = HI_RGB(0x00, 0x00, 0x00), // black + [0x1] = HI_RGB(0xe3, 0x1e, 0x60), // magenta + [0x2] = HI_RGB(0x60, 0x4e, 0xbd), // dark blue + [0x3] = HI_RGB(0xff, 0x44, 0xfd), // purple + [0x4] = HI_RGB(0x00, 0xa3, 0x60), // dark green + [0x5] = HI_RGB(0x9c, 0x9c, 0x9c), // gray 1 + [0x6] = HI_RGB(0x14, 0xcf, 0xfd), // medium blue + [0x7] = HI_RGB(0xd0, 0xc3, 0xff), // light blue + [0x8] = HI_RGB(0x60, 0x72, 0x03), // brown + [0x9] = HI_RGB(0xff, 0x6a, 0x3c), // orange + [0xa] = HI_RGB(0x9c, 0x9c, 0x9c), // gray 2 + [0xb] = HI_RGB(0xff, 0xa0, 0xd0), // pink + [0xc] = HI_RGB(0x14, 0xf5, 0x3c), // light green + [0xd] = HI_RGB(0xd0, 0xdd, 0x8d), // yellow + [0xe] = HI_RGB(0x72, 0xff, 0xd0), // aqua + [0xf] = HI_RGB(0xff, 0xff, 0xff), // white +}; + +enum { + C_BLACK = HI_RGB(0x00, 0x00, 0x00), // black + C_PURPLE = HI_RGB(0xff, 0x44, 0xfd), // purple + C_GREEN = HI_RGB(0x14, 0xf5, 0x3c), // green + C_BLUE = HI_RGB(0x14, 0xcf, 0xfd), // blue + C_ORANGE = HI_RGB(0xff, 0x6a, 0x3c), // orange + C_WHITE = HI_RGB(0xff, 0xff, 0xff), // white +}; + +static const uint32_t hires_colors[] = { + C_BLACK, + C_PURPLE, + C_GREEN, + C_GREEN, + C_PURPLE, + C_BLUE, + C_ORANGE, + C_ORANGE, + C_BLUE, + C_WHITE, +}; + +static const uint32_t dhires_colors[] = { + [0x0] = HI_RGB(0x00, 0x00, 0x00), // black + [0x1] = HI_RGB(0xe3, 0x1e, 0x60), // magenta + [0x2] = HI_RGB(0x60, 0x72, 0x03), // brown + [0x3] = HI_RGB(0xff, 0x6a, 0x3c), // orange + [0x4] = HI_RGB(0x00, 0xa3, 0x60), // dark green + [0x5] = HI_RGB(0x9c, 0x9c, 0x9c), // gray 1 + [0x6] = HI_RGB(0x14, 0xf5, 0x3c), // light green + [0x7] = HI_RGB(0xd0, 0xdd, 0x8d), // yellow + [0x8] = HI_RGB(0x60, 0x4e, 0xbd), // dark blue + [0x9] = HI_RGB(0xff, 0x44, 0xfd), // purple + [0xa] = HI_RGB(0x9c, 0x9c, 0x9c), // gray 2 + [0xb] = HI_RGB(0xff, 0xa0, 0xd0), // pink + [0xc] = HI_RGB(0x14, 0xcf, 0xfd), // medium blue + [0xd] = HI_RGB(0xd0, 0xc3, 0xff), // light blue + [0xe] = HI_RGB(0x72, 0xff, 0xd0), // aqua + [0xf] = HI_RGB(0xff, 0xff, 0xff), // white +}; + +static const uint32_t mono[3][2] = { + { 0xff000000, C_WHITE }, + { 0xff000000, C_GREEN }, + { 0xff000000, C_ORANGE }, +}; + + +/* this 'dims' the colors for every second line of pixels */ +#define C_SCANLINE_MASK 0xffc0c0c0 + +static inline uint16_t +_mii_line_to_video_addr( + uint16_t addr, + uint8_t line) +{ + addr += ((line & 0x07) << 10) | + (((line >> 3) & 7) << 7) | + ((line >> 6) << 5) | ((line >> 6) << 3); + return addr; +} +/* + * This is the state of the video output + * All timings lifted from https://rich12345.tripod.com/aiivideo/vbl.html + * + * This is a 'protothread' basically cooperative scheduling using an + * old compiler trick. It's not a real thread, but it's a way to + * write code that looks like a thread, and is easy to read. + * The 'pt_start' macro starts the thread, and pt_yield() yields + * the thread to the main loop. + * The pt_end() macro ends the thread. + * Remeber you cannot have locals in the thread, they must be + * static or global. + * *everything* before the pt_start call is ran every time, so you can use + * that to reload some sort of state, as here, were we reload all the + * video mode softwsitches. + */ +void +mii_video_run( + mii_t *mii) +{ + // no need to do anything, we're waiting cycles + if (mii->video.wait) { + if (mii->video.wait > mii->cycles) + return; + // extra cycles we waited are kept around for next delay + mii->video.wait = mii->cycles - mii->video.wait; + } + mii_bank_t * main = &mii->bank[MII_BANK_MAIN]; + bool text = !!mii_bank_peek(main, SWTEXT); + bool page2 = !!mii_bank_peek(main, SWPAGE2); + bool col80 = !!mii_bank_peek(main, SW80COL); + bool store80 = !!mii_bank_peek(main, SW80STORE); + bool mixed = !!mii_bank_peek(main, SWMIXED); + bool hires = !!mii_bank_peek(main, SWHIRES); + bool dhires = !!mii_bank_peek(main, SWRDDHIRES); + + pt_start(mii->video.state); + /* + We cheat and draw a whole line at a time, then 'wait' until + horizontal blanking, then wait until vertical blanking. + */ + do { + // 'clear' VBL flag. Flag is 0 during retrace + mii_bank_poke(main, SWVBL, 0x80); + if (mixed && !text) { + text = mii->video.line >= 192 - (4 * 8); + hires = 0; + } + // http://www.1000bit.it/support/manuali/apple/technotes/aiie/tn.aiie.03.html + if (hires && !text && col80 && dhires) { + if (store80) + page2 = 0; + uint8_t reg = mii_bank_peek(main, SWAN3_REGISTER); + uint16_t a = (0x2000 + (0x2000 * page2)); + a = _mii_line_to_video_addr(a, mii->video.line); + uint32_t * screen = mii->video.pixels + + (mii->video.line * MII_VRAM_WIDTH * 2); + uint32_t * l2 = screen + MII_VRAM_WIDTH; + + mii_bank_t * aux = &mii->bank[MII_BANK_AUX]; + + if (reg == 0 || mii->video.color_mode != MII_VIDEO_COLOR) { + for (int x = 0; x < 40; x += 1) { + uint32_t ext = (mii_bank_peek(aux, a + x) & 0x7f) | + ((mii_bank_peek(main, a + x) & 0x7f) << 7); + for (int bi = 0; bi < 14; bi++) { + uint8_t pixel = (ext >> bi) & 1; + uint32_t col = pixel ? + mono[mii->video.color_mode][1] : + mono[mii->video.color_mode][0]; + *screen++ = col; + *l2++ = col & C_SCANLINE_MASK; + } + } + } else { // color mode + int x = 0, dx = 0; + do { + uint64_t run = 0; + // get 8 bytes, so we get 8*7=56 bits for 14 pixels + for (int bx = 0; bx < 8 && x < 80; bx++, x++) { + uint8_t b = mii_bank_peek( + x & 1 ? main : aux, a + (x / 2)); + run |= ((uint64_t)(b & 0x7f) << (bx * 7)); + } + for (int px = 0; px < 14 && dx < 80*2; px++, dx++) { + uint8_t pixel = run & 0xf; + run >>= 4; + uint32_t col = dhires_colors[pixel]; + *screen++ = col; + *screen++ = col; + *screen++ = col; + *screen++ = col; + *l2++ = col & C_SCANLINE_MASK; + *l2++ = col & C_SCANLINE_MASK; + *l2++ = col & C_SCANLINE_MASK; + *l2++ = col & C_SCANLINE_MASK; + } + } while (x < 80); + } + } else if (hires && !text) { + if (store80) + page2 = 0; + uint16_t a = (0x2000 + (0x2000 * page2)); + a = _mii_line_to_video_addr(a, mii->video.line); + uint32_t * screen = mii->video.pixels + + (mii->video.line * MII_VRAM_WIDTH * 2); + uint32_t * l2 = screen + MII_VRAM_WIDTH; + + uint8_t b0 = 0; + uint8_t b1 = mii_bank_peek(main, a + 0); + for (int x = 0; x < 40; x++) { + uint8_t b2 = mii_bank_peek(main, a + x + 1); + // last 2 pixels, current 7 pixels, next 2 pixels + uint16_t run = ((b0 & 0x60) >> ( 5 )) | + ((b1 & 0x7f) << ( 2 )) | + ((b2 & 0x03) << ( 9 )); + int odd = (x & 1) << 1; + int offset = (b1 & 0x80) >> 5; + + if (mii->video.color_mode == MII_VIDEO_COLOR) { + for (int i = 0; i < 7; i++) { + uint8_t left = (run >> (1 + i)) & 1; + uint8_t pixel = (run >> (2 + i)) & 1; + uint8_t right = (run >> (3 + i)) & 1; + + int idx = 0; // black + if (pixel) { + if (left || right) { + idx = 9; // white + } else { + idx = offset + odd + (i & 1) + 1; + } + } else { + if (left && right) { + idx = offset + odd + 1 - (i & 1) + 1; + } + } + uint32_t col = hires_colors[idx]; + *screen++ = col; + *screen++ = col; + *l2++ = col & C_SCANLINE_MASK; + *l2++ = col & C_SCANLINE_MASK; + } + } else { + for (int i = 0; i < 7; i++) { + uint8_t pixel = (run >> (2 + i)) & 1; + uint32_t col = pixel ? + mono[mii->video.color_mode][1] : + mono[mii->video.color_mode][0]; + *screen++ = col; + *screen++ = col; + *l2++ = col & C_SCANLINE_MASK; + *l2++ = col & C_SCANLINE_MASK; + } + } + b0 = b1; + b1 = b2; + } + } else { + if (store80) + page2 = 0; + uint16_t a = (0x400 + (0x400 * page2)); + int i = mii->video.line >> 3; + a += ((i & 0x07) << 7) | ((i >> 3) << 5) | ((i >> 3) << 3); + + mii_bank_t * aux = &mii->bank[MII_BANK_AUX]; + uint32_t * screen = mii->video.pixels + + (mii->video.line * MII_VRAM_WIDTH * 2); + uint32_t * l2 = screen + MII_VRAM_WIDTH; + for (int x = 0; x < 40 + (40 * col80); x++) { + uint8_t c = 0; + if (col80) + c = mii_bank_peek( + x & 1 ? main : aux, a + (x >> 1)); + else + c = mii_bank_peek(main, a + x); + if (text) { + const uint8_t * rom = iie_enhanced_video + (c << 3); + uint8_t bits = rom[mii->video.line & 0x07]; + for (int pi = 0; pi < 7; pi++) { + uint8_t pixel = (bits >> pi) & 1; + uint32_t col = pixel ? + mono[mii->video.color_mode][0] : + mono[mii->video.color_mode][1]; + *screen++ = col; + *l2++ = col & C_SCANLINE_MASK; + if (!col80) { + *screen++ = col; + *l2++ = col & C_SCANLINE_MASK; + } + } + } else { // lores graphics + int lo_line = mii->video.line / 4; + c = c >> ((lo_line & 1) * 4); + uint32_t pixel = lores_colors[c & 0x0f]; + for (int pi = 0; pi < 7; pi++) { + *screen++ = pixel; + *l2++ = pixel & C_SCANLINE_MASK; + if (!col80) { + *screen++ = pixel; + *l2++ = pixel & C_SCANLINE_MASK; + } + } + } + } + } + mii->video.line++; + if (mii->video.line == 192) { + mii->video.line = 0; + mii->video.wait = mii->cycles - mii->video.wait + + MII_VIDEO_H_CYCLES * mii->speed; + pt_yield(mii->video.state); + mii_bank_poke(main, SWVBL, 0x00); + if (mii->video.vbl_irq) + mii->cpu_state.irq = 1; + mii->video.wait = mii->cycles - mii->video.wait + + MII_VBL_UP_CYCLES * mii->speed; + mii->video.frame_count++; + pt_yield(mii->video.state); + } else { + mii->video.wait = mii->cycles - mii->video.wait + + (MII_VIDEO_H_CYCLES + MII_VIDEO_HB_CYCLES) * + mii->speed; + pt_yield(mii->video.state); + } + } while (1); + pt_end(mii->video.state); + return; +} + +bool +mii_access_video( + mii_t *mii, + uint16_t addr, + uint8_t * byte, + bool write) +{ + bool res = false; + mii_bank_t * main = &mii->bank[MII_BANK_MAIN]; + switch (addr) { + case SWALTCHARSETOFF: + case SWALTCHARSETON: + if (!write) break; + res = true; + mii_bank_poke(main, SWALTCHARSET, (addr & 1) << 7); + break; + case SWVBL: + case SW80COL: + case SWTEXT: + case SWMIXED: + case SWPAGE2: + case SWHIRES: + case SWALTCHARSET: + case SWRDDHIRES: + res = true; + if (!write) + *byte = mii_bank_peek(main, addr); + break; + case SW80COLOFF: + case SW80COLON: + if (!write) break; + res = true; + mii_bank_poke(main, SW80COL, (addr & 1) << 7); +// printf("80COL %s\n", on ? "ON" : "OFF"); + break; + case SWDHIRESOFF: // 0xc05f, + case SWDHIRESON: { // = 0xc05e, + res = true; + uint8_t an3 = !!mii_bank_peek(main, SWAN3); + bool an3_on = !!(addr & 1); // 5f is ON, 5e is OFF + uint8_t reg = mii_bank_peek(main, SWAN3_REGISTER); + if (an3_on && !an3) { + uint8_t bit = !!mii_bank_peek(main, SW80COL); + reg = ((reg << 1) | bit) & 3; + printf("VIDEO 80:%d REG now %x\n", bit, reg); + mii_bank_poke(main, SWAN3_REGISTER, reg); + } + mii_bank_poke(main, SWAN3, an3_on); + printf("DHRES IS %s mode:%d\n", + (addr & 1) ? "OFF" : "ON", reg); + mii_bank_poke(main, SWRDDHIRES, (!(addr & 1)) << 7); + } break; + case SWTEXTOFF: + case SWTEXTON: + res = true; + mii_bank_poke(main, SWTEXT, (addr & 1) << 7); + break; + case SWMIXEDOFF: + case SWMIXEDON: + res = true; + mii_bank_poke(main, SWMIXED, (addr & 1) << 7); + break; + } + return res; +} diff --git a/src/mii_video.h b/src/mii_video.h new file mode 100644 index 0000000..dd5fc56 --- /dev/null +++ b/src/mii_video.h @@ -0,0 +1,55 @@ +/* + * mii_video.h + * + * Copyright (C) 2023 Michel Pollet + * + * SPDX-License-Identifier: MIT + */ + +#pragma once + +#include +#include + + +// TODO move VRAM stuff to somewhere else +/* + These are currently way bigger than needed, because they need to be + a power of two to easily map to an opengl texture. + */ +#define MII_VRAM_WIDTH 1024 +#define MII_VRAM_HEIGHT 512 + +#define MII_VIDEO_WIDTH (280 * 2) +#define MII_VIDEO_HEIGHT (192 * 2) + +enum { + MII_VIDEO_COLOR = 0, + MII_VIDEO_GREEN, + MII_VIDEO_AMBER, +}; + +struct mii_t; + +typedef struct mii_video_t { + void * state; // protothread state in mii_video.c + uint8_t line; // current line + bool vbl_irq; // VBL IRQ emabled (set by mouse card) + __uint128_t wait; // 'wait until' cycle marker + uint32_t pixels[MII_VRAM_WIDTH * MII_VRAM_HEIGHT]; + uint32_t frame_count; // incremented every frame + uint32_t frame_drawn; + uint8_t color_mode; // color, green, amber +} mii_video_t; + +bool +mii_access_video( + struct mii_t *mii, + uint16_t addr, + uint8_t * byte, + bool write); +void +mii_video_run( + struct mii_t *mii); + + diff --git a/src/roms/mii_rom_disk2.h b/src/roms/mii_rom_disk2.h new file mode 100644 index 0000000..4dae73f --- /dev/null +++ b/src/roms/mii_rom_disk2.h @@ -0,0 +1,26 @@ +#pragma once +static const unsigned char mii_rom_disk2[] = { + 0xa2, 0x20, 0xa0, 0x00, 0xa2, 0x03, 0x86, 0x3c, 0x8a, 0x0a, 0x24, 0x3c, + 0xf0, 0x10, 0x05, 0x3c, 0x49, 0xff, 0x29, 0x7e, 0xb0, 0x08, 0x4a, 0xd0, + 0xfb, 0x98, 0x9d, 0x56, 0x03, 0xc8, 0xe8, 0x10, 0xe5, 0x20, 0x58, 0xff, + 0xba, 0xbd, 0x00, 0x01, 0x0a, 0x0a, 0x0a, 0x0a, 0x85, 0x2b, 0xaa, 0xbd, + 0x8e, 0xc0, 0xbd, 0x8c, 0xc0, 0xbd, 0x8a, 0xc0, 0xbd, 0x89, 0xc0, 0xa0, + 0x50, 0xbd, 0x80, 0xc0, 0x98, 0x29, 0x03, 0x0a, 0x05, 0x2b, 0xaa, 0xbd, + 0x81, 0xc0, 0xa9, 0x56, 0x20, 0xa8, 0xfc, 0x88, 0x10, 0xeb, 0x85, 0x26, + 0x85, 0x3d, 0x85, 0x41, 0xa9, 0x08, 0x85, 0x27, 0x18, 0x08, 0xbd, 0x8c, + 0xc0, 0x10, 0xfb, 0x49, 0xd5, 0xd0, 0xf7, 0xbd, 0x8c, 0xc0, 0x10, 0xfb, + 0xc9, 0xaa, 0xd0, 0xf3, 0xea, 0xbd, 0x8c, 0xc0, 0x10, 0xfb, 0xc9, 0x96, + 0xf0, 0x09, 0x28, 0x90, 0xdf, 0x49, 0xad, 0xf0, 0x25, 0xd0, 0xd9, 0xa0, + 0x03, 0x85, 0x40, 0xbd, 0x8c, 0xc0, 0x10, 0xfb, 0x2a, 0x85, 0x3c, 0xbd, + 0x8c, 0xc0, 0x10, 0xfb, 0x25, 0x3c, 0x88, 0xd0, 0xec, 0x28, 0xc5, 0x3d, + 0xd0, 0xbe, 0xa5, 0x40, 0xc5, 0x41, 0xd0, 0xb8, 0xb0, 0xb7, 0xa0, 0x56, + 0x84, 0x3c, 0xbc, 0x8c, 0xc0, 0x10, 0xfb, 0x59, 0xd6, 0x02, 0xa4, 0x3c, + 0x88, 0x99, 0x00, 0x03, 0xd0, 0xee, 0x84, 0x3c, 0xbc, 0x8c, 0xc0, 0x10, + 0xfb, 0x59, 0xd6, 0x02, 0xa4, 0x3c, 0x91, 0x26, 0xc8, 0xd0, 0xef, 0xbc, + 0x8c, 0xc0, 0x10, 0xfb, 0x59, 0xd6, 0x02, 0xd0, 0x87, 0xa0, 0x00, 0xa2, + 0x56, 0xca, 0x30, 0xfb, 0xb1, 0x26, 0x5e, 0x00, 0x03, 0x2a, 0x5e, 0x00, + 0x03, 0x2a, 0x91, 0x26, 0xc8, 0xd0, 0xee, 0xe6, 0x27, 0xe6, 0x3d, 0xa5, + 0x3d, 0xcd, 0x00, 0x08, 0xa6, 0x2b, 0x90, 0xdb, 0x4c, 0x01, 0x08, 0x00, + 0x00, 0x00, 0x00, 0x00 +}; +static const unsigned int mii_rom_disk2_len = 256; diff --git a/src/roms/mii_rom_iiee.h b/src/roms/mii_rom_iiee.h new file mode 100644 index 0000000..872b4d1 --- /dev/null +++ b/src/roms/mii_rom_iiee.h @@ -0,0 +1,1370 @@ +#pragma once +static const unsigned char iie_enhanced_rom_bin[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x4c, 0x13, 0xc2, 0xa4, 0x24, 0xa5, 0x25, 0x48, + 0x20, 0x03, 0xce, 0x20, 0xf4, 0xc1, 0xa0, 0x00, 0x68, 0x69, 0x00, 0xc5, + 0x23, 0x90, 0xf0, 0xb0, 0x34, 0xa5, 0x22, 0x85, 0x25, 0xa0, 0x00, 0x84, + 0x24, 0xf0, 0xe4, 0xa5, 0x22, 0x48, 0x20, 0x03, 0xce, 0xa5, 0x28, 0x85, + 0x2a, 0xa5, 0x29, 0x85, 0x2b, 0xa4, 0x21, 0x88, 0x68, 0x69, 0x01, 0xc5, + 0x23, 0xb0, 0x0d, 0x48, 0x20, 0x03, 0xce, 0xb1, 0x28, 0x91, 0x2a, 0x88, + 0x10, 0xf9, 0x30, 0xe1, 0xa0, 0x00, 0x20, 0xf4, 0xc1, 0xa5, 0x25, 0x4c, + 0x03, 0xce, 0xa9, 0x28, 0x85, 0x21, 0xa9, 0x18, 0x85, 0x23, 0xa9, 0x17, + 0x85, 0x25, 0xd0, 0xef, 0xa4, 0x2a, 0x4c, 0xf4, 0xc1, 0x4c, 0xeb, 0xcb, + 0x4c, 0x9a, 0xcc, 0xa4, 0x2a, 0x4c, 0x9d, 0xcc, 0x4c, 0x74, 0xcc, 0x4c, + 0xa0, 0xc2, 0x4c, 0xb0, 0xc2, 0x4c, 0xf2, 0xc2, 0x20, 0x90, 0xcc, 0xad, + 0x7b, 0x05, 0x85, 0x24, 0x8d, 0x7b, 0x04, 0x4c, 0xfe, 0xcd, 0xb4, 0x00, + 0xf0, 0x0f, 0xc0, 0x1b, 0xf0, 0x0e, 0x20, 0x80, 0xcd, 0xb4, 0x00, 0xf0, + 0x04, 0xa9, 0xfd, 0x95, 0x01, 0xb5, 0x01, 0x60, 0xa5, 0x37, 0xc9, 0xc3, + 0xd0, 0xf3, 0x4c, 0x32, 0xc8, 0xa4, 0x24, 0xb1, 0x28, 0x48, 0x29, 0x3f, + 0x09, 0x40, 0x91, 0x28, 0x68, 0x60, 0xa8, 0xa5, 0x28, 0x20, 0xba, 0xca, + 0x90, 0x4c, 0x20, 0x14, 0xce, 0xa0, 0x03, 0xd9, 0xee, 0xc2, 0xd0, 0x03, + 0xb9, 0xa4, 0xc9, 0x88, 0x10, 0xf5, 0x30, 0x3a, 0x20, 0x70, 0xc8, 0x4c, + 0x0a, 0xc2, 0x8a, 0x29, 0x03, 0x85, 0x2f, 0xa5, 0x2a, 0x29, 0x8f, 0x4c, + 0x71, 0xca, 0x20, 0xf0, 0xfc, 0x8a, 0x85, 0x34, 0x60, 0xac, 0x7b, 0x05, + 0x20, 0x44, 0xce, 0x09, 0x80, 0x60, 0xa4, 0x24, 0xa9, 0xa0, 0x2c, 0x1e, + 0xc0, 0x10, 0x06, 0x24, 0x32, 0x30, 0x02, 0xa9, 0x20, 0x4c, 0xa8, 0xcc, + 0xa8, 0xa5, 0x28, 0x20, 0x03, 0xce, 0x28, 0x30, 0x03, 0x4c, 0xc5, 0xfe, + 0x4c, 0xc8, 0xfe, 0x88, 0x30, 0xba, 0x88, 0x30, 0xa5, 0x88, 0x30, 0x9a, + 0x88, 0x30, 0x3d, 0x88, 0x30, 0xe2, 0xa9, 0xc2, 0x48, 0xa9, 0x09, 0x48, + 0xad, 0xfb, 0x04, 0x29, 0xd6, 0xd0, 0x0d, 0x98, 0x18, 0x69, 0x0c, 0x48, + 0x20, 0x50, 0xc8, 0x20, 0xfe, 0xcd, 0x68, 0xa8, 0xa9, 0xc1, 0x48, 0xb9, + 0x44, 0xc2, 0x48, 0x60, 0x18, 0x22, 0xf1, 0x5f, 0x75, 0x02, 0xa8, 0x51, + 0xe1, 0x94, 0xe8, 0xd5, 0x7b, 0x64, 0x67, 0x6a, 0x75, 0x6f, 0x78, 0x72, + 0xe1, 0x89, 0xe8, 0xd5, 0x2c, 0x1f, 0xc0, 0x10, 0x06, 0x20, 0x74, 0xc8, + 0x4c, 0x0a, 0xc2, 0xa8, 0x8a, 0x48, 0x98, 0x48, 0x48, 0x68, 0xc9, 0xff, + 0xf0, 0x04, 0xa9, 0xff, 0xd0, 0x02, 0x68, 0x48, 0x48, 0xa4, 0x24, 0x91, + 0x28, 0xe6, 0x4e, 0xd0, 0x0a, 0xa5, 0x4f, 0xe6, 0x4f, 0x45, 0x4f, 0x29, + 0x40, 0xd0, 0xe2, 0xad, 0x00, 0xc0, 0x10, 0xed, 0x68, 0x68, 0xa4, 0x24, + 0x91, 0x28, 0x68, 0xaa, 0xad, 0x00, 0xc0, 0x8d, 0x10, 0xc0, 0x30, 0xc4, + 0x20, 0x52, 0xc1, 0x2c, 0x1f, 0xc0, 0x10, 0x02, 0x06, 0x21, 0xa5, 0x25, + 0x8d, 0xfb, 0x05, 0x60, 0xa9, 0xff, 0x8d, 0xfb, 0x04, 0xad, 0x5d, 0xc0, + 0xad, 0x5f, 0xc0, 0xad, 0x62, 0xc0, 0x10, 0x03, 0x4c, 0x00, 0xc6, 0xad, + 0x61, 0xc0, 0x10, 0x1a, 0xa0, 0xb0, 0xa9, 0x00, 0x85, 0x3c, 0xa9, 0xbf, + 0x38, 0x85, 0x3d, 0x48, 0xa9, 0xa0, 0x91, 0x3c, 0x88, 0x91, 0x3c, 0x68, + 0xe9, 0x01, 0xc9, 0x01, 0xd0, 0xef, 0x8d, 0x0b, 0xc0, 0x20, 0x89, 0xca, + 0xd0, 0x03, 0x8d, 0x0a, 0xc0, 0x60, 0x88, 0x95, 0x8a, 0x8b, 0xa4, 0x24, + 0xb1, 0x28, 0x2c, 0x1f, 0xc0, 0x30, 0xf2, 0x4c, 0x26, 0xce, 0x00, 0x00, + 0x2c, 0x43, 0xce, 0x70, 0x12, 0x38, 0x90, 0x18, 0xb8, 0x50, 0x0c, 0x01, + 0x88, 0x4a, 0x50, 0x56, 0x5c, 0x4c, 0x76, 0xc3, 0x4c, 0xc3, 0xc3, 0x8d, + 0x7b, 0x06, 0x98, 0x48, 0x8a, 0x48, 0x08, 0xad, 0xfb, 0x04, 0x2c, 0xf8, + 0x07, 0x30, 0x05, 0x09, 0x08, 0x8d, 0xfb, 0x04, 0x20, 0x6d, 0xc3, 0x28, + 0x70, 0x15, 0x90, 0x10, 0xaa, 0x10, 0x0d, 0x20, 0x5b, 0xcd, 0x68, 0xaa, + 0x68, 0xa8, 0xad, 0x7b, 0x06, 0x6c, 0x38, 0x00, 0x4c, 0x7c, 0xc8, 0x4c, + 0x03, 0xc8, 0x20, 0x6d, 0xc3, 0x4c, 0xb4, 0xc9, 0x20, 0x6d, 0xc3, 0x4c, + 0xd6, 0xc9, 0x20, 0x6d, 0xc3, 0x4c, 0xf0, 0xc9, 0xaa, 0xf0, 0x08, 0xca, + 0xd0, 0x07, 0x2c, 0x00, 0xc0, 0x10, 0x04, 0x38, 0x60, 0xa2, 0x03, 0x18, + 0x60, 0xa2, 0xc3, 0x8e, 0xf8, 0x07, 0xae, 0xff, 0xcf, 0x60, 0x48, 0x98, + 0x48, 0xad, 0x13, 0xc0, 0x48, 0xad, 0x14, 0xc0, 0x48, 0x90, 0x08, 0x8d, + 0x02, 0xc0, 0x8d, 0x05, 0xc0, 0xb0, 0x06, 0x8d, 0x04, 0xc0, 0x8d, 0x03, + 0xc0, 0xa0, 0x00, 0xb1, 0x3c, 0x91, 0x42, 0xe6, 0x42, 0xd0, 0x02, 0xe6, + 0x43, 0xa5, 0x3c, 0xc5, 0x3e, 0xa5, 0x3d, 0xe5, 0x3f, 0xe6, 0x3c, 0xd0, + 0x02, 0xe6, 0x3d, 0x90, 0xe6, 0x8d, 0x04, 0xc0, 0x68, 0x10, 0x03, 0x8d, + 0x05, 0xc0, 0x8d, 0x02, 0xc0, 0x68, 0x10, 0x03, 0x8d, 0x03, 0xc0, 0x68, + 0xa8, 0x68, 0x60, 0x48, 0xad, 0xed, 0x03, 0x48, 0xad, 0xee, 0x03, 0x48, + 0x90, 0x08, 0x8d, 0x03, 0xc0, 0x8d, 0x05, 0xc0, 0xb0, 0x06, 0x8d, 0x02, + 0xc0, 0x8d, 0x04, 0xc0, 0x68, 0x8d, 0xee, 0x03, 0x68, 0x8d, 0xed, 0x03, + 0x68, 0x70, 0x05, 0x8d, 0x08, 0xc0, 0x50, 0x03, 0x8d, 0x09, 0xc0, 0x6c, + 0xed, 0x03, 0x00, 0x00, 0x8d, 0x81, 0xc0, 0x4c, 0x7a, 0xfc, 0x2c, 0x15, + 0xc0, 0x8d, 0x07, 0xc0, 0xd8, 0x38, 0x30, 0x01, 0x18, 0x48, 0x48, 0x48, + 0x8a, 0xba, 0xe8, 0xe8, 0xe8, 0xe8, 0x48, 0x98, 0x48, 0xbd, 0x00, 0x01, + 0x29, 0x10, 0xa8, 0xad, 0x18, 0xc0, 0x2d, 0x1c, 0xc0, 0x29, 0x80, 0xf0, + 0x05, 0xa9, 0x20, 0x8d, 0x54, 0xc0, 0x2a, 0x2c, 0x13, 0xc0, 0x10, 0x05, + 0x8d, 0x02, 0xc0, 0x09, 0x20, 0x2c, 0x14, 0xc0, 0x10, 0x05, 0x8d, 0x04, + 0xc0, 0x09, 0x10, 0x2c, 0x12, 0xc0, 0x10, 0x0c, 0x09, 0x0c, 0x2c, 0x11, + 0xc0, 0x10, 0x02, 0x49, 0x06, 0x8d, 0x81, 0xc0, 0x2c, 0x16, 0xc0, 0x10, + 0x0d, 0xba, 0x8e, 0x01, 0x01, 0xae, 0x00, 0x01, 0x9a, 0x8d, 0x08, 0xc0, + 0x09, 0x80, 0x88, 0x30, 0x0c, 0x85, 0x44, 0x68, 0xa8, 0x68, 0xaa, 0x68, + 0x68, 0x68, 0x4c, 0x47, 0xfa, 0x48, 0xad, 0xf8, 0x07, 0x48, 0xa9, 0xc3, + 0x48, 0xa9, 0xf4, 0x48, 0x08, 0x4c, 0x74, 0xfc, 0xad, 0x81, 0xc0, 0x68, + 0x10, 0x07, 0x8d, 0x09, 0xc0, 0xae, 0x01, 0x01, 0x9a, 0xa0, 0x06, 0x10, + 0x06, 0xbe, 0xc1, 0xc4, 0xfe, 0x00, 0xc0, 0x88, 0x30, 0x03, 0x0a, 0xd0, + 0xf2, 0x0a, 0x0a, 0x68, 0xa8, 0xba, 0xa9, 0x40, 0x48, 0xa9, 0xc0, 0x48, + 0xa9, 0x06, 0x69, 0x00, 0x48, 0xa9, 0x8d, 0x48, 0x9a, 0x8a, 0x69, 0x03, + 0xaa, 0x38, 0xe9, 0x07, 0x9d, 0x00, 0x01, 0xe8, 0xa9, 0x01, 0x9d, 0x00, + 0x01, 0x68, 0xaa, 0x68, 0x60, 0x83, 0x8b, 0x8b, 0x05, 0x03, 0x55, 0x00, + 0x20, 0x13, 0xff, 0x84, 0x34, 0xdd, 0xb4, 0xf9, 0xd0, 0x13, 0x20, 0x13, + 0xff, 0xdd, 0xba, 0xf9, 0xf0, 0x0d, 0xbd, 0xba, 0xf9, 0xf0, 0x07, 0xc9, + 0xa4, 0xf0, 0x03, 0xa4, 0x34, 0x18, 0x88, 0x26, 0x44, 0xe0, 0x03, 0xd0, + 0x0d, 0x20, 0xa7, 0xff, 0xa5, 0x3f, 0xf0, 0x01, 0xe8, 0x86, 0x35, 0xa2, + 0x03, 0x88, 0x86, 0x3d, 0xca, 0x10, 0xc9, 0x60, 0x90, 0x48, 0xa9, 0x00, + 0x85, 0x3d, 0x85, 0x3f, 0xa0, 0x50, 0x84, 0x3c, 0xc8, 0x84, 0x3e, 0x20, + 0xd1, 0xc5, 0x18, 0xa5, 0x73, 0xaa, 0xca, 0x86, 0x3e, 0xe5, 0x50, 0x48, + 0xa5, 0x74, 0xa8, 0xe8, 0xd0, 0x01, 0x88, 0x84, 0x3f, 0xe5, 0x51, 0xc5, + 0x6e, 0x90, 0x02, 0xd0, 0x02, 0x38, 0x60, 0x85, 0x74, 0x85, 0x70, 0x85, + 0x3d, 0x85, 0xe9, 0x68, 0x85, 0xe8, 0x85, 0x73, 0x85, 0x6f, 0x85, 0x3c, + 0x20, 0x98, 0xc5, 0xa9, 0x03, 0x20, 0xd6, 0xc5, 0x18, 0x60, 0xa5, 0x9b, + 0x65, 0x50, 0x85, 0x3e, 0xa5, 0x9c, 0x65, 0x51, 0x85, 0x3f, 0xa0, 0x04, + 0xb1, 0x9b, 0x20, 0xef, 0xe0, 0xa5, 0x94, 0x85, 0x3c, 0xa5, 0x95, 0x85, + 0x3d, 0x18, 0x60, 0xa0, 0x4b, 0x20, 0x79, 0xc5, 0xd0, 0xf9, 0x69, 0xfe, + 0xb0, 0xf5, 0xa0, 0x21, 0x20, 0x79, 0xc5, 0xc8, 0xc8, 0x88, 0xd0, 0xfd, + 0x90, 0x05, 0xa0, 0x32, 0x88, 0xd0, 0xfd, 0xac, 0x20, 0xc0, 0xa0, 0x2c, + 0xca, 0x60, 0xa2, 0x08, 0x48, 0x20, 0x98, 0xc5, 0x68, 0x2a, 0xa0, 0x3a, + 0xca, 0xd0, 0xf5, 0x60, 0x20, 0x9b, 0xc5, 0x88, 0xad, 0x60, 0xc0, 0x45, + 0x2f, 0x10, 0xf8, 0x45, 0x2f, 0x85, 0x2f, 0xc0, 0x80, 0x60, 0x20, 0x67, + 0xc5, 0xa0, 0x27, 0xa2, 0x00, 0x41, 0x3c, 0x48, 0xa1, 0x3c, 0x20, 0xc8, + 0xc5, 0x20, 0xba, 0xfc, 0xa0, 0x1d, 0x68, 0x90, 0xee, 0xa0, 0x22, 0x20, + 0xc8, 0xc5, 0xf0, 0x08, 0xa2, 0x10, 0x0a, 0x20, 0x74, 0xc5, 0xd0, 0xfa, + 0x60, 0x20, 0x98, 0xc5, 0xa9, 0x16, 0x20, 0x67, 0xc5, 0x85, 0x2e, 0x20, + 0x98, 0xc5, 0xa0, 0x24, 0x20, 0x9b, 0xc5, 0xb0, 0xf9, 0x20, 0x9b, 0xc5, + 0xa0, 0x3b, 0x20, 0x8a, 0xc5, 0x81, 0x3c, 0x45, 0x2e, 0x85, 0x2e, 0x20, + 0xba, 0xfc, 0xa0, 0x35, 0x90, 0xf0, 0x20, 0x8a, 0xc5, 0xc5, 0x2e, 0x60, + 0x8d, 0x50, 0xc0, 0xa0, 0x04, 0xa2, 0x00, 0x18, 0x79, 0xb4, 0xc7, 0x95, + 0x00, 0xe8, 0xd0, 0xf7, 0x18, 0x79, 0xb4, 0xc7, 0xd5, 0x00, 0xd0, 0x10, + 0xe8, 0xd0, 0xf5, 0x6a, 0x2c, 0x19, 0xc0, 0x10, 0x02, 0x49, 0xa5, 0x88, + 0x10, 0xe1, 0x30, 0x06, 0x55, 0x00, 0x18, 0x4c, 0xcd, 0xc6, 0x86, 0x01, + 0x86, 0x02, 0x86, 0x03, 0xa2, 0x04, 0x86, 0x04, 0xe6, 0x01, 0xa8, 0x8d, + 0x83, 0xc0, 0x8d, 0x83, 0xc0, 0xa5, 0x01, 0x29, 0xf0, 0xc9, 0xc0, 0xd0, + 0x0c, 0xad, 0x8b, 0xc0, 0xad, 0x8b, 0xc0, 0xa5, 0x01, 0x69, 0x0f, 0xd0, + 0x02, 0xa5, 0x01, 0x85, 0x03, 0x98, 0xa0, 0x00, 0x18, 0x7d, 0xb4, 0xc7, + 0x91, 0x02, 0xca, 0x10, 0x02, 0xa2, 0x04, 0xc8, 0xd0, 0xf2, 0xe6, 0x01, + 0xd0, 0xcc, 0xe6, 0x01, 0xa8, 0xad, 0x83, 0xc0, 0xad, 0x83, 0xc0, 0xa5, + 0x01, 0x29, 0xf0, 0xc9, 0xc0, 0xd0, 0x09, 0xad, 0x8b, 0xc0, 0xa5, 0x01, + 0x69, 0x0f, 0xd0, 0x02, 0xa5, 0x01, 0x85, 0x03, 0x98, 0xa0, 0x00, 0x18, + 0x7d, 0xb4, 0xc7, 0x51, 0x02, 0xd0, 0x35, 0xb1, 0x02, 0xca, 0x10, 0x02, + 0xa2, 0x04, 0xc8, 0xd0, 0xee, 0xe6, 0x01, 0xd0, 0xcb, 0x6a, 0x2c, 0x19, + 0xc0, 0x10, 0x02, 0x49, 0xa5, 0xc6, 0x04, 0x10, 0x87, 0xaa, 0x20, 0x8d, + 0xc9, 0xd0, 0x07, 0x0e, 0x00, 0x0c, 0x0a, 0xcd, 0x00, 0x0c, 0xd0, 0x76, + 0xcd, 0x00, 0x08, 0xf0, 0x71, 0x8a, 0x8d, 0x09, 0xc0, 0x4c, 0x03, 0xc6, + 0x38, 0xaa, 0xad, 0x13, 0xc0, 0xb8, 0x10, 0x03, 0x2c, 0xb4, 0xc7, 0xa9, + 0xa0, 0xa0, 0x06, 0x99, 0xfe, 0xbf, 0x99, 0x06, 0xc0, 0x88, 0x88, 0xd0, + 0xf6, 0x8d, 0x51, 0xc0, 0x8d, 0x54, 0xc0, 0x99, 0x00, 0x04, 0x99, 0x00, + 0x05, 0x99, 0x00, 0x06, 0x99, 0x00, 0x07, 0xc8, 0xd0, 0xf1, 0x8a, 0xf0, + 0x27, 0xa0, 0x03, 0xb0, 0x02, 0xa0, 0x05, 0xa9, 0xaa, 0x50, 0x03, 0x8d, + 0xb0, 0x05, 0xb9, 0xea, 0xc7, 0x99, 0xb1, 0x05, 0x88, 0x10, 0xf7, 0xa0, + 0x10, 0x8a, 0x4a, 0xaa, 0xa9, 0x58, 0x2a, 0x99, 0xb6, 0x05, 0x88, 0x88, + 0xd0, 0xf3, 0xf0, 0xfe, 0xa0, 0x02, 0xb9, 0xf0, 0xc7, 0x90, 0x03, 0xb9, + 0xf3, 0xc7, 0x99, 0xb8, 0x05, 0x88, 0x10, 0xf2, 0x30, 0xfe, 0xa0, 0x01, + 0xa9, 0x7f, 0x6a, 0xbe, 0xb9, 0xc7, 0xf0, 0x0f, 0x90, 0x03, 0xbe, 0xc9, + 0xc7, 0x9d, 0xff, 0xbf, 0xc8, 0xd0, 0xef, 0xae, 0x30, 0xc0, 0x2a, 0x88, + 0xbe, 0xd9, 0xc7, 0xf0, 0x13, 0x30, 0xf4, 0x2a, 0x90, 0x07, 0x1e, 0x00, + 0xc0, 0x90, 0x17, 0xb0, 0xee, 0x1e, 0x00, 0xc0, 0xb0, 0x10, 0x90, 0xe7, + 0x2a, 0xc8, 0x38, 0xe9, 0x01, 0xb0, 0xcb, 0x88, 0xd0, 0x0b, 0xa0, 0x09, + 0xd0, 0xc2, 0xa2, 0x00, 0xc0, 0x0a, 0x4c, 0xd7, 0xc6, 0x46, 0x80, 0xd0, + 0xb5, 0xa9, 0xa0, 0xa0, 0x00, 0x99, 0x00, 0x04, 0x99, 0x00, 0x05, 0x99, + 0x00, 0x06, 0x99, 0x00, 0x07, 0xc8, 0xd0, 0xf1, 0xad, 0x61, 0xc0, 0x2d, + 0x62, 0xc0, 0x0a, 0xe6, 0xff, 0xa5, 0xff, 0x90, 0x03, 0x4c, 0x00, 0xc6, + 0xad, 0x51, 0xc0, 0xa0, 0x08, 0xb9, 0xf6, 0xc7, 0x99, 0xb8, 0x05, 0x88, + 0x10, 0xf7, 0x30, 0xe0, 0x53, 0x43, 0x2b, 0x29, 0x07, 0x00, 0x89, 0x31, + 0x03, 0x05, 0x09, 0x0b, 0x01, 0x00, 0x83, 0x51, 0x53, 0x55, 0x57, 0x0f, + 0x0d, 0x00, 0x81, 0x31, 0x04, 0x06, 0x0a, 0x0c, 0x02, 0x00, 0x84, 0x52, + 0x54, 0x56, 0x58, 0x10, 0x0e, 0x00, 0x11, 0xff, 0x13, 0x14, 0x16, 0x17, + 0x18, 0x00, 0x12, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x00, 0xd2, 0xc1, + 0xcd, 0xa0, 0xda, 0xd0, 0xcd, 0xcd, 0xd5, 0xc9, 0xcf, 0xd5, 0xd3, 0xf9, + 0xf3, 0xf4, 0xe5, 0xed, 0xa0, 0xcf, 0xcb, 0x00, 0x4c, 0xb0, 0xc9, 0x20, + 0xf4, 0xce, 0x20, 0x2a, 0xc8, 0x20, 0x2e, 0xcd, 0xa9, 0x01, 0x8d, 0xfb, + 0x04, 0x20, 0x90, 0xca, 0xd0, 0x08, 0x06, 0x21, 0x8d, 0x01, 0xc0, 0x8d, + 0x0d, 0xc0, 0x8d, 0x0f, 0xc0, 0x20, 0x90, 0xcc, 0xac, 0x7b, 0x05, 0x4c, + 0x7e, 0xc8, 0xa9, 0x07, 0x85, 0x36, 0xa9, 0xc3, 0x85, 0x37, 0xa9, 0x05, + 0x85, 0x38, 0xa9, 0xc3, 0x85, 0x39, 0x60, 0xe6, 0x4e, 0xd0, 0x02, 0xe6, + 0x4f, 0xad, 0x00, 0xc0, 0x10, 0xf5, 0x8d, 0x10, 0xc0, 0x60, 0x00, 0x00, + 0x00, 0x4c, 0x50, 0xc3, 0xa5, 0x25, 0x8d, 0xfb, 0x05, 0xa4, 0x24, 0xcc, + 0x7b, 0x04, 0xf0, 0x03, 0x8c, 0x7b, 0x05, 0xa5, 0x21, 0x18, 0xed, 0x7b, + 0x05, 0xb0, 0x05, 0xa0, 0x00, 0x8c, 0x7b, 0x05, 0xac, 0x7b, 0x05, 0x60, + 0xa4, 0x35, 0x18, 0xb0, 0x38, 0x8d, 0x7b, 0x06, 0x98, 0x48, 0x8a, 0x48, + 0xb0, 0x5e, 0x20, 0x50, 0xc8, 0xad, 0x7b, 0x06, 0xc9, 0x8d, 0xd0, 0x18, + 0xae, 0x00, 0xc0, 0x10, 0x13, 0xe0, 0x93, 0xd0, 0x0f, 0x2c, 0x10, 0xc0, + 0xae, 0x00, 0xc0, 0x10, 0xfb, 0xe0, 0x83, 0xf0, 0x03, 0x2c, 0x10, 0xc0, + 0x29, 0x7f, 0xc9, 0x20, 0xb0, 0x06, 0x20, 0xd2, 0xca, 0x4c, 0xbd, 0xc8, + 0xad, 0x7b, 0x06, 0x20, 0x38, 0xce, 0xc8, 0x8c, 0x7b, 0x05, 0xc4, 0x21, + 0x90, 0x03, 0x20, 0x51, 0xcb, 0xad, 0xfb, 0x04, 0x29, 0xf7, 0x8d, 0xfb, + 0x04, 0xad, 0x7b, 0x05, 0x2c, 0x1f, 0xc0, 0x10, 0x02, 0xa9, 0x00, 0x85, + 0x24, 0x8d, 0x7b, 0x04, 0x68, 0xaa, 0x68, 0xa8, 0xad, 0x7b, 0x06, 0x60, + 0xa4, 0x24, 0xad, 0x7b, 0x06, 0x91, 0x28, 0x20, 0x50, 0xc8, 0x20, 0x26, + 0xce, 0x20, 0x3b, 0xc8, 0x8d, 0x7b, 0x06, 0x20, 0x26, 0xce, 0xa8, 0xad, + 0xfb, 0x04, 0x29, 0x08, 0xf0, 0xcb, 0xc0, 0x8d, 0xd0, 0x08, 0xad, 0xfb, + 0x04, 0x29, 0xf7, 0x8d, 0xfb, 0x04, 0xc0, 0x9b, 0xf0, 0x11, 0xc0, 0x95, + 0xd0, 0xb7, 0xac, 0x7b, 0x05, 0x20, 0x44, 0xce, 0x09, 0x80, 0x8d, 0x7b, + 0x06, 0xd0, 0xaa, 0x20, 0xb1, 0xce, 0x20, 0x3b, 0xc8, 0x20, 0xc4, 0xce, + 0x20, 0x14, 0xce, 0x29, 0x7f, 0xa0, 0x10, 0xd9, 0x7c, 0xc9, 0xf0, 0x05, + 0x88, 0x10, 0xf8, 0x30, 0x0f, 0xb9, 0x6b, 0xc9, 0x29, 0x7f, 0x20, 0xd6, + 0xca, 0xb9, 0x6b, 0xc9, 0x30, 0xd9, 0x10, 0xa2, 0xa8, 0xad, 0xfb, 0x04, + 0xc0, 0x11, 0xd0, 0x0b, 0x20, 0x4d, 0xcd, 0xa9, 0x98, 0x8d, 0x7b, 0x06, + 0x4c, 0xc5, 0xc8, 0xc0, 0x05, 0xd0, 0x08, 0x29, 0xdf, 0x8d, 0xfb, 0x04, + 0x4c, 0xe6, 0xc8, 0xc0, 0x04, 0xd0, 0xf9, 0x09, 0x20, 0xd0, 0xf2, 0x0c, + 0x1c, 0x08, 0x0a, 0x1f, 0x1d, 0x0b, 0x9f, 0x88, 0x9c, 0x8a, 0x11, 0x12, + 0x88, 0x8a, 0x9f, 0x9c, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x49, + 0x4a, 0x4b, 0x4d, 0x34, 0x38, 0x08, 0x0a, 0x0b, 0x15, 0x2c, 0x13, 0xc0, + 0x30, 0x11, 0xa9, 0xee, 0x8d, 0x05, 0xc0, 0x8d, 0x03, 0xc0, 0x8d, 0x00, + 0x0c, 0x8d, 0x00, 0x08, 0xcd, 0x00, 0x0c, 0x60, 0xca, 0xcb, 0xcd, 0xc9, + 0x00, 0x00, 0xad, 0x7b, 0x06, 0x4c, 0x56, 0xc3, 0xa9, 0x83, 0xd0, 0x02, + 0xa9, 0x81, 0x48, 0x20, 0x90, 0xca, 0xf0, 0x04, 0x68, 0xa2, 0x09, 0x60, + 0x68, 0x8d, 0xfb, 0x04, 0x8d, 0x01, 0xc0, 0x8d, 0x0d, 0xc0, 0x8d, 0x0f, + 0xc0, 0x20, 0xd4, 0xce, 0x20, 0x90, 0xcc, 0x4c, 0x1f, 0xca, 0x20, 0xd4, + 0xce, 0x20, 0x3b, 0xc8, 0x29, 0x7f, 0x8d, 0x7b, 0x06, 0xa2, 0x00, 0xad, + 0xfb, 0x04, 0x29, 0x02, 0xf0, 0x02, 0xa2, 0xc3, 0xad, 0x7b, 0x06, 0x60, + 0x29, 0x7f, 0xaa, 0x20, 0xd4, 0xce, 0xa9, 0x08, 0x2c, 0xfb, 0x04, 0xd0, + 0x32, 0x8a, 0x2c, 0x2e, 0xca, 0xf0, 0x50, 0xac, 0x7b, 0x05, 0x24, 0x32, + 0x10, 0x02, 0x09, 0x80, 0x20, 0x70, 0xce, 0xc8, 0x8c, 0x7b, 0x05, 0xc4, + 0x21, 0x90, 0x08, 0xa9, 0x00, 0x8d, 0x7b, 0x05, 0x20, 0xd8, 0xcb, 0xa5, + 0x28, 0x8d, 0x7b, 0x07, 0xa5, 0x29, 0x8d, 0xfb, 0x07, 0x20, 0x1f, 0xce, + 0xa2, 0x00, 0x60, 0x20, 0x1f, 0xce, 0x8a, 0x38, 0xe9, 0x20, 0x2c, 0xfb, + 0x06, 0x30, 0x30, 0x8d, 0xfb, 0x05, 0x85, 0x25, 0x20, 0xba, 0xca, 0xad, + 0xfb, 0x06, 0x8d, 0x7b, 0x05, 0xa9, 0xf7, 0x2d, 0xfb, 0x04, 0x8d, 0xfb, + 0x04, 0xd0, 0xcc, 0x20, 0x1f, 0xce, 0x8a, 0xc9, 0x1e, 0xf0, 0x06, 0x20, + 0xd6, 0xca, 0x4c, 0x1f, 0xca, 0xa9, 0x08, 0x0d, 0xfb, 0x04, 0x8d, 0xfb, + 0x04, 0xa9, 0xff, 0x8d, 0xfb, 0x06, 0x4c, 0x29, 0xca, 0xaa, 0xa5, 0x2a, + 0xa0, 0x03, 0xe0, 0x8a, 0xf0, 0x0b, 0x4a, 0x90, 0x08, 0x4a, 0x4a, 0x09, + 0x20, 0x88, 0xd0, 0xfa, 0xc8, 0x88, 0xd0, 0xf2, 0x60, 0x20, 0xb7, 0xf8, + 0xd0, 0x02, 0xc8, 0x60, 0xad, 0x1c, 0xc0, 0x0a, 0xa9, 0x88, 0x2c, 0x18, + 0xc0, 0x8d, 0x01, 0xc0, 0x08, 0x8d, 0x55, 0xc0, 0xac, 0x00, 0x04, 0x8d, + 0x00, 0x04, 0xad, 0x00, 0x04, 0x8c, 0x00, 0x04, 0x28, 0xb0, 0x03, 0x8d, + 0x54, 0xc0, 0x30, 0x03, 0x8d, 0x00, 0xc0, 0xc9, 0x88, 0x60, 0x48, 0x4a, + 0x29, 0x03, 0x09, 0x04, 0x85, 0x29, 0x68, 0x29, 0x18, 0x90, 0x02, 0x69, + 0x7f, 0x85, 0x28, 0x0a, 0x0a, 0x05, 0x28, 0x85, 0x28, 0x60, 0x2c, 0x06, + 0xcb, 0x50, 0xb8, 0x8d, 0x7b, 0x07, 0x48, 0x98, 0x48, 0xac, 0x7b, 0x07, + 0xc0, 0x05, 0x90, 0x13, 0xb9, 0xb4, 0xcb, 0xf0, 0x0e, 0x50, 0x12, 0x30, + 0x10, 0x8d, 0x7b, 0x07, 0xad, 0xfb, 0x04, 0x29, 0x28, 0xf0, 0x03, 0x38, + 0xb0, 0x09, 0xad, 0x7b, 0x07, 0x09, 0x80, 0x20, 0x07, 0xcb, 0x18, 0x68, + 0xa8, 0x68, 0x60, 0x48, 0xb9, 0x99, 0xcb, 0x48, 0x60, 0xad, 0xfb, 0x04, + 0x10, 0x05, 0x29, 0xef, 0x8d, 0xfb, 0x04, 0x60, 0xad, 0xfb, 0x04, 0x10, + 0xfa, 0x09, 0x10, 0xd0, 0xf3, 0xa9, 0x40, 0x20, 0x34, 0xcb, 0xa0, 0xc0, + 0xa9, 0x0c, 0x20, 0x34, 0xcb, 0xad, 0x30, 0xc0, 0x88, 0xd0, 0xf5, 0x60, + 0x38, 0x48, 0xe9, 0x01, 0xd0, 0xfc, 0x68, 0xe9, 0x01, 0xd0, 0xf6, 0x60, + 0xce, 0x7b, 0x05, 0x10, 0x0b, 0xa5, 0x21, 0x8d, 0x7b, 0x05, 0xce, 0x7b, + 0x05, 0x20, 0x79, 0xcb, 0x60, 0xa9, 0x00, 0x8d, 0x7b, 0x05, 0xad, 0xfb, + 0x04, 0x30, 0x03, 0x20, 0xd8, 0xcb, 0x60, 0xa5, 0x22, 0x85, 0x25, 0xa9, + 0x00, 0x8d, 0x7b, 0x05, 0x4c, 0xfe, 0xcd, 0xee, 0x7b, 0x05, 0xad, 0x7b, + 0x05, 0xc5, 0x21, 0x90, 0x03, 0x20, 0x51, 0xcb, 0x60, 0xa5, 0x22, 0xc5, + 0x25, 0xb0, 0x1e, 0xc6, 0x25, 0x4c, 0xfe, 0xcd, 0xad, 0xfb, 0x04, 0x10, + 0x02, 0x29, 0xfb, 0xa0, 0xff, 0xd0, 0x09, 0xad, 0xfb, 0x04, 0x10, 0x02, + 0x09, 0x04, 0xa0, 0x7f, 0x8d, 0xfb, 0x04, 0x84, 0x32, 0x60, 0x0c, 0x17, + 0x20, 0x3f, 0x00, 0xd7, 0x73, 0x8f, 0x50, 0x83, 0x8e, 0x00, 0xe9, 0xfb, + 0x00, 0x00, 0x4c, 0xd3, 0xea, 0x3c, 0x5e, 0x95, 0x43, 0x6a, 0x99, 0x00, + 0x78, 0x4b, 0x4b, 0xcb, 0xcb, 0x00, 0xcb, 0x4c, 0x4c, 0xcb, 0x4b, 0x4b, + 0x00, 0x4c, 0x4c, 0x00, 0x00, 0x4d, 0x4b, 0x4b, 0x4d, 0x4b, 0x4c, 0x4d, + 0x4b, 0x4c, 0x00, 0x4b, 0xa0, 0x00, 0xf0, 0x15, 0xe6, 0x25, 0xa5, 0x25, + 0x8d, 0xfb, 0x05, 0xc5, 0x23, 0xb0, 0x03, 0x4c, 0x03, 0xce, 0xce, 0xfb, + 0x05, 0xc6, 0x25, 0xa0, 0x01, 0x8a, 0x48, 0x8c, 0x7b, 0x07, 0xa5, 0x21, + 0x48, 0x2c, 0x1f, 0xc0, 0x10, 0x1c, 0x8d, 0x01, 0xc0, 0x4a, 0xaa, 0xa5, + 0x20, 0x4a, 0xb8, 0x90, 0x03, 0x2c, 0x06, 0xcb, 0x2a, 0x45, 0x21, 0x4a, + 0x70, 0x03, 0xb0, 0x01, 0xca, 0x86, 0x21, 0xad, 0x1f, 0xc0, 0x08, 0xa6, + 0x22, 0x98, 0xd0, 0x03, 0xa6, 0x23, 0xca, 0x8a, 0x20, 0x03, 0xce, 0xa5, + 0x28, 0x85, 0x2a, 0xa5, 0x29, 0x85, 0x2b, 0xad, 0x7b, 0x07, 0xf0, 0x32, + 0xe8, 0xe4, 0x23, 0xb0, 0x32, 0x8a, 0x20, 0x03, 0xce, 0xa4, 0x21, 0x28, + 0x08, 0x10, 0x1e, 0xad, 0x55, 0xc0, 0x98, 0xf0, 0x07, 0xb1, 0x28, 0x91, + 0x2a, 0x88, 0xd0, 0xf9, 0x70, 0x04, 0xb1, 0x28, 0x91, 0x2a, 0xad, 0x54, + 0xc0, 0xa4, 0x21, 0xb0, 0x04, 0xb1, 0x28, 0x91, 0x2a, 0x88, 0x10, 0xf9, + 0x30, 0xc1, 0xca, 0xe4, 0x22, 0x10, 0xce, 0x28, 0x68, 0x85, 0x21, 0x20, + 0x96, 0xcc, 0x20, 0xfe, 0xcd, 0x68, 0xaa, 0x60, 0x20, 0x9a, 0xcc, 0xa5, + 0x25, 0x48, 0x10, 0x06, 0x20, 0x03, 0xce, 0x20, 0x96, 0xcc, 0xe6, 0x25, + 0xa5, 0x25, 0xc5, 0x23, 0x90, 0xf2, 0x68, 0x85, 0x25, 0x4c, 0xfe, 0xcd, + 0x20, 0x5f, 0xcb, 0x4c, 0x74, 0xcc, 0xa0, 0x00, 0xf0, 0x03, 0xac, 0x7b, + 0x05, 0xa5, 0x32, 0x29, 0x80, 0x09, 0x20, 0x2c, 0x1f, 0xc0, 0x30, 0x15, + 0x91, 0x28, 0xc8, 0xc4, 0x21, 0x90, 0xf9, 0x60, 0x86, 0x2a, 0xa2, 0xd8, + 0xa0, 0x14, 0xa5, 0x32, 0x29, 0xa0, 0x4c, 0xd5, 0xcc, 0x86, 0x2a, 0x48, + 0x98, 0x48, 0x38, 0xe5, 0x21, 0xaa, 0x98, 0x4a, 0xa8, 0x68, 0x45, 0x20, + 0x6a, 0xb0, 0x03, 0x10, 0x01, 0xc8, 0x68, 0xb0, 0x0b, 0x2c, 0x55, 0xc0, + 0x91, 0x28, 0x2c, 0x54, 0xc0, 0xe8, 0xf0, 0x06, 0x91, 0x28, 0xc8, 0xe8, + 0xd0, 0xef, 0xa6, 0x2a, 0x38, 0x60, 0xad, 0xfb, 0x04, 0x30, 0x4d, 0x20, + 0x31, 0xcd, 0x2c, 0x1f, 0xc0, 0x10, 0x12, 0x20, 0x91, 0xcd, 0x90, 0x0d, + 0x20, 0x90, 0xca, 0xd0, 0x3b, 0x2c, 0x1f, 0xc0, 0x30, 0x03, 0x20, 0xc4, + 0xcd, 0xad, 0x7b, 0x05, 0x18, 0x65, 0x20, 0x2c, 0x1f, 0xc0, 0x30, 0x06, + 0xc9, 0x28, 0x90, 0x02, 0xa9, 0x27, 0x8d, 0x7b, 0x05, 0x85, 0x24, 0xa5, + 0x25, 0x20, 0xba, 0xca, 0x2c, 0x1f, 0xc0, 0x10, 0x05, 0x20, 0x71, 0xcd, + 0xf0, 0x03, 0x20, 0x6d, 0xcd, 0xa9, 0x00, 0x2c, 0x1a, 0xc0, 0x30, 0x02, + 0xa9, 0x14, 0x85, 0x22, 0x60, 0xad, 0xfb, 0x04, 0x09, 0x01, 0xd0, 0x05, + 0xad, 0xfb, 0x04, 0x29, 0xfe, 0x8d, 0xfb, 0x04, 0x60, 0xad, 0xfb, 0x04, + 0x30, 0x1a, 0x20, 0x2e, 0xcd, 0x20, 0x80, 0xcd, 0x20, 0x64, 0xcd, 0xa9, + 0xfd, 0x85, 0x39, 0xa9, 0x1b, 0x85, 0x38, 0x60, 0xa9, 0xfd, 0x85, 0x37, + 0xa9, 0xf0, 0x85, 0x36, 0x60, 0xa9, 0x28, 0xd0, 0x02, 0xa9, 0x50, 0x85, + 0x21, 0xa9, 0x18, 0x85, 0x23, 0xa9, 0x00, 0x85, 0x22, 0x85, 0x20, 0x60, + 0x2c, 0x1f, 0xc0, 0x10, 0x03, 0x20, 0xef, 0xcc, 0x8d, 0x0e, 0xc0, 0xa9, + 0xff, 0x8d, 0xfb, 0x04, 0x60, 0x8a, 0x48, 0xa2, 0x17, 0x8d, 0x01, 0xc0, + 0x8a, 0x20, 0xba, 0xca, 0xa0, 0x27, 0x84, 0x2a, 0x98, 0x4a, 0xb0, 0x03, + 0x2c, 0x55, 0xc0, 0xa8, 0xb1, 0x28, 0x2c, 0x54, 0xc0, 0xa4, 0x2a, 0x91, + 0x28, 0x88, 0x10, 0xea, 0xca, 0x30, 0x04, 0xe4, 0x22, 0xb0, 0xdd, 0x8d, + 0x00, 0xc0, 0x8d, 0x0c, 0xc0, 0x4c, 0xf8, 0xcd, 0x8a, 0x48, 0xa2, 0x17, + 0x8a, 0x20, 0xba, 0xca, 0xa0, 0x00, 0x8d, 0x01, 0xc0, 0xb1, 0x28, 0x84, + 0x2a, 0x48, 0x98, 0x4a, 0xb0, 0x03, 0x8d, 0x55, 0xc0, 0xa8, 0x68, 0x91, + 0x28, 0x8d, 0x54, 0xc0, 0xa4, 0x2a, 0xc8, 0xc0, 0x28, 0x90, 0xe6, 0x20, + 0xb0, 0xcc, 0xca, 0x30, 0x04, 0xe4, 0x22, 0xb0, 0xd3, 0x8d, 0x0d, 0xc0, + 0x20, 0xfe, 0xcd, 0x68, 0xaa, 0x60, 0xa5, 0x25, 0x8d, 0xfb, 0x05, 0x20, + 0xba, 0xca, 0xa5, 0x20, 0x2c, 0x1f, 0xc0, 0x10, 0x01, 0x4a, 0x18, 0x65, + 0x28, 0x85, 0x28, 0x60, 0xc9, 0xe1, 0x90, 0x06, 0xc9, 0xfb, 0xb0, 0x02, + 0x29, 0xdf, 0x60, 0xad, 0xfb, 0x04, 0x29, 0x10, 0xd0, 0x11, 0x48, 0x98, + 0x48, 0xac, 0x7b, 0x05, 0x20, 0x44, 0xce, 0x49, 0x80, 0x20, 0x70, 0xce, + 0x68, 0xa8, 0x68, 0x60, 0x48, 0x24, 0x32, 0x30, 0x02, 0x29, 0x7f, 0x20, + 0x70, 0xce, 0x68, 0x60, 0xb1, 0x28, 0x2c, 0x1f, 0xc0, 0x10, 0x19, 0x8d, + 0x01, 0xc0, 0x84, 0x2a, 0x98, 0x45, 0x20, 0x6a, 0xb0, 0x04, 0xad, 0x55, + 0xc0, 0xc8, 0x98, 0x4a, 0xa8, 0xb1, 0x28, 0x2c, 0x54, 0xc0, 0xa4, 0x2a, + 0x2c, 0x1e, 0xc0, 0x10, 0x06, 0xc9, 0x20, 0xb0, 0x02, 0x09, 0x40, 0x60, + 0x48, 0x29, 0xff, 0x30, 0x16, 0xad, 0xfb, 0x04, 0x6a, 0x68, 0x48, 0x90, + 0x0e, 0x2c, 0x1e, 0xc0, 0x10, 0x09, 0x49, 0x40, 0x2c, 0xac, 0xce, 0xf0, + 0x02, 0x49, 0x40, 0x2c, 0x1f, 0xc0, 0x10, 0x1d, 0x8d, 0x01, 0xc0, 0x48, + 0x84, 0x2a, 0x98, 0x45, 0x20, 0x4a, 0xb0, 0x04, 0xad, 0x55, 0xc0, 0xc8, + 0x98, 0x4a, 0xa8, 0x68, 0x91, 0x28, 0xad, 0x54, 0xc0, 0xa4, 0x2a, 0x68, + 0x60, 0x91, 0x28, 0x68, 0x60, 0x48, 0x98, 0x48, 0xac, 0x7b, 0x05, 0x20, + 0x44, 0xce, 0x8d, 0x7b, 0x06, 0x29, 0x80, 0x49, 0xab, 0x4c, 0xcd, 0xce, + 0x48, 0x98, 0x48, 0xac, 0x7b, 0x05, 0xad, 0x7b, 0x06, 0x20, 0x70, 0xce, + 0x68, 0xa8, 0x68, 0x60, 0x20, 0x71, 0xcd, 0xa9, 0xff, 0x85, 0x32, 0xad, + 0xfb, 0x04, 0x29, 0x04, 0xf0, 0x02, 0x46, 0x32, 0xad, 0x7b, 0x07, 0x85, + 0x28, 0xad, 0xfb, 0x07, 0x85, 0x29, 0xad, 0xfb, 0x05, 0x85, 0x25, 0x60, + 0x2c, 0x12, 0xc0, 0x10, 0x3d, 0xa9, 0x06, 0xcd, 0xb3, 0xfb, 0xf0, 0x36, + 0xa2, 0x03, 0x2c, 0x11, 0xc0, 0x30, 0x02, 0xa2, 0x0b, 0x8d, 0xb3, 0xfb, + 0x2c, 0x80, 0xc0, 0xad, 0xb3, 0xfb, 0xc9, 0x06, 0xf0, 0x01, 0xe8, 0x2c, + 0x81, 0xc0, 0x2c, 0x81, 0xc0, 0xa0, 0x00, 0xa9, 0xf8, 0x85, 0x37, 0x84, + 0x36, 0xb1, 0x36, 0x91, 0x36, 0xc8, 0xd0, 0xf9, 0xe6, 0x37, 0xd0, 0xf5, + 0xbd, 0x80, 0xc0, 0xbd, 0x80, 0xc0, 0x60, 0x00, 0x00, 0x00, 0xe9, 0x81, + 0x4a, 0xd0, 0x14, 0xa4, 0x3f, 0xa6, 0x3e, 0xd0, 0x01, 0x88, 0xca, 0x8a, + 0x18, 0xe5, 0x3a, 0x85, 0x3e, 0x10, 0x01, 0xc8, 0x98, 0xe5, 0x3b, 0xd0, + 0x40, 0xa4, 0x2f, 0xb9, 0x3d, 0x00, 0x91, 0x3a, 0x88, 0x10, 0xf8, 0x20, + 0x48, 0xf9, 0x20, 0x1a, 0xfc, 0x20, 0x1a, 0xfc, 0x4c, 0xe3, 0xfc, 0xa5, + 0x3d, 0x20, 0x8e, 0xf8, 0xaa, 0xbd, 0x00, 0xfa, 0xc5, 0x42, 0xd0, 0x13, + 0xbd, 0xc0, 0xf9, 0xc5, 0x43, 0xd0, 0x0c, 0xa5, 0x44, 0xa4, 0x2e, 0xc0, + 0x9d, 0xf0, 0xb3, 0xc5, 0x2e, 0xf0, 0xca, 0xc6, 0x3d, 0xd0, 0xdc, 0xe6, + 0x44, 0xc6, 0x35, 0xf0, 0xd6, 0xa4, 0x34, 0x98, 0xaa, 0x4c, 0xd2, 0xfc, + 0x20, 0xc7, 0xff, 0xad, 0x00, 0x02, 0xc9, 0xa0, 0xf0, 0x12, 0xc9, 0x8d, + 0xd0, 0x01, 0x60, 0x20, 0xa7, 0xff, 0xc9, 0x93, 0xd0, 0xe5, 0x8a, 0xf0, + 0xe2, 0x20, 0x78, 0xfe, 0xa9, 0x03, 0x85, 0x3d, 0x20, 0x13, 0xff, 0x0a, + 0xe9, 0xbe, 0xc9, 0xc2, 0x90, 0xd1, 0x0a, 0x0a, 0xa2, 0x04, 0x0a, 0x26, + 0x42, 0x26, 0x43, 0xca, 0x10, 0xf8, 0xc6, 0x3d, 0xf0, 0xf4, 0x10, 0xe4, + 0xa2, 0x05, 0x20, 0xc8, 0xc4, 0xa5, 0x44, 0x0a, 0x0a, 0x05, 0x35, 0xc9, + 0x20, 0xb0, 0x06, 0xa6, 0x35, 0xf0, 0x02, 0x09, 0x80, 0x85, 0x44, 0x84, + 0x34, 0xb9, 0x00, 0x02, 0xc9, 0xbb, 0xf0, 0x04, 0xc9, 0x8d, 0xd0, 0xb4, + 0x4c, 0x6b, 0xcf, 0xdf, 0x6f, 0xd8, 0x65, 0xd7, 0xf8, 0xdc, 0x94, 0xd9, + 0xb1, 0xdb, 0x30, 0xf3, 0xd8, 0xdf, 0xe1, 0xdb, 0x8f, 0xf3, 0x98, 0xf3, + 0xe4, 0xf1, 0xdd, 0xf1, 0xd4, 0xf1, 0x24, 0xf2, 0x31, 0xf2, 0x40, 0xf2, + 0xd7, 0xf3, 0xe1, 0xf3, 0xe8, 0xf6, 0xfd, 0xf6, 0x68, 0xf7, 0x6e, 0xf7, + 0xe6, 0xf7, 0x57, 0xfc, 0x20, 0xf7, 0x26, 0xf7, 0x74, 0xf7, 0x6c, 0xf2, + 0x6e, 0xf2, 0x72, 0xf2, 0x76, 0xf2, 0x7f, 0xf2, 0x4e, 0xf2, 0x6a, 0xd9, + 0x55, 0xf2, 0x85, 0xf2, 0xa5, 0xf2, 0xca, 0xf2, 0x17, 0xf3, 0xbb, 0xf3, + 0x9e, 0xf3, 0x61, 0xf2, 0x45, 0xda, 0x3d, 0xd9, 0x11, 0xd9, 0xc8, 0xd9, + 0x48, 0xd8, 0xf4, 0x03, 0x20, 0xd9, 0x6a, 0xd9, 0xdb, 0xd9, 0x6d, 0xd8, + 0xeb, 0xd9, 0x83, 0xe7, 0xc8, 0xd8, 0xaf, 0xd8, 0x12, 0xe3, 0x7a, 0xe7, + 0xd4, 0xda, 0x95, 0xd8, 0xa4, 0xd6, 0x69, 0xd6, 0x9f, 0xdb, 0x48, 0xd6, + 0x90, 0xeb, 0x23, 0xec, 0xaf, 0xeb, 0x0a, 0x00, 0xde, 0xe2, 0x12, 0xd4, + 0xcd, 0xdf, 0xff, 0xe2, 0x8d, 0xee, 0xae, 0xef, 0x41, 0xe9, 0x09, 0xef, + 0xea, 0xef, 0xf1, 0xef, 0x3a, 0xf0, 0x9e, 0xf0, 0x64, 0xe7, 0xd6, 0xe6, + 0xc5, 0xe3, 0x07, 0xe7, 0xe5, 0xe6, 0x46, 0xe6, 0x5a, 0xe6, 0x86, 0xe6, + 0x91, 0xe6, 0x79, 0xc0, 0xe7, 0x79, 0xa9, 0xe7, 0x7b, 0x81, 0xe9, 0x7b, + 0x68, 0xea, 0x7d, 0x96, 0xee, 0x50, 0x54, 0xdf, 0x46, 0x4e, 0xdf, 0x7f, + 0xcf, 0xee, 0x7f, 0x97, 0xde, 0x64, 0x64, 0xdf, 0x45, 0x4e, 0xc4, 0x46, + 0x4f, 0xd2, 0x4e, 0x45, 0x58, 0xd4, 0x44, 0x41, 0x54, 0xc1, 0x49, 0x4e, + 0x50, 0x55, 0xd4, 0x44, 0x45, 0xcc, 0x44, 0x49, 0xcd, 0x52, 0x45, 0x41, + 0xc4, 0x47, 0xd2, 0x54, 0x45, 0x58, 0xd4, 0x50, 0x52, 0xa3, 0x49, 0x4e, + 0xa3, 0x43, 0x41, 0x4c, 0xcc, 0x50, 0x4c, 0x4f, 0xd4, 0x48, 0x4c, 0x49, + 0xce, 0x56, 0x4c, 0x49, 0xce, 0x48, 0x47, 0x52, 0xb2, 0x48, 0x47, 0xd2, + 0x48, 0x43, 0x4f, 0x4c, 0x4f, 0x52, 0xbd, 0x48, 0x50, 0x4c, 0x4f, 0xd4, + 0x44, 0x52, 0x41, 0xd7, 0x58, 0x44, 0x52, 0x41, 0xd7, 0x48, 0x54, 0x41, + 0xc2, 0x48, 0x4f, 0x4d, 0xc5, 0x52, 0x4f, 0x54, 0xbd, 0x53, 0x43, 0x41, + 0x4c, 0x45, 0xbd, 0x53, 0x48, 0x4c, 0x4f, 0x41, 0xc4, 0x54, 0x52, 0x41, + 0x43, 0xc5, 0x4e, 0x4f, 0x54, 0x52, 0x41, 0x43, 0xc5, 0x4e, 0x4f, 0x52, + 0x4d, 0x41, 0xcc, 0x49, 0x4e, 0x56, 0x45, 0x52, 0x53, 0xc5, 0x46, 0x4c, + 0x41, 0x53, 0xc8, 0x43, 0x4f, 0x4c, 0x4f, 0x52, 0xbd, 0x50, 0x4f, 0xd0, + 0x56, 0x54, 0x41, 0xc2, 0x48, 0x49, 0x4d, 0x45, 0x4d, 0xba, 0x4c, 0x4f, + 0x4d, 0x45, 0x4d, 0xba, 0x4f, 0x4e, 0x45, 0x52, 0xd2, 0x52, 0x45, 0x53, + 0x55, 0x4d, 0xc5, 0x52, 0x45, 0x43, 0x41, 0x4c, 0xcc, 0x53, 0x54, 0x4f, + 0x52, 0xc5, 0x53, 0x50, 0x45, 0x45, 0x44, 0xbd, 0x4c, 0x45, 0xd4, 0x47, + 0x4f, 0x54, 0xcf, 0x52, 0x55, 0xce, 0x49, 0xc6, 0x52, 0x45, 0x53, 0x54, + 0x4f, 0x52, 0xc5, 0xa6, 0x47, 0x4f, 0x53, 0x55, 0xc2, 0x52, 0x45, 0x54, + 0x55, 0x52, 0xce, 0x52, 0x45, 0xcd, 0x53, 0x54, 0x4f, 0xd0, 0x4f, 0xce, + 0x57, 0x41, 0x49, 0xd4, 0x4c, 0x4f, 0x41, 0xc4, 0x53, 0x41, 0x56, 0xc5, + 0x44, 0x45, 0xc6, 0x50, 0x4f, 0x4b, 0xc5, 0x50, 0x52, 0x49, 0x4e, 0xd4, + 0x43, 0x4f, 0x4e, 0xd4, 0x4c, 0x49, 0x53, 0xd4, 0x43, 0x4c, 0x45, 0x41, + 0xd2, 0x47, 0x45, 0xd4, 0x4e, 0x45, 0xd7, 0x54, 0x41, 0x42, 0xa8, 0x54, + 0xcf, 0x46, 0xce, 0x53, 0x50, 0x43, 0xa8, 0x54, 0x48, 0x45, 0xce, 0x41, + 0xd4, 0x4e, 0x4f, 0xd4, 0x53, 0x54, 0x45, 0xd0, 0xab, 0xad, 0xaa, 0xaf, + 0xde, 0x41, 0x4e, 0xc4, 0x4f, 0xd2, 0xbe, 0xbd, 0xbc, 0x53, 0x47, 0xce, + 0x49, 0x4e, 0xd4, 0x41, 0x42, 0xd3, 0x55, 0x53, 0xd2, 0x46, 0x52, 0xc5, + 0x53, 0x43, 0x52, 0x4e, 0xa8, 0x50, 0x44, 0xcc, 0x50, 0x4f, 0xd3, 0x53, + 0x51, 0xd2, 0x52, 0x4e, 0xc4, 0x4c, 0x4f, 0xc7, 0x45, 0x58, 0xd0, 0x43, + 0x4f, 0xd3, 0x53, 0x49, 0xce, 0x54, 0x41, 0xce, 0x41, 0x54, 0xce, 0x50, + 0x45, 0x45, 0xcb, 0x4c, 0x45, 0xce, 0x53, 0x54, 0x52, 0xa4, 0x56, 0x41, + 0xcc, 0x41, 0x53, 0xc3, 0x43, 0x48, 0x52, 0xa4, 0x4c, 0x45, 0x46, 0x54, + 0xa4, 0x52, 0x49, 0x47, 0x48, 0x54, 0xa4, 0x4d, 0x49, 0x44, 0xa4, 0x00, + 0x4e, 0x45, 0x58, 0x54, 0x20, 0x57, 0x49, 0x54, 0x48, 0x4f, 0x55, 0x54, + 0x20, 0x46, 0x4f, 0xd2, 0x53, 0x59, 0x4e, 0x54, 0x41, 0xd8, 0x52, 0x45, + 0x54, 0x55, 0x52, 0x4e, 0x20, 0x57, 0x49, 0x54, 0x48, 0x4f, 0x55, 0x54, + 0x20, 0x47, 0x4f, 0x53, 0x55, 0xc2, 0x4f, 0x55, 0x54, 0x20, 0x4f, 0x46, + 0x20, 0x44, 0x41, 0x54, 0xc1, 0x49, 0x4c, 0x4c, 0x45, 0x47, 0x41, 0x4c, + 0x20, 0x51, 0x55, 0x41, 0x4e, 0x54, 0x49, 0x54, 0xd9, 0x4f, 0x56, 0x45, + 0x52, 0x46, 0x4c, 0x4f, 0xd7, 0x4f, 0x55, 0x54, 0x20, 0x4f, 0x46, 0x20, + 0x4d, 0x45, 0x4d, 0x4f, 0x52, 0xd9, 0x55, 0x4e, 0x44, 0x45, 0x46, 0x27, + 0x44, 0x20, 0x53, 0x54, 0x41, 0x54, 0x45, 0x4d, 0x45, 0x4e, 0xd4, 0x42, + 0x41, 0x44, 0x20, 0x53, 0x55, 0x42, 0x53, 0x43, 0x52, 0x49, 0x50, 0xd4, + 0x52, 0x45, 0x44, 0x49, 0x4d, 0x27, 0x44, 0x20, 0x41, 0x52, 0x52, 0x41, + 0xd9, 0x44, 0x49, 0x56, 0x49, 0x53, 0x49, 0x4f, 0x4e, 0x20, 0x42, 0x59, + 0x20, 0x5a, 0x45, 0x52, 0xcf, 0x49, 0x4c, 0x4c, 0x45, 0x47, 0x41, 0x4c, + 0x20, 0x44, 0x49, 0x52, 0x45, 0x43, 0xd4, 0x54, 0x59, 0x50, 0x45, 0x20, + 0x4d, 0x49, 0x53, 0x4d, 0x41, 0x54, 0x43, 0xc8, 0x53, 0x54, 0x52, 0x49, + 0x4e, 0x47, 0x20, 0x54, 0x4f, 0x4f, 0x20, 0x4c, 0x4f, 0x4e, 0xc7, 0x46, + 0x4f, 0x52, 0x4d, 0x55, 0x4c, 0x41, 0x20, 0x54, 0x4f, 0x4f, 0x20, 0x43, + 0x4f, 0x4d, 0x50, 0x4c, 0x45, 0xd8, 0x43, 0x41, 0x4e, 0x27, 0x54, 0x20, + 0x43, 0x4f, 0x4e, 0x54, 0x49, 0x4e, 0x55, 0xc5, 0x55, 0x4e, 0x44, 0x45, + 0x46, 0x27, 0x44, 0x20, 0x46, 0x55, 0x4e, 0x43, 0x54, 0x49, 0x4f, 0xce, + 0x20, 0x45, 0x52, 0x52, 0x4f, 0x52, 0x07, 0x00, 0x20, 0x49, 0x4e, 0x20, + 0x00, 0x0d, 0x42, 0x52, 0x45, 0x41, 0x4b, 0x07, 0x00, 0xba, 0xe8, 0xe8, + 0xe8, 0xe8, 0xbd, 0x01, 0x01, 0xc9, 0x81, 0xd0, 0x21, 0xa5, 0x86, 0xd0, + 0x0a, 0xbd, 0x02, 0x01, 0x85, 0x85, 0xbd, 0x03, 0x01, 0x85, 0x86, 0xdd, + 0x03, 0x01, 0xd0, 0x07, 0xa5, 0x85, 0xdd, 0x02, 0x01, 0xf0, 0x07, 0x8a, + 0x18, 0x69, 0x12, 0xaa, 0xd0, 0xd8, 0x60, 0x20, 0xe3, 0xd3, 0x85, 0x6d, + 0x84, 0x6e, 0x38, 0xa5, 0x96, 0xe5, 0x9b, 0x85, 0x5e, 0xa8, 0xa5, 0x97, + 0xe5, 0x9c, 0xaa, 0xe8, 0x98, 0xf0, 0x23, 0xa5, 0x96, 0x38, 0xe5, 0x5e, + 0x85, 0x96, 0xb0, 0x03, 0xc6, 0x97, 0x38, 0xa5, 0x94, 0xe5, 0x5e, 0x85, + 0x94, 0xb0, 0x08, 0xc6, 0x95, 0x90, 0x04, 0xb1, 0x96, 0x91, 0x94, 0x88, + 0xd0, 0xf9, 0xb1, 0x96, 0x91, 0x94, 0xc6, 0x97, 0xc6, 0x95, 0xca, 0xd0, + 0xf2, 0x60, 0x0a, 0x69, 0x36, 0xb0, 0x35, 0x85, 0x5e, 0xba, 0xe4, 0x5e, + 0x90, 0x2e, 0x60, 0xc4, 0x70, 0x90, 0x28, 0xd0, 0x04, 0xc5, 0x6f, 0x90, + 0x22, 0x48, 0xa2, 0x09, 0x98, 0x48, 0xb5, 0x93, 0xca, 0x10, 0xfa, 0x20, + 0x84, 0xe4, 0xa2, 0xf7, 0x68, 0x95, 0x9d, 0xe8, 0x30, 0xfa, 0x68, 0xa8, + 0x68, 0xc4, 0x70, 0x90, 0x06, 0xd0, 0x05, 0xc5, 0x6f, 0xb0, 0x01, 0x60, + 0xa2, 0x4d, 0x24, 0xd8, 0x10, 0x03, 0x4c, 0xe9, 0xf2, 0x20, 0xfb, 0xda, + 0x20, 0x5a, 0xdb, 0xbd, 0x60, 0xd2, 0x48, 0x20, 0x5c, 0xdb, 0xe8, 0x68, + 0x10, 0xf5, 0x20, 0x83, 0xd6, 0xa9, 0x50, 0xa0, 0xd3, 0x20, 0x3a, 0xdb, + 0xa4, 0x76, 0xc8, 0xf0, 0x03, 0x20, 0x19, 0xed, 0x20, 0xfb, 0xda, 0xa2, + 0xdd, 0x20, 0x2e, 0xd5, 0x86, 0xb8, 0x84, 0xb9, 0x46, 0xd8, 0x20, 0xb1, + 0x00, 0xaa, 0xf0, 0xec, 0xa2, 0xff, 0x86, 0x76, 0x90, 0x06, 0x20, 0x59, + 0xd5, 0x4c, 0x05, 0xd8, 0xa6, 0xaf, 0x86, 0x69, 0xa6, 0xb0, 0x86, 0x6a, + 0x20, 0x0c, 0xda, 0x20, 0x59, 0xd5, 0x84, 0x0f, 0x20, 0x1a, 0xd6, 0x90, + 0x44, 0xa0, 0x01, 0xb1, 0x9b, 0x85, 0x5f, 0xa5, 0x69, 0x85, 0x5e, 0xa5, + 0x9c, 0x85, 0x61, 0xa5, 0x9b, 0x88, 0xf1, 0x9b, 0x18, 0x65, 0x69, 0x85, + 0x69, 0x85, 0x60, 0xa5, 0x6a, 0x69, 0xff, 0x85, 0x6a, 0xe5, 0x9c, 0xaa, + 0x38, 0xa5, 0x9b, 0xe5, 0x69, 0xa8, 0xb0, 0x03, 0xe8, 0xc6, 0x61, 0x18, + 0x65, 0x5e, 0x90, 0x03, 0xc6, 0x5f, 0x18, 0xb1, 0x5e, 0x91, 0x60, 0xc8, + 0xd0, 0xf9, 0xe6, 0x5f, 0xe6, 0x61, 0xca, 0xd0, 0xf2, 0xad, 0x00, 0x02, + 0xf0, 0x38, 0xa5, 0x73, 0xa4, 0x74, 0x85, 0x6f, 0x84, 0x70, 0xa5, 0x69, + 0x85, 0x96, 0x65, 0x0f, 0x85, 0x94, 0xa4, 0x6a, 0x84, 0x97, 0x90, 0x01, + 0xc8, 0x84, 0x95, 0x20, 0x93, 0xd3, 0xa5, 0x50, 0xa4, 0x51, 0x8d, 0xfe, + 0x01, 0x8c, 0xff, 0x01, 0xa5, 0x6d, 0xa4, 0x6e, 0x85, 0x69, 0x84, 0x6a, + 0xa4, 0x0f, 0xb9, 0xfb, 0x01, 0x88, 0x91, 0x9b, 0xd0, 0xf8, 0x20, 0x65, + 0xd6, 0xa5, 0x67, 0xa4, 0x68, 0x85, 0x5e, 0x84, 0x5f, 0x18, 0xa0, 0x01, + 0xb1, 0x5e, 0xd0, 0x0b, 0xa5, 0x69, 0x85, 0xaf, 0xa5, 0x6a, 0x85, 0xb0, + 0x4c, 0x3c, 0xd4, 0xa0, 0x04, 0xc8, 0xb1, 0x5e, 0xd0, 0xfb, 0xc8, 0x98, + 0x65, 0x5e, 0xaa, 0xa0, 0x00, 0x91, 0x5e, 0xa5, 0x5f, 0x69, 0x00, 0xc8, + 0x91, 0x5e, 0x86, 0x5e, 0x85, 0x5f, 0x90, 0xd2, 0xa2, 0x80, 0x86, 0x33, + 0x20, 0x6a, 0xfd, 0xe0, 0xef, 0x90, 0x02, 0xa2, 0xef, 0xa9, 0x00, 0x9d, + 0x00, 0x02, 0x8a, 0xf0, 0x0b, 0xbd, 0xff, 0x01, 0x29, 0x7f, 0x9d, 0xff, + 0x01, 0xca, 0xd0, 0xf5, 0xa9, 0x00, 0xa2, 0xff, 0xa0, 0x01, 0x60, 0x20, + 0x0c, 0xfd, 0x29, 0x7f, 0x60, 0xa6, 0xb8, 0xca, 0xa0, 0x04, 0x84, 0x13, + 0x24, 0xd6, 0x10, 0x08, 0x68, 0x68, 0x20, 0x65, 0xd6, 0x4c, 0xd2, 0xd7, + 0xe8, 0x20, 0x8c, 0xf7, 0x24, 0x13, 0x70, 0x04, 0xc9, 0x20, 0xf0, 0xf4, + 0x85, 0x0e, 0xc9, 0x22, 0xf0, 0x74, 0x70, 0x4d, 0xc9, 0x3f, 0xd0, 0x04, + 0xa9, 0xba, 0xd0, 0x45, 0xc9, 0x30, 0x90, 0x04, 0xc9, 0x3c, 0x90, 0x3d, + 0x84, 0xad, 0xa9, 0xd0, 0x85, 0x9d, 0xa9, 0xcf, 0x85, 0x9e, 0xa0, 0x00, + 0x84, 0x0f, 0x88, 0x86, 0xb8, 0xca, 0xc8, 0xd0, 0x02, 0xe6, 0x9e, 0xe8, + 0x20, 0x8c, 0xf7, 0xc9, 0x20, 0xf0, 0xf8, 0x38, 0xf1, 0x9d, 0xf0, 0xee, + 0xc9, 0x80, 0xd0, 0x41, 0x05, 0x0f, 0xc9, 0xc5, 0xd0, 0x0d, 0x20, 0x87, + 0xf7, 0xc9, 0x4e, 0xf0, 0x34, 0xc9, 0x4f, 0xf0, 0x30, 0xa9, 0xc5, 0xa4, + 0xad, 0xe8, 0xc8, 0x99, 0xfb, 0x01, 0xb9, 0xfb, 0x01, 0xf0, 0x39, 0x38, + 0xe9, 0x3a, 0xf0, 0x04, 0xc9, 0x49, 0xd0, 0x02, 0x85, 0x13, 0x38, 0xe9, + 0x78, 0xd0, 0x86, 0x85, 0x0e, 0x20, 0x8c, 0xf7, 0xf0, 0xdf, 0xc5, 0x0e, + 0xf0, 0xdb, 0xc8, 0x99, 0xfb, 0x01, 0xe8, 0xd0, 0xf0, 0xa6, 0xb8, 0xe6, + 0x0f, 0xb1, 0x9d, 0xc8, 0xd0, 0x02, 0xe6, 0x9e, 0x0a, 0x90, 0xf6, 0xb1, + 0x9d, 0xd0, 0x9d, 0x20, 0x9a, 0xf7, 0x10, 0xbb, 0x99, 0xfd, 0x01, 0xc6, + 0xb9, 0xa9, 0xff, 0x85, 0xb8, 0x60, 0xa5, 0x67, 0xa6, 0x68, 0xa0, 0x01, + 0x85, 0x9b, 0x86, 0x9c, 0xb1, 0x9b, 0xf0, 0x1f, 0xc8, 0xc8, 0xa5, 0x51, + 0xd1, 0x9b, 0x90, 0x18, 0xf0, 0x03, 0x88, 0xd0, 0x09, 0xa5, 0x50, 0x88, + 0xd1, 0x9b, 0x90, 0x0c, 0xf0, 0x0a, 0x88, 0xb1, 0x9b, 0xaa, 0x88, 0xb1, + 0x9b, 0xb0, 0xd7, 0x18, 0x60, 0xd0, 0xfd, 0xa9, 0x00, 0x85, 0xd6, 0xa8, + 0x91, 0x67, 0xc8, 0x91, 0x67, 0xa5, 0x67, 0x69, 0x02, 0x85, 0x69, 0x85, + 0xaf, 0xa5, 0x68, 0x69, 0x00, 0x85, 0x6a, 0x85, 0xb0, 0x20, 0x97, 0xd6, + 0xa9, 0x00, 0xd0, 0x2a, 0xa5, 0x73, 0xa4, 0x74, 0x85, 0x6f, 0x84, 0x70, + 0xa5, 0x69, 0xa4, 0x6a, 0x85, 0x6b, 0x84, 0x6c, 0x85, 0x6d, 0x84, 0x6e, + 0x20, 0x49, 0xd8, 0xa2, 0x55, 0x86, 0x52, 0x68, 0xa8, 0x68, 0xa2, 0xf8, + 0x9a, 0x48, 0x98, 0x48, 0xa9, 0x00, 0x85, 0x7a, 0x85, 0x14, 0x60, 0x18, + 0xa5, 0x67, 0x69, 0xff, 0x85, 0xb8, 0xa5, 0x68, 0x69, 0xff, 0x85, 0xb9, + 0x60, 0x90, 0x0a, 0xf0, 0x08, 0xc9, 0xc9, 0xf0, 0x04, 0xc9, 0x2c, 0xd0, + 0xe5, 0x20, 0x0c, 0xda, 0x20, 0x1a, 0xd6, 0x20, 0xb7, 0x00, 0xf0, 0x10, + 0xc9, 0xc9, 0xf0, 0x04, 0xc9, 0x2c, 0xd0, 0x84, 0x20, 0xb1, 0x00, 0x20, + 0x0c, 0xda, 0xd0, 0xca, 0x68, 0x68, 0xa5, 0x50, 0x05, 0x51, 0xd0, 0x06, + 0xa9, 0xff, 0x85, 0x50, 0x85, 0x51, 0xa0, 0x01, 0xb1, 0x9b, 0xf0, 0x44, + 0x20, 0x58, 0xd8, 0x20, 0xfb, 0xda, 0xc8, 0xb1, 0x9b, 0xaa, 0xc8, 0xb1, + 0x9b, 0xc5, 0x51, 0xd0, 0x04, 0xe4, 0x50, 0xf0, 0x02, 0xb0, 0x2d, 0x84, + 0x85, 0x20, 0xaa, 0xf7, 0xa9, 0x20, 0xa4, 0x85, 0x29, 0x7f, 0x20, 0x5c, + 0xdb, 0x20, 0xb4, 0xf7, 0xea, 0x90, 0x07, 0x20, 0xfb, 0xda, 0xa9, 0x05, + 0x85, 0x24, 0xc8, 0xb1, 0x9b, 0xd0, 0x1d, 0xa8, 0xb1, 0x9b, 0xaa, 0xc8, + 0xb1, 0x9b, 0x86, 0x9b, 0x85, 0x9c, 0xd0, 0xb6, 0xa9, 0x0d, 0x20, 0x5c, + 0xdb, 0x4c, 0xd2, 0xd7, 0xc8, 0xd0, 0x02, 0xe6, 0x9e, 0xb1, 0x9d, 0x60, + 0x10, 0xcc, 0x38, 0xe9, 0x7f, 0xaa, 0x84, 0x85, 0xa0, 0xd0, 0x84, 0x9d, + 0xa0, 0xcf, 0x84, 0x9e, 0xa0, 0xff, 0xca, 0xf0, 0x07, 0x20, 0x2c, 0xd7, + 0x10, 0xfb, 0x30, 0xf6, 0xa9, 0x20, 0x20, 0x5c, 0xdb, 0x20, 0x2c, 0xd7, + 0x30, 0x05, 0x20, 0x5c, 0xdb, 0xd0, 0xf6, 0x20, 0x5c, 0xdb, 0xa9, 0x20, + 0xd0, 0x98, 0xa9, 0x80, 0x85, 0x14, 0x20, 0x46, 0xda, 0x20, 0x65, 0xd3, + 0xd0, 0x05, 0x8a, 0x69, 0x0f, 0xaa, 0x9a, 0x68, 0x68, 0xa9, 0x09, 0x20, + 0xd6, 0xd3, 0x20, 0xa3, 0xd9, 0x18, 0x98, 0x65, 0xb8, 0x48, 0xa5, 0xb9, + 0x69, 0x00, 0x48, 0xa5, 0x76, 0x48, 0xa5, 0x75, 0x48, 0xa9, 0xc1, 0x20, + 0xc0, 0xde, 0x20, 0x6a, 0xdd, 0x20, 0x67, 0xdd, 0xa5, 0xa2, 0x09, 0x7f, + 0x25, 0x9e, 0x85, 0x9e, 0xa9, 0xaf, 0xa0, 0xd7, 0x85, 0x5e, 0x84, 0x5f, + 0x4c, 0x20, 0xde, 0xa9, 0x13, 0xa0, 0xe9, 0x20, 0xf9, 0xea, 0x20, 0xb7, + 0x00, 0xc9, 0xc7, 0xd0, 0x06, 0x20, 0xb1, 0x00, 0x20, 0x67, 0xdd, 0x20, + 0x82, 0xeb, 0x20, 0x15, 0xde, 0xa5, 0x86, 0x48, 0xa5, 0x85, 0x48, 0xa9, + 0x81, 0x48, 0xba, 0x86, 0xf8, 0x20, 0x58, 0xd8, 0xa5, 0xb8, 0xa4, 0xb9, + 0xa6, 0x76, 0xe8, 0xf0, 0x04, 0x85, 0x79, 0x84, 0x7a, 0xa0, 0x00, 0xb1, + 0xb8, 0xd0, 0x57, 0xa0, 0x02, 0xb1, 0xb8, 0x18, 0xf0, 0x34, 0xc8, 0xb1, + 0xb8, 0x85, 0x75, 0xc8, 0xb1, 0xb8, 0x85, 0x76, 0x98, 0x65, 0xb8, 0x85, + 0xb8, 0x90, 0x02, 0xe6, 0xb9, 0x24, 0xf2, 0x10, 0x14, 0xa6, 0x76, 0xe8, + 0xf0, 0x0f, 0xa9, 0x23, 0x20, 0x5c, 0xdb, 0xa6, 0x75, 0xa5, 0x76, 0x20, + 0x24, 0xed, 0x20, 0x57, 0xdb, 0x20, 0xb1, 0x00, 0x20, 0x28, 0xd8, 0x4c, + 0xd2, 0xd7, 0xf0, 0x62, 0xf0, 0x2d, 0xe9, 0x80, 0x90, 0x11, 0xc9, 0x40, + 0xb0, 0x14, 0x0a, 0xa8, 0xb9, 0x01, 0xd0, 0x48, 0xb9, 0x00, 0xd0, 0x48, + 0x4c, 0xb1, 0x00, 0x4c, 0x46, 0xda, 0xc9, 0x3a, 0xf0, 0xbf, 0x4c, 0xc9, + 0xde, 0x38, 0xa5, 0x67, 0xe9, 0x01, 0xa4, 0x68, 0xb0, 0x01, 0x88, 0x85, + 0x7d, 0x84, 0x7e, 0x60, 0xad, 0x00, 0xc0, 0xc9, 0x83, 0xf0, 0x01, 0x60, + 0x20, 0x53, 0xd5, 0xa2, 0xff, 0x24, 0xd8, 0x10, 0x03, 0x4c, 0xe9, 0xf2, + 0xc9, 0x03, 0xb0, 0x01, 0x18, 0xd0, 0x3c, 0xa5, 0xb8, 0xa4, 0xb9, 0xa6, + 0x76, 0xe8, 0xf0, 0x0c, 0x85, 0x79, 0x84, 0x7a, 0xa5, 0x75, 0xa4, 0x76, + 0x85, 0x77, 0x84, 0x78, 0x68, 0x68, 0xa9, 0x5d, 0xa0, 0xd3, 0x90, 0x03, + 0x4c, 0x31, 0xd4, 0x4c, 0x3c, 0xd4, 0xd0, 0x17, 0xa2, 0xd2, 0xa4, 0x7a, + 0xd0, 0x03, 0x4c, 0x12, 0xd4, 0xa5, 0x79, 0x85, 0xb8, 0x84, 0xb9, 0xa5, + 0x77, 0xa4, 0x78, 0x85, 0x75, 0x84, 0x76, 0x60, 0x38, 0xa5, 0xaf, 0xe5, + 0x67, 0x85, 0x50, 0xa5, 0xb0, 0xe5, 0x68, 0x85, 0x51, 0x20, 0xf0, 0xd8, + 0x20, 0xcd, 0xfe, 0x20, 0x01, 0xd9, 0x4c, 0xcd, 0xfe, 0x20, 0xf0, 0xd8, + 0x20, 0xfd, 0xfe, 0x18, 0xa5, 0x67, 0x65, 0x50, 0x85, 0x69, 0xa5, 0x68, + 0x65, 0x51, 0x85, 0x6a, 0xa5, 0x52, 0x85, 0xd6, 0x20, 0x01, 0xd9, 0x20, + 0xfd, 0xfe, 0x24, 0xd6, 0x10, 0x03, 0x4c, 0x65, 0xd6, 0x4c, 0xf2, 0xd4, + 0xa9, 0x50, 0xa0, 0x00, 0x85, 0x3c, 0x84, 0x3d, 0xa9, 0x52, 0x85, 0x3e, + 0x84, 0x3f, 0x84, 0xd6, 0x60, 0xa5, 0x67, 0xa4, 0x68, 0x85, 0x3c, 0x84, + 0x3d, 0xa5, 0x69, 0xa4, 0x6a, 0x85, 0x3e, 0x84, 0x3f, 0x60, 0x08, 0xc6, + 0x76, 0x28, 0xd0, 0x03, 0x4c, 0x65, 0xd6, 0x20, 0x6c, 0xd6, 0x4c, 0x35, + 0xd9, 0xa9, 0x03, 0x20, 0xd6, 0xd3, 0xa5, 0xb9, 0x48, 0xa5, 0xb8, 0x48, + 0xa5, 0x76, 0x48, 0xa5, 0x75, 0x48, 0xa9, 0xb0, 0x48, 0x20, 0xb7, 0x00, + 0x20, 0x3e, 0xd9, 0x4c, 0xd2, 0xd7, 0x20, 0x0c, 0xda, 0x20, 0xa6, 0xd9, + 0xa5, 0x76, 0xc5, 0x51, 0xb0, 0x0b, 0x98, 0x38, 0x65, 0xb8, 0xa6, 0xb9, + 0x90, 0x07, 0xe8, 0xb0, 0x04, 0xa5, 0x67, 0xa6, 0x68, 0x20, 0x1e, 0xd6, + 0x90, 0x1e, 0xa5, 0x9b, 0xe9, 0x01, 0x85, 0xb8, 0xa5, 0x9c, 0xe9, 0x00, + 0x85, 0xb9, 0x60, 0xd0, 0xfd, 0xa9, 0xff, 0x85, 0x85, 0x20, 0x65, 0xd3, + 0x9a, 0xc9, 0xb0, 0xf0, 0x0b, 0xa2, 0x16, 0x2c, 0xa2, 0x5a, 0x4c, 0x12, + 0xd4, 0x4c, 0xc9, 0xde, 0x68, 0x68, 0xc0, 0x42, 0xf0, 0x3b, 0x85, 0x75, + 0x68, 0x85, 0x76, 0x68, 0x85, 0xb8, 0x68, 0x85, 0xb9, 0x20, 0xa3, 0xd9, + 0x98, 0x18, 0x65, 0xb8, 0x85, 0xb8, 0x90, 0x02, 0xe6, 0xb9, 0x60, 0xa2, + 0x3a, 0x2c, 0xa2, 0x00, 0x86, 0x0d, 0xa0, 0x00, 0x84, 0x0e, 0xa5, 0x0e, + 0xa6, 0x0d, 0x85, 0x0d, 0x86, 0x0e, 0xb1, 0xb8, 0xf0, 0xe8, 0xc5, 0x0e, + 0xf0, 0xe4, 0xc8, 0xc9, 0x22, 0xd0, 0xf3, 0xf0, 0xe9, 0x68, 0x68, 0x68, + 0x60, 0x20, 0x7b, 0xdd, 0x20, 0xb7, 0x00, 0xc9, 0xab, 0xf0, 0x05, 0xa9, + 0xc4, 0x20, 0xc0, 0xde, 0xa5, 0x9d, 0xd0, 0x05, 0x20, 0xa6, 0xd9, 0xf0, + 0xb7, 0x20, 0xb7, 0x00, 0xb0, 0x03, 0x4c, 0x3e, 0xd9, 0x4c, 0x28, 0xd8, + 0x20, 0xf8, 0xe6, 0x48, 0xc9, 0xb0, 0xf0, 0x04, 0xc9, 0xab, 0xd0, 0x89, + 0xc6, 0xa1, 0xd0, 0x04, 0x68, 0x4c, 0x2a, 0xd8, 0x20, 0xb1, 0x00, 0x20, + 0x0c, 0xda, 0xc9, 0x2c, 0xf0, 0xee, 0x68, 0x60, 0xa2, 0x00, 0x86, 0x50, + 0x86, 0x51, 0xb0, 0xf7, 0xe9, 0x2f, 0x85, 0x0d, 0xa5, 0x51, 0x85, 0x5e, + 0xc9, 0x19, 0xb0, 0xd4, 0xa5, 0x50, 0x0a, 0x26, 0x5e, 0x0a, 0x26, 0x5e, + 0x65, 0x50, 0x85, 0x50, 0xa5, 0x5e, 0x65, 0x51, 0x85, 0x51, 0x06, 0x50, + 0x26, 0x51, 0xa5, 0x50, 0x65, 0x0d, 0x85, 0x50, 0x90, 0x02, 0xe6, 0x51, + 0x20, 0xb1, 0x00, 0x4c, 0x12, 0xda, 0x20, 0xe3, 0xdf, 0x85, 0x85, 0x84, + 0x86, 0xa9, 0xd0, 0x20, 0xc0, 0xde, 0xa5, 0x12, 0x48, 0xa5, 0x11, 0x48, + 0x20, 0x7b, 0xdd, 0x68, 0x2a, 0x20, 0x6d, 0xdd, 0xd0, 0x18, 0x68, 0x10, + 0x12, 0x20, 0x72, 0xeb, 0x20, 0x0c, 0xe1, 0xa0, 0x00, 0xa5, 0xa0, 0x91, + 0x85, 0xc8, 0xa5, 0xa1, 0x91, 0x85, 0x60, 0x4c, 0x27, 0xeb, 0x68, 0xa0, + 0x02, 0xb1, 0xa0, 0xc5, 0x70, 0x90, 0x17, 0xd0, 0x07, 0x88, 0xb1, 0xa0, + 0xc5, 0x6f, 0x90, 0x0e, 0xa4, 0xa1, 0xc4, 0x6a, 0x90, 0x08, 0xd0, 0x0d, + 0xa5, 0xa0, 0xc5, 0x69, 0xb0, 0x07, 0xa5, 0xa0, 0xa4, 0xa1, 0x4c, 0xb7, + 0xda, 0xa0, 0x00, 0xb1, 0xa0, 0x20, 0xd5, 0xe3, 0xa5, 0x8c, 0xa4, 0x8d, + 0x85, 0xab, 0x84, 0xac, 0x20, 0xd4, 0xe5, 0xa9, 0x9d, 0xa0, 0x00, 0x85, + 0x8c, 0x84, 0x8d, 0x20, 0x35, 0xe6, 0xa0, 0x00, 0xb1, 0x8c, 0x91, 0x85, + 0xc8, 0xb1, 0x8c, 0x91, 0x85, 0xc8, 0xb1, 0x8c, 0x91, 0x85, 0x60, 0x20, + 0x3d, 0xdb, 0x20, 0xb7, 0x00, 0xf0, 0x24, 0xf0, 0x29, 0xc9, 0xc0, 0xf0, + 0x3c, 0xc9, 0xc3, 0x18, 0xf0, 0x37, 0xc9, 0x2c, 0x18, 0xf0, 0x1c, 0xc9, + 0x3b, 0xf0, 0x44, 0x20, 0x7b, 0xdd, 0x24, 0x11, 0x30, 0xdd, 0x20, 0x34, + 0xed, 0x20, 0xe7, 0xe3, 0x4c, 0xcf, 0xda, 0xa9, 0x0d, 0x20, 0x5c, 0xdb, + 0x49, 0xff, 0x60, 0x20, 0xb4, 0xf7, 0x30, 0x09, 0xc9, 0x18, 0x90, 0x05, + 0x20, 0xfb, 0xda, 0xd0, 0x1e, 0x69, 0x10, 0x29, 0xf0, 0xaa, 0x38, 0xb0, + 0x0c, 0x08, 0x20, 0xf5, 0xe6, 0xc9, 0x29, 0xd0, 0x62, 0x28, 0x90, 0x07, + 0xca, 0x20, 0xc3, 0xf7, 0x90, 0x05, 0xaa, 0xe8, 0xca, 0xd0, 0x06, 0x20, + 0xb1, 0x00, 0x4c, 0xd7, 0xda, 0x20, 0x57, 0xdb, 0xd0, 0xf2, 0x20, 0xe7, + 0xe3, 0x20, 0x00, 0xe6, 0xaa, 0xa0, 0x00, 0xe8, 0xca, 0xf0, 0xbb, 0xb1, + 0x5e, 0x20, 0x5c, 0xdb, 0xc8, 0xc9, 0x0d, 0xd0, 0xf3, 0x20, 0x00, 0xdb, + 0x4c, 0x44, 0xdb, 0xa9, 0x20, 0x2c, 0xa9, 0x3f, 0x09, 0x80, 0xc9, 0xa0, + 0x90, 0x02, 0x05, 0xf3, 0x20, 0xed, 0xfd, 0x29, 0x7f, 0x48, 0xa5, 0xf1, + 0x20, 0xa8, 0xfc, 0x68, 0x60, 0xa5, 0x15, 0xf0, 0x12, 0x30, 0x04, 0xa0, + 0xff, 0xd0, 0x04, 0xa5, 0x7b, 0xa4, 0x7c, 0x85, 0x75, 0x84, 0x76, 0x4c, + 0xc9, 0xde, 0x68, 0x24, 0xd8, 0x10, 0x05, 0xa2, 0xfe, 0x4c, 0xe9, 0xf2, + 0xa9, 0xef, 0xa0, 0xdc, 0x20, 0x3a, 0xdb, 0xa5, 0x79, 0xa4, 0x7a, 0x85, + 0xb8, 0x84, 0xb9, 0x60, 0x20, 0x06, 0xe3, 0xa2, 0x01, 0xa0, 0x02, 0xa9, + 0x00, 0x8d, 0x01, 0x02, 0xa9, 0x40, 0x20, 0xeb, 0xdb, 0x60, 0xc9, 0x22, + 0xd0, 0x0e, 0x20, 0x81, 0xde, 0xa9, 0x3b, 0x20, 0xc0, 0xde, 0x20, 0x3d, + 0xdb, 0x4c, 0xc7, 0xdb, 0x20, 0x5a, 0xdb, 0x20, 0x06, 0xe3, 0xa9, 0x2c, + 0x8d, 0xff, 0x01, 0x20, 0x2c, 0xd5, 0xad, 0x00, 0x02, 0xc9, 0x03, 0xd0, + 0x10, 0x4c, 0x63, 0xd8, 0x20, 0x5a, 0xdb, 0x4c, 0x2c, 0xd5, 0xa6, 0x7d, + 0xa4, 0x7e, 0xa9, 0x98, 0x2c, 0xa9, 0x00, 0x85, 0x15, 0x86, 0x7f, 0x84, + 0x80, 0x20, 0xe3, 0xdf, 0x85, 0x85, 0x84, 0x86, 0xa5, 0xb8, 0xa4, 0xb9, + 0x85, 0x87, 0x84, 0x88, 0xa6, 0x7f, 0xa4, 0x80, 0x86, 0xb8, 0x84, 0xb9, + 0x20, 0xb7, 0x00, 0xd0, 0x1e, 0x24, 0x15, 0x50, 0x0e, 0x20, 0x0c, 0xfd, + 0x29, 0x7f, 0x8d, 0x00, 0x02, 0xa2, 0xff, 0xa0, 0x01, 0xd0, 0x08, 0x30, + 0x7f, 0x20, 0x5a, 0xdb, 0x20, 0xdc, 0xdb, 0x86, 0xb8, 0x84, 0xb9, 0x20, + 0xb1, 0x00, 0x24, 0x11, 0x10, 0x31, 0x24, 0x15, 0x50, 0x09, 0xe8, 0x86, + 0xb8, 0xa9, 0x00, 0x85, 0x0d, 0xf0, 0x0c, 0x85, 0x0d, 0xc9, 0x22, 0xf0, + 0x07, 0xa9, 0x3a, 0x85, 0x0d, 0xa9, 0x2c, 0x18, 0x85, 0x0e, 0xa5, 0xb8, + 0xa4, 0xb9, 0x69, 0x00, 0x90, 0x01, 0xc8, 0x20, 0xed, 0xe3, 0x20, 0x3d, + 0xe7, 0x20, 0x7b, 0xda, 0x4c, 0x72, 0xdc, 0x48, 0xad, 0x00, 0x02, 0xf0, + 0x30, 0x68, 0x20, 0x4a, 0xec, 0xa5, 0x12, 0x20, 0x63, 0xda, 0x20, 0xb7, + 0x00, 0xf0, 0x07, 0xc9, 0x2c, 0xf0, 0x03, 0x4c, 0x71, 0xdb, 0xa5, 0xb8, + 0xa4, 0xb9, 0x85, 0x7f, 0x84, 0x80, 0xa5, 0x87, 0xa4, 0x88, 0x85, 0xb8, + 0x84, 0xb9, 0x20, 0xb7, 0x00, 0xf0, 0x33, 0x20, 0xbe, 0xde, 0x4c, 0xf1, + 0xdb, 0xa5, 0x15, 0xd0, 0xcc, 0x4c, 0x86, 0xdb, 0x20, 0xa3, 0xd9, 0xc8, + 0xaa, 0xd0, 0x12, 0xa2, 0x2a, 0xc8, 0xb1, 0xb8, 0xf0, 0x5f, 0xc8, 0xb1, + 0xb8, 0x85, 0x7b, 0xc8, 0xb1, 0xb8, 0xc8, 0x85, 0x7c, 0xb1, 0xb8, 0xaa, + 0x20, 0x98, 0xd9, 0xe0, 0x83, 0xd0, 0xdd, 0x4c, 0x2b, 0xdc, 0xa5, 0x7f, + 0xa4, 0x80, 0xa6, 0x15, 0x10, 0x03, 0x4c, 0x53, 0xd8, 0xa0, 0x00, 0xb1, + 0x7f, 0xf0, 0x07, 0xa9, 0xdf, 0xa0, 0xdc, 0x4c, 0x3a, 0xdb, 0x60, 0x3f, + 0x45, 0x58, 0x54, 0x52, 0x41, 0x20, 0x49, 0x47, 0x4e, 0x4f, 0x52, 0x45, + 0x44, 0x0d, 0x00, 0x3f, 0x52, 0x45, 0x45, 0x4e, 0x54, 0x45, 0x52, 0x0d, + 0x00, 0xd0, 0x04, 0xa0, 0x00, 0xf0, 0x03, 0x20, 0xe3, 0xdf, 0x85, 0x85, + 0x84, 0x86, 0x20, 0x65, 0xd3, 0xf0, 0x04, 0xa2, 0x00, 0xf0, 0x69, 0x9a, + 0xe8, 0xe8, 0xe8, 0xe8, 0x8a, 0xe8, 0xe8, 0xe8, 0xe8, 0xe8, 0xe8, 0x86, + 0x60, 0xa0, 0x01, 0x20, 0xf9, 0xea, 0xba, 0xbd, 0x09, 0x01, 0x85, 0xa2, + 0xa5, 0x85, 0xa4, 0x86, 0x20, 0xbe, 0xe7, 0x20, 0x27, 0xeb, 0xa0, 0x01, + 0x20, 0xb4, 0xeb, 0xba, 0x38, 0xfd, 0x09, 0x01, 0xf0, 0x17, 0xbd, 0x0f, + 0x01, 0x85, 0x75, 0xbd, 0x10, 0x01, 0x85, 0x76, 0xbd, 0x12, 0x01, 0x85, + 0xb8, 0xbd, 0x11, 0x01, 0x85, 0xb9, 0x4c, 0xd2, 0xd7, 0x8a, 0x69, 0x11, + 0xaa, 0x9a, 0x20, 0xb7, 0x00, 0xc9, 0x2c, 0xd0, 0xf1, 0x20, 0xb1, 0x00, + 0x20, 0xff, 0xdc, 0x20, 0x7b, 0xdd, 0x18, 0x24, 0x38, 0x24, 0x11, 0x30, + 0x03, 0xb0, 0x03, 0x60, 0xb0, 0xfd, 0xa2, 0xa3, 0x4c, 0x12, 0xd4, 0xa6, + 0xb8, 0xd0, 0x02, 0xc6, 0xb9, 0xc6, 0xb8, 0xa2, 0x00, 0x24, 0x48, 0x8a, + 0x48, 0xa9, 0x01, 0x20, 0xd6, 0xd3, 0x20, 0x60, 0xde, 0xa9, 0x00, 0x85, + 0x89, 0x20, 0xb7, 0x00, 0x38, 0xe9, 0xcf, 0x90, 0x17, 0xc9, 0x03, 0xb0, + 0x13, 0xc9, 0x01, 0x2a, 0x49, 0x01, 0x45, 0x89, 0xc5, 0x89, 0x90, 0x61, + 0x85, 0x89, 0x20, 0xb1, 0x00, 0x4c, 0x98, 0xdd, 0xa6, 0x89, 0xd0, 0x2c, + 0xb0, 0x7b, 0x69, 0x07, 0x90, 0x77, 0x65, 0x11, 0xd0, 0x03, 0x4c, 0x97, + 0xe5, 0x69, 0xff, 0x85, 0x5e, 0x0a, 0x65, 0x5e, 0xa8, 0x68, 0xd9, 0xb2, + 0xd0, 0xb0, 0x67, 0x20, 0x6a, 0xdd, 0x48, 0x20, 0xfd, 0xdd, 0x68, 0xa4, + 0x87, 0x10, 0x17, 0xaa, 0xf0, 0x56, 0xd0, 0x5f, 0x46, 0x11, 0x8a, 0x2a, + 0xa6, 0xb8, 0xd0, 0x02, 0xc6, 0xb9, 0xc6, 0xb8, 0xa0, 0x1b, 0x85, 0x89, + 0xd0, 0xd7, 0xd9, 0xb2, 0xd0, 0xb0, 0x48, 0x90, 0xd9, 0xb9, 0xb4, 0xd0, + 0x48, 0xb9, 0xb3, 0xd0, 0x48, 0x20, 0x10, 0xde, 0xa5, 0x89, 0x4c, 0x86, + 0xdd, 0x4c, 0xc9, 0xde, 0xa5, 0xa2, 0xbe, 0xb2, 0xd0, 0xa8, 0x68, 0x85, + 0x5e, 0xe6, 0x5e, 0x68, 0x85, 0x5f, 0x98, 0x48, 0x20, 0x72, 0xeb, 0xa5, + 0xa1, 0x48, 0xa5, 0xa0, 0x48, 0xa5, 0x9f, 0x48, 0xa5, 0x9e, 0x48, 0xa5, + 0x9d, 0x48, 0x6c, 0x5e, 0x00, 0xa0, 0xff, 0x68, 0xf0, 0x23, 0xc9, 0x64, + 0xf0, 0x03, 0x20, 0x6a, 0xdd, 0x84, 0x87, 0x68, 0x4a, 0x85, 0x16, 0x68, + 0x85, 0xa5, 0x68, 0x85, 0xa6, 0x68, 0x85, 0xa7, 0x68, 0x85, 0xa8, 0x68, + 0x85, 0xa9, 0x68, 0x85, 0xaa, 0x45, 0xa2, 0x85, 0xab, 0xa5, 0x9d, 0x60, + 0xa9, 0x00, 0x85, 0x11, 0x20, 0xb1, 0x00, 0xb0, 0x03, 0x4c, 0x4a, 0xec, + 0x20, 0x7d, 0xe0, 0xb0, 0x64, 0xc9, 0x2e, 0xf0, 0xf4, 0xc9, 0xc9, 0xf0, + 0x55, 0xc9, 0xc8, 0xf0, 0xe7, 0xc9, 0x22, 0xd0, 0x0f, 0xa5, 0xb8, 0xa4, + 0xb9, 0x69, 0x00, 0x90, 0x01, 0xc8, 0x20, 0xe7, 0xe3, 0x4c, 0x3d, 0xe7, + 0xc9, 0xc6, 0xd0, 0x10, 0xa0, 0x18, 0xd0, 0x38, 0xa5, 0x9d, 0xd0, 0x03, + 0xa0, 0x01, 0x2c, 0xa0, 0x00, 0x4c, 0x01, 0xe3, 0xc9, 0xc2, 0xd0, 0x03, + 0x4c, 0x54, 0xe3, 0xc9, 0xd2, 0x90, 0x03, 0x4c, 0x0c, 0xdf, 0x20, 0xbb, + 0xde, 0x20, 0x7b, 0xdd, 0xa9, 0x29, 0x2c, 0xa9, 0x28, 0x2c, 0xa9, 0x2c, + 0xa0, 0x00, 0xd1, 0xb8, 0xd0, 0x03, 0x4c, 0xb1, 0x00, 0xa2, 0x10, 0x4c, + 0x12, 0xd4, 0xa0, 0x15, 0x68, 0x68, 0x4c, 0xd7, 0xdd, 0x20, 0xe3, 0xdf, + 0x85, 0xa0, 0x84, 0xa1, 0xa6, 0x11, 0xf0, 0x05, 0xa2, 0x00, 0x86, 0xac, + 0x60, 0xa6, 0x12, 0x10, 0x0d, 0xa0, 0x00, 0xb1, 0xa0, 0xaa, 0xc8, 0xb1, + 0xa0, 0xa8, 0x8a, 0x4c, 0xf2, 0xe2, 0x4c, 0xf9, 0xea, 0x20, 0xb1, 0x00, + 0x20, 0xec, 0xf1, 0x8a, 0xa4, 0xf0, 0x20, 0x71, 0xf8, 0xa8, 0x20, 0x01, + 0xe3, 0x4c, 0xb8, 0xde, 0xc9, 0xd7, 0xf0, 0xe9, 0x0a, 0x48, 0xaa, 0x20, + 0xb1, 0x00, 0xe0, 0xcf, 0x90, 0x20, 0x20, 0xbb, 0xde, 0x20, 0x7b, 0xdd, + 0x20, 0xbe, 0xde, 0x20, 0x6c, 0xdd, 0x68, 0xaa, 0xa5, 0xa1, 0x48, 0xa5, + 0xa0, 0x48, 0x8a, 0x48, 0x20, 0xf8, 0xe6, 0x68, 0xa8, 0x8a, 0x48, 0x4c, + 0x3f, 0xdf, 0x20, 0xb2, 0xde, 0x68, 0xa8, 0xb9, 0xdc, 0xcf, 0x85, 0x91, + 0xb9, 0xdd, 0xcf, 0x85, 0x92, 0x20, 0x90, 0x00, 0x4c, 0x6a, 0xdd, 0xa5, + 0xa5, 0x05, 0x9d, 0xd0, 0x0b, 0xa5, 0xa5, 0xf0, 0x04, 0xa5, 0x9d, 0xd0, + 0x03, 0xa0, 0x00, 0x2c, 0xa0, 0x01, 0x4c, 0x01, 0xe3, 0x20, 0x6d, 0xdd, + 0xb0, 0x13, 0xa5, 0xaa, 0x09, 0x7f, 0x25, 0xa6, 0x85, 0xa6, 0xa9, 0xa5, + 0xa0, 0x00, 0x20, 0xb2, 0xeb, 0xaa, 0x4c, 0xb0, 0xdf, 0xa9, 0x00, 0x85, + 0x11, 0xc6, 0x89, 0x20, 0x00, 0xe6, 0x85, 0x9d, 0x86, 0x9e, 0x84, 0x9f, + 0xa5, 0xa8, 0xa4, 0xa9, 0x20, 0x04, 0xe6, 0x86, 0xa8, 0x84, 0xa9, 0xaa, + 0x38, 0xe5, 0x9d, 0xf0, 0x08, 0xa9, 0x01, 0x90, 0x04, 0xa6, 0x9d, 0xa9, + 0xff, 0x85, 0xa2, 0xa0, 0xff, 0xe8, 0xc8, 0xca, 0xd0, 0x07, 0xa6, 0xa2, + 0x30, 0x0f, 0x18, 0x90, 0x0c, 0xb1, 0xa8, 0xd1, 0x9e, 0xf0, 0xef, 0xa2, + 0xff, 0xb0, 0x02, 0xa2, 0x01, 0xe8, 0x8a, 0x2a, 0x25, 0x16, 0xf0, 0x02, + 0xa9, 0x01, 0x4c, 0x93, 0xeb, 0x20, 0xfb, 0xe6, 0x20, 0x1e, 0xfb, 0x4c, + 0x01, 0xe3, 0x20, 0xbe, 0xde, 0xaa, 0x20, 0xe8, 0xdf, 0x20, 0xb7, 0x00, + 0xd0, 0xf4, 0x60, 0xa2, 0x00, 0x20, 0xb7, 0x00, 0x86, 0x10, 0x85, 0x81, + 0x20, 0xb7, 0x00, 0x20, 0x7d, 0xe0, 0xb0, 0x03, 0x4c, 0xc9, 0xde, 0xa2, + 0x00, 0x86, 0x11, 0x86, 0x12, 0x4c, 0x07, 0xe0, 0x4c, 0x28, 0xf1, 0x4c, + 0x3c, 0xd4, 0xc4, 0x20, 0xb1, 0x00, 0x90, 0x05, 0x20, 0x7d, 0xe0, 0x90, + 0x0b, 0xaa, 0x20, 0xb1, 0x00, 0x90, 0xfb, 0x20, 0x7d, 0xe0, 0xb0, 0xf6, + 0xc9, 0x24, 0xd0, 0x06, 0xa9, 0xff, 0x85, 0x11, 0xd0, 0x10, 0xc9, 0x25, + 0xd0, 0x13, 0xa5, 0x14, 0x30, 0xc6, 0xa9, 0x80, 0x85, 0x12, 0x05, 0x81, + 0x85, 0x81, 0x8a, 0x09, 0x80, 0xaa, 0x20, 0xb1, 0x00, 0x86, 0x82, 0x38, + 0x05, 0x14, 0xe9, 0x28, 0xd0, 0x03, 0x4c, 0x1e, 0xe1, 0x24, 0x14, 0x30, + 0x02, 0x70, 0xf7, 0xa9, 0x00, 0x85, 0x14, 0xa5, 0x69, 0xa6, 0x6a, 0xa0, + 0x00, 0x86, 0x9c, 0x85, 0x9b, 0xe4, 0x6c, 0xd0, 0x04, 0xc5, 0x6b, 0xf0, + 0x22, 0xa5, 0x81, 0xd1, 0x9b, 0xd0, 0x08, 0xa5, 0x82, 0xc8, 0xd1, 0x9b, + 0xf0, 0x6c, 0x88, 0x18, 0xa5, 0x9b, 0x69, 0x07, 0x90, 0xe1, 0xe8, 0xd0, + 0xdc, 0xc9, 0x41, 0x90, 0x05, 0xe9, 0x5b, 0x38, 0xe9, 0xa5, 0x60, 0x68, + 0x48, 0xc9, 0xd7, 0xd0, 0x0f, 0xba, 0xbd, 0x02, 0x01, 0xc9, 0xde, 0xd0, + 0x07, 0xa9, 0x9a, 0xa0, 0xe0, 0x60, 0x00, 0x00, 0xa5, 0x6b, 0xa4, 0x6c, + 0x85, 0x9b, 0x84, 0x9c, 0xa5, 0x6d, 0xa4, 0x6e, 0x85, 0x96, 0x84, 0x97, + 0x18, 0x69, 0x07, 0x90, 0x01, 0xc8, 0x85, 0x94, 0x84, 0x95, 0x20, 0x93, + 0xd3, 0xa5, 0x94, 0xa4, 0x95, 0xc8, 0x85, 0x6b, 0x84, 0x6c, 0xa0, 0x00, + 0xa5, 0x81, 0x91, 0x9b, 0xc8, 0xa5, 0x82, 0x91, 0x9b, 0xa9, 0x00, 0xc8, + 0x91, 0x9b, 0xc8, 0x91, 0x9b, 0xc8, 0x91, 0x9b, 0xc8, 0x91, 0x9b, 0xc8, + 0x91, 0x9b, 0xa5, 0x9b, 0x18, 0x69, 0x02, 0xa4, 0x9c, 0x90, 0x01, 0xc8, + 0x85, 0x83, 0x84, 0x84, 0x60, 0xa5, 0x0f, 0x0a, 0x69, 0x05, 0x65, 0x9b, + 0xa4, 0x9c, 0x90, 0x01, 0xc8, 0x85, 0x94, 0x84, 0x95, 0x60, 0x90, 0x80, + 0x00, 0x00, 0x20, 0xb1, 0x00, 0x20, 0x67, 0xdd, 0xa5, 0xa2, 0x30, 0x0d, + 0xa5, 0x9d, 0xc9, 0x90, 0x90, 0x09, 0xa9, 0xfe, 0xa0, 0xe0, 0x20, 0xb2, + 0xeb, 0xd0, 0x7e, 0x4c, 0xf2, 0xeb, 0xa5, 0x14, 0xd0, 0x47, 0xa5, 0x10, + 0x05, 0x12, 0x48, 0xa5, 0x11, 0x48, 0xa0, 0x00, 0x98, 0x48, 0xa5, 0x82, + 0x48, 0xa5, 0x81, 0x48, 0x20, 0x02, 0xe1, 0x68, 0x85, 0x81, 0x68, 0x85, + 0x82, 0x68, 0xa8, 0xba, 0xbd, 0x02, 0x01, 0x48, 0xbd, 0x01, 0x01, 0x48, + 0xa5, 0xa0, 0x9d, 0x02, 0x01, 0xa5, 0xa1, 0x9d, 0x01, 0x01, 0xc8, 0x20, + 0xb7, 0x00, 0xc9, 0x2c, 0xf0, 0xd2, 0x84, 0x0f, 0x20, 0xb8, 0xde, 0x68, + 0x85, 0x11, 0x68, 0x85, 0x12, 0x29, 0x7f, 0x85, 0x10, 0xa6, 0x6b, 0xa5, + 0x6c, 0x86, 0x9b, 0x85, 0x9c, 0xc5, 0x6e, 0xd0, 0x04, 0xe4, 0x6d, 0xf0, + 0x3f, 0xa0, 0x00, 0xb1, 0x9b, 0xc8, 0xc5, 0x81, 0xd0, 0x06, 0xa5, 0x82, + 0xd1, 0x9b, 0xf0, 0x16, 0xc8, 0xb1, 0x9b, 0x18, 0x65, 0x9b, 0xaa, 0xc8, + 0xb1, 0x9b, 0x65, 0x9c, 0x90, 0xd7, 0xa2, 0x6b, 0x2c, 0xa2, 0x35, 0x4c, + 0x12, 0xd4, 0xa2, 0x78, 0xa5, 0x10, 0xd0, 0xf7, 0xa5, 0x14, 0xf0, 0x02, + 0x38, 0x60, 0x20, 0xed, 0xe0, 0xa5, 0x0f, 0xa0, 0x04, 0xd1, 0x9b, 0xd0, + 0xe1, 0x4c, 0x4b, 0xe2, 0xa5, 0x14, 0xf0, 0x05, 0xa2, 0x2a, 0x4c, 0x12, + 0xd4, 0x20, 0xed, 0xe0, 0x20, 0xe3, 0xd3, 0xa9, 0x00, 0xa8, 0x85, 0xae, + 0xa2, 0x05, 0xa5, 0x81, 0x91, 0x9b, 0x10, 0x01, 0xca, 0xc8, 0xa5, 0x82, + 0x91, 0x9b, 0x10, 0x02, 0xca, 0xca, 0x86, 0xad, 0xa5, 0x0f, 0xc8, 0xc8, + 0xc8, 0x91, 0x9b, 0xa2, 0x0b, 0xa9, 0x00, 0x24, 0x10, 0x50, 0x08, 0x68, + 0x18, 0x69, 0x01, 0xaa, 0x68, 0x69, 0x00, 0xc8, 0x91, 0x9b, 0xc8, 0x8a, + 0x91, 0x9b, 0x20, 0xad, 0xe2, 0x86, 0xad, 0x85, 0xae, 0xa4, 0x5e, 0xc6, + 0x0f, 0xd0, 0xdc, 0x65, 0x95, 0xb0, 0x5d, 0x85, 0x95, 0xa8, 0x8a, 0x65, + 0x94, 0x90, 0x03, 0xc8, 0xf0, 0x52, 0x20, 0xe3, 0xd3, 0x85, 0x6d, 0x84, + 0x6e, 0xa9, 0x00, 0xe6, 0xae, 0xa4, 0xad, 0xf0, 0x05, 0x88, 0x91, 0x94, + 0xd0, 0xfb, 0xc6, 0x95, 0xc6, 0xae, 0xd0, 0xf5, 0xe6, 0x95, 0x38, 0xa5, + 0x6d, 0xe5, 0x9b, 0xa0, 0x02, 0x91, 0x9b, 0xa5, 0x6e, 0xc8, 0xe5, 0x9c, + 0x91, 0x9b, 0xa5, 0x10, 0xd0, 0x62, 0xc8, 0xb1, 0x9b, 0x85, 0x0f, 0xa9, + 0x00, 0x85, 0xad, 0x85, 0xae, 0xc8, 0x68, 0xaa, 0x85, 0xa0, 0x68, 0x85, + 0xa1, 0xd1, 0x9b, 0x90, 0x0e, 0xd0, 0x06, 0xc8, 0x8a, 0xd1, 0x9b, 0x90, + 0x07, 0x4c, 0x96, 0xe1, 0x4c, 0x10, 0xd4, 0xc8, 0xa5, 0xae, 0x05, 0xad, + 0x18, 0xf0, 0x0a, 0x20, 0xad, 0xe2, 0x8a, 0x65, 0xa0, 0xaa, 0x98, 0xa4, + 0x5e, 0x65, 0xa1, 0x86, 0xad, 0xc6, 0x0f, 0xd0, 0xca, 0x85, 0xae, 0xa2, + 0x05, 0xa5, 0x81, 0x10, 0x01, 0xca, 0xa5, 0x82, 0x10, 0x02, 0xca, 0xca, + 0x86, 0x64, 0xa9, 0x00, 0x20, 0xb6, 0xe2, 0x8a, 0x65, 0x94, 0x85, 0x83, + 0x98, 0x65, 0x95, 0x85, 0x84, 0xa8, 0xa5, 0x83, 0x60, 0x84, 0x5e, 0xb1, + 0x9b, 0x85, 0x64, 0x88, 0xb1, 0x9b, 0x85, 0x65, 0xa9, 0x10, 0x85, 0x99, + 0xa2, 0x00, 0xa0, 0x00, 0x8a, 0x0a, 0xaa, 0x98, 0x2a, 0xa8, 0xb0, 0xa4, + 0x06, 0xad, 0x26, 0xae, 0x90, 0x0b, 0x18, 0x8a, 0x65, 0x64, 0xaa, 0x98, + 0x65, 0x65, 0xa8, 0xb0, 0x93, 0xc6, 0x99, 0xd0, 0xe3, 0x60, 0xa5, 0x11, + 0xf0, 0x03, 0x20, 0x00, 0xe6, 0x20, 0x84, 0xe4, 0x38, 0xa5, 0x6f, 0xe5, + 0x6d, 0xa8, 0xa5, 0x70, 0xe5, 0x6e, 0xa2, 0x00, 0x86, 0x11, 0x85, 0x9e, + 0x84, 0x9f, 0xa2, 0x90, 0x4c, 0x9b, 0xeb, 0xa4, 0x24, 0xa9, 0x00, 0x38, + 0xf0, 0xec, 0xa6, 0x76, 0xe8, 0xd0, 0xa1, 0xa2, 0x95, 0x2c, 0xa2, 0xe0, + 0x4c, 0x12, 0xd4, 0x20, 0x41, 0xe3, 0x20, 0x06, 0xe3, 0x20, 0xbb, 0xde, + 0xa9, 0x80, 0x85, 0x14, 0x20, 0xe3, 0xdf, 0x20, 0x6a, 0xdd, 0x20, 0xb8, + 0xde, 0xa9, 0xd0, 0x20, 0xc0, 0xde, 0x48, 0xa5, 0x84, 0x48, 0xa5, 0x83, + 0x48, 0xa5, 0xb9, 0x48, 0xa5, 0xb8, 0x48, 0x20, 0x95, 0xd9, 0x4c, 0xaf, + 0xe3, 0xa9, 0xc2, 0x20, 0xc0, 0xde, 0x09, 0x80, 0x85, 0x14, 0x20, 0xea, + 0xdf, 0x85, 0x8a, 0x84, 0x8b, 0x4c, 0x6a, 0xdd, 0x20, 0x41, 0xe3, 0xa5, + 0x8b, 0x48, 0xa5, 0x8a, 0x48, 0x20, 0xb2, 0xde, 0x20, 0x6a, 0xdd, 0x68, + 0x85, 0x8a, 0x68, 0x85, 0x8b, 0xa0, 0x02, 0xb1, 0x8a, 0x85, 0x83, 0xaa, + 0xc8, 0xb1, 0x8a, 0xf0, 0x99, 0x85, 0x84, 0xc8, 0xb1, 0x83, 0x48, 0x88, + 0x10, 0xfa, 0xa4, 0x84, 0x20, 0x2b, 0xeb, 0xa5, 0xb9, 0x48, 0xa5, 0xb8, + 0x48, 0xb1, 0x8a, 0x85, 0xb8, 0xc8, 0xb1, 0x8a, 0x85, 0xb9, 0xa5, 0x84, + 0x48, 0xa5, 0x83, 0x48, 0x20, 0x67, 0xdd, 0x68, 0x85, 0x8a, 0x68, 0x85, + 0x8b, 0x20, 0xb7, 0x00, 0xf0, 0x03, 0x4c, 0xc9, 0xde, 0x68, 0x85, 0xb8, + 0x68, 0x85, 0xb9, 0xa0, 0x00, 0x68, 0x91, 0x8a, 0x68, 0xc8, 0x91, 0x8a, + 0x68, 0xc8, 0x91, 0x8a, 0x68, 0xc8, 0x91, 0x8a, 0x68, 0xc8, 0x91, 0x8a, + 0x60, 0x20, 0x6a, 0xdd, 0xa0, 0x00, 0x20, 0x36, 0xed, 0x68, 0x68, 0xa9, + 0xff, 0xa0, 0x00, 0xf0, 0x12, 0xa6, 0xa0, 0xa4, 0xa1, 0x86, 0x8c, 0x84, + 0x8d, 0x20, 0x52, 0xe4, 0x86, 0x9e, 0x84, 0x9f, 0x85, 0x9d, 0x60, 0xa2, + 0x22, 0x86, 0x0d, 0x86, 0x0e, 0x85, 0xab, 0x84, 0xac, 0x85, 0x9e, 0x84, + 0x9f, 0xa0, 0xff, 0xc8, 0xb1, 0xab, 0xf0, 0x0c, 0xc5, 0x0d, 0xf0, 0x04, + 0xc5, 0x0e, 0xd0, 0xf3, 0xc9, 0x22, 0xf0, 0x01, 0x18, 0x84, 0x9d, 0x98, + 0x65, 0xab, 0x85, 0xad, 0xa6, 0xac, 0x90, 0x01, 0xe8, 0x86, 0xae, 0xa5, + 0xac, 0xf0, 0x04, 0xc9, 0x02, 0xd0, 0x0b, 0x98, 0x20, 0xd5, 0xe3, 0xa6, + 0xab, 0xa4, 0xac, 0x20, 0xe2, 0xe5, 0xa6, 0x52, 0xe0, 0x5e, 0xd0, 0x05, + 0xa2, 0xbf, 0x4c, 0x12, 0xd4, 0xa5, 0x9d, 0x95, 0x00, 0xa5, 0x9e, 0x95, + 0x01, 0xa5, 0x9f, 0x95, 0x02, 0xa0, 0x00, 0x86, 0xa0, 0x84, 0xa1, 0x88, + 0x84, 0x11, 0x86, 0x53, 0xe8, 0xe8, 0xe8, 0x86, 0x52, 0x60, 0x46, 0x13, + 0x48, 0x49, 0xff, 0x38, 0x65, 0x6f, 0xa4, 0x70, 0xb0, 0x01, 0x88, 0xc4, + 0x6e, 0x90, 0x11, 0xd0, 0x04, 0xc5, 0x6d, 0x90, 0x0b, 0x85, 0x6f, 0x84, + 0x70, 0x85, 0x71, 0x84, 0x72, 0xaa, 0x68, 0x60, 0xa2, 0x4d, 0xa5, 0x13, + 0x30, 0xb8, 0x20, 0x84, 0xe4, 0xa9, 0x80, 0x85, 0x13, 0x68, 0xd0, 0xd0, + 0xa6, 0x73, 0xa5, 0x74, 0x86, 0x6f, 0x85, 0x70, 0xa0, 0x00, 0x84, 0x8b, + 0xa5, 0x6d, 0xa6, 0x6e, 0x85, 0x9b, 0x86, 0x9c, 0xa9, 0x55, 0xa2, 0x00, + 0x85, 0x5e, 0x86, 0x5f, 0xc5, 0x52, 0xf0, 0x05, 0x20, 0x23, 0xe5, 0xf0, + 0xf7, 0xa9, 0x07, 0x85, 0x8f, 0xa5, 0x69, 0xa6, 0x6a, 0x85, 0x5e, 0x86, + 0x5f, 0xe4, 0x6c, 0xd0, 0x04, 0xc5, 0x6b, 0xf0, 0x05, 0x20, 0x19, 0xe5, + 0xf0, 0xf3, 0x85, 0x94, 0x86, 0x95, 0xa9, 0x03, 0x85, 0x8f, 0xa5, 0x94, + 0xa6, 0x95, 0xe4, 0x6e, 0xd0, 0x07, 0xc5, 0x6d, 0xd0, 0x03, 0x4c, 0x62, + 0xe5, 0x85, 0x5e, 0x86, 0x5f, 0xa0, 0x00, 0xb1, 0x5e, 0xaa, 0xc8, 0xb1, + 0x5e, 0x08, 0xc8, 0xb1, 0x5e, 0x65, 0x94, 0x85, 0x94, 0xc8, 0xb1, 0x5e, + 0x65, 0x95, 0x85, 0x95, 0x28, 0x10, 0xd3, 0x8a, 0x30, 0xd0, 0xc8, 0xb1, + 0x5e, 0xa0, 0x00, 0x0a, 0x69, 0x05, 0x65, 0x5e, 0x85, 0x5e, 0x90, 0x02, + 0xe6, 0x5f, 0xa6, 0x5f, 0xe4, 0x95, 0xd0, 0x04, 0xc5, 0x94, 0xf0, 0xba, + 0x20, 0x23, 0xe5, 0xf0, 0xf3, 0xb1, 0x5e, 0x30, 0x35, 0xc8, 0xb1, 0x5e, + 0x10, 0x30, 0xc8, 0xb1, 0x5e, 0xf0, 0x2b, 0xc8, 0xb1, 0x5e, 0xaa, 0xc8, + 0xb1, 0x5e, 0xc5, 0x70, 0x90, 0x06, 0xd0, 0x1e, 0xe4, 0x6f, 0xb0, 0x1a, + 0xc5, 0x9c, 0x90, 0x16, 0xd0, 0x04, 0xe4, 0x9b, 0x90, 0x10, 0x86, 0x9b, + 0x85, 0x9c, 0xa5, 0x5e, 0xa6, 0x5f, 0x85, 0x8a, 0x86, 0x8b, 0xa5, 0x8f, + 0x85, 0x91, 0xa5, 0x8f, 0x18, 0x65, 0x5e, 0x85, 0x5e, 0x90, 0x02, 0xe6, + 0x5f, 0xa6, 0x5f, 0xa0, 0x00, 0x60, 0xa6, 0x8b, 0xf0, 0xf7, 0xa5, 0x91, + 0x29, 0x04, 0x4a, 0xa8, 0x85, 0x91, 0xb1, 0x8a, 0x65, 0x9b, 0x85, 0x96, + 0xa5, 0x9c, 0x69, 0x00, 0x85, 0x97, 0xa5, 0x6f, 0xa6, 0x70, 0x85, 0x94, + 0x86, 0x95, 0x20, 0x9a, 0xd3, 0xa4, 0x91, 0xc8, 0xa5, 0x94, 0x91, 0x8a, + 0xaa, 0xe6, 0x95, 0xa5, 0x95, 0xc8, 0x91, 0x8a, 0x4c, 0x88, 0xe4, 0xa5, + 0xa1, 0x48, 0xa5, 0xa0, 0x48, 0x20, 0x60, 0xde, 0x20, 0x6c, 0xdd, 0x68, + 0x85, 0xab, 0x68, 0x85, 0xac, 0xa0, 0x00, 0xb1, 0xab, 0x18, 0x71, 0xa0, + 0x90, 0x05, 0xa2, 0xb0, 0x4c, 0x12, 0xd4, 0x20, 0xd5, 0xe3, 0x20, 0xd4, + 0xe5, 0xa5, 0x8c, 0xa4, 0x8d, 0x20, 0x04, 0xe6, 0x20, 0xe6, 0xe5, 0xa5, + 0xab, 0xa4, 0xac, 0x20, 0x04, 0xe6, 0x20, 0x2a, 0xe4, 0x4c, 0x95, 0xdd, + 0xa0, 0x00, 0xb1, 0xab, 0x48, 0xc8, 0xb1, 0xab, 0xaa, 0xc8, 0xb1, 0xab, + 0xa8, 0x68, 0x86, 0x5e, 0x84, 0x5f, 0xa8, 0xf0, 0x0a, 0x48, 0x88, 0xb1, + 0x5e, 0x91, 0x71, 0x98, 0xd0, 0xf8, 0x68, 0x18, 0x65, 0x71, 0x85, 0x71, + 0x90, 0x02, 0xe6, 0x72, 0x60, 0x20, 0x6c, 0xdd, 0xa5, 0xa0, 0xa4, 0xa1, + 0x85, 0x5e, 0x84, 0x5f, 0x20, 0x35, 0xe6, 0x08, 0xa0, 0x00, 0xb1, 0x5e, + 0x48, 0xc8, 0xb1, 0x5e, 0xaa, 0xc8, 0xb1, 0x5e, 0xa8, 0x68, 0x28, 0xd0, + 0x13, 0xc4, 0x70, 0xd0, 0x0f, 0xe4, 0x6f, 0xd0, 0x0b, 0x48, 0x18, 0x65, + 0x6f, 0x85, 0x6f, 0x90, 0x02, 0xe6, 0x70, 0x68, 0x86, 0x5e, 0x84, 0x5f, + 0x60, 0xc4, 0x54, 0xd0, 0x0c, 0xc5, 0x53, 0xd0, 0x08, 0x85, 0x52, 0xe9, + 0x03, 0x85, 0x53, 0xa0, 0x00, 0x60, 0x20, 0xfb, 0xe6, 0x8a, 0x48, 0xa9, + 0x01, 0x20, 0xdd, 0xe3, 0x68, 0xa0, 0x00, 0x91, 0x9e, 0x68, 0x68, 0x4c, + 0x2a, 0xe4, 0x20, 0xb9, 0xe6, 0xd1, 0x8c, 0x98, 0x90, 0x04, 0xb1, 0x8c, + 0xaa, 0x98, 0x48, 0x8a, 0x48, 0x20, 0xdd, 0xe3, 0xa5, 0x8c, 0xa4, 0x8d, + 0x20, 0x04, 0xe6, 0x68, 0xa8, 0x68, 0x18, 0x65, 0x5e, 0x85, 0x5e, 0x90, + 0x02, 0xe6, 0x5f, 0x98, 0x20, 0xe6, 0xe5, 0x4c, 0x2a, 0xe4, 0x20, 0xb9, + 0xe6, 0x18, 0xf1, 0x8c, 0x49, 0xff, 0x4c, 0x60, 0xe6, 0xa9, 0xff, 0x85, + 0xa1, 0x20, 0xb7, 0x00, 0xc9, 0x29, 0xf0, 0x06, 0x20, 0xbe, 0xde, 0x20, + 0xf8, 0xe6, 0x20, 0xb9, 0xe6, 0xca, 0x8a, 0x48, 0x18, 0xa2, 0x00, 0xf1, + 0x8c, 0xb0, 0xb8, 0x49, 0xff, 0xc5, 0xa1, 0x90, 0xb3, 0xa5, 0xa1, 0xb0, + 0xaf, 0x20, 0xb8, 0xde, 0x68, 0xa8, 0x68, 0x85, 0x91, 0x68, 0x68, 0x68, + 0xaa, 0x68, 0x85, 0x8c, 0x68, 0x85, 0x8d, 0xa5, 0x91, 0x48, 0x98, 0x48, + 0xa0, 0x00, 0x8a, 0xf0, 0x1d, 0x60, 0x20, 0xdc, 0xe6, 0x4c, 0x01, 0xe3, + 0x20, 0xfd, 0xe5, 0xa2, 0x00, 0x86, 0x11, 0xa8, 0x60, 0x20, 0xdc, 0xe6, + 0xf0, 0x08, 0xa0, 0x00, 0xb1, 0x5e, 0xa8, 0x4c, 0x01, 0xe3, 0x4c, 0x99, + 0xe1, 0x20, 0xb1, 0x00, 0x20, 0x67, 0xdd, 0x20, 0x08, 0xe1, 0xa6, 0xa0, + 0xd0, 0xf0, 0xa6, 0xa1, 0x4c, 0xb7, 0x00, 0x20, 0xdc, 0xe6, 0xd0, 0x03, + 0x4c, 0x4e, 0xe8, 0xa6, 0xb8, 0xa4, 0xb9, 0x86, 0xad, 0x84, 0xae, 0xa6, + 0x5e, 0x86, 0xb8, 0x18, 0x65, 0x5e, 0x85, 0x60, 0xa6, 0x5f, 0x86, 0xb9, + 0x90, 0x01, 0xe8, 0x86, 0x61, 0xa0, 0x00, 0xb1, 0x60, 0x48, 0xa9, 0x00, + 0x91, 0x60, 0x20, 0xb7, 0x00, 0x20, 0x4a, 0xec, 0x68, 0xa0, 0x00, 0x91, + 0x60, 0xa6, 0xad, 0xa4, 0xae, 0x86, 0xb8, 0x84, 0xb9, 0x60, 0x20, 0x67, + 0xdd, 0x20, 0x52, 0xe7, 0x20, 0xbe, 0xde, 0x4c, 0xf8, 0xe6, 0xa5, 0x9d, + 0xc9, 0x91, 0xb0, 0x9a, 0x20, 0xf2, 0xeb, 0xa5, 0xa0, 0xa4, 0xa1, 0x84, + 0x50, 0x85, 0x51, 0x60, 0xa5, 0x50, 0x48, 0xa5, 0x51, 0x48, 0x20, 0x52, + 0xe7, 0xa0, 0x00, 0xb1, 0x50, 0xa8, 0x68, 0x85, 0x51, 0x68, 0x85, 0x50, + 0x4c, 0x01, 0xe3, 0x20, 0x46, 0xe7, 0x8a, 0xa0, 0x00, 0x91, 0x50, 0x60, + 0x20, 0x46, 0xe7, 0x86, 0x85, 0xa2, 0x00, 0x20, 0xb7, 0x00, 0xf0, 0x03, + 0x20, 0x4c, 0xe7, 0x86, 0x86, 0xa0, 0x00, 0xb1, 0x50, 0x45, 0x86, 0x25, + 0x85, 0xf0, 0xf8, 0x60, 0xa9, 0x64, 0xa0, 0xee, 0x4c, 0xbe, 0xe7, 0x20, + 0xe3, 0xe9, 0xa5, 0xa2, 0x49, 0xff, 0x85, 0xa2, 0x45, 0xaa, 0x85, 0xab, + 0xa5, 0x9d, 0x4c, 0xc1, 0xe7, 0x20, 0xf0, 0xe8, 0x90, 0x3c, 0x20, 0xe3, + 0xe9, 0xd0, 0x03, 0x4c, 0x53, 0xeb, 0xa6, 0xac, 0x86, 0x92, 0xa2, 0xa5, + 0xa5, 0xa5, 0xa8, 0xf0, 0xce, 0x38, 0xe5, 0x9d, 0xf0, 0x24, 0x90, 0x12, + 0x84, 0x9d, 0xa4, 0xaa, 0x84, 0xa2, 0x49, 0xff, 0x69, 0x00, 0xa0, 0x00, + 0x84, 0x92, 0xa2, 0x9d, 0xd0, 0x04, 0xa0, 0x00, 0x84, 0xac, 0xc9, 0xf9, + 0x30, 0xc7, 0xa8, 0xa5, 0xac, 0x56, 0x01, 0x20, 0x07, 0xe9, 0x24, 0xab, + 0x10, 0x57, 0xa0, 0x9d, 0xe0, 0xa5, 0xf0, 0x02, 0xa0, 0xa5, 0x38, 0x49, + 0xff, 0x65, 0x92, 0x85, 0xac, 0xb9, 0x04, 0x00, 0xf5, 0x04, 0x85, 0xa1, + 0xb9, 0x03, 0x00, 0xf5, 0x03, 0x85, 0xa0, 0xb9, 0x02, 0x00, 0xf5, 0x02, + 0x85, 0x9f, 0xb9, 0x01, 0x00, 0xf5, 0x01, 0x85, 0x9e, 0xb0, 0x03, 0x20, + 0x9e, 0xe8, 0xa0, 0x00, 0x98, 0x18, 0xa6, 0x9e, 0xd0, 0x4a, 0xa6, 0x9f, + 0x86, 0x9e, 0xa6, 0xa0, 0x86, 0x9f, 0xa6, 0xa1, 0x86, 0xa0, 0xa6, 0xac, + 0x86, 0xa1, 0x84, 0xac, 0x69, 0x08, 0xc9, 0x20, 0xd0, 0xe4, 0xa9, 0x00, + 0x85, 0x9d, 0x85, 0xa2, 0x60, 0x65, 0x92, 0x85, 0xac, 0xa5, 0xa1, 0x65, + 0xa9, 0x85, 0xa1, 0xa5, 0xa0, 0x65, 0xa8, 0x85, 0xa0, 0xa5, 0x9f, 0x65, + 0xa7, 0x85, 0x9f, 0xa5, 0x9e, 0x65, 0xa6, 0x85, 0x9e, 0x4c, 0x8d, 0xe8, + 0x69, 0x01, 0x06, 0xac, 0x26, 0xa1, 0x26, 0xa0, 0x26, 0x9f, 0x26, 0x9e, + 0x10, 0xf2, 0x38, 0xe5, 0x9d, 0xb0, 0xc7, 0x49, 0xff, 0x69, 0x01, 0x85, + 0x9d, 0x90, 0x0e, 0xe6, 0x9d, 0xf0, 0x42, 0x66, 0x9e, 0x66, 0x9f, 0x66, + 0xa0, 0x66, 0xa1, 0x66, 0xac, 0x60, 0xa5, 0xa2, 0x49, 0xff, 0x85, 0xa2, + 0xa5, 0x9e, 0x49, 0xff, 0x85, 0x9e, 0xa5, 0x9f, 0x49, 0xff, 0x85, 0x9f, + 0xa5, 0xa0, 0x49, 0xff, 0x85, 0xa0, 0xa5, 0xa1, 0x49, 0xff, 0x85, 0xa1, + 0xa5, 0xac, 0x49, 0xff, 0x85, 0xac, 0xe6, 0xac, 0xd0, 0x0e, 0xe6, 0xa1, + 0xd0, 0x0a, 0xe6, 0xa0, 0xd0, 0x06, 0xe6, 0x9f, 0xd0, 0x02, 0xe6, 0x9e, + 0x60, 0xa2, 0x45, 0x4c, 0x12, 0xd4, 0xa2, 0x61, 0xb4, 0x04, 0x84, 0xac, + 0xb4, 0x03, 0x94, 0x04, 0xb4, 0x02, 0x94, 0x03, 0xb4, 0x01, 0x94, 0x02, + 0xa4, 0xa4, 0x94, 0x01, 0x69, 0x08, 0x30, 0xe8, 0xf0, 0xe6, 0xe9, 0x08, + 0xa8, 0xa5, 0xac, 0xb0, 0x14, 0x16, 0x01, 0x90, 0x02, 0xf6, 0x01, 0x76, + 0x01, 0x76, 0x01, 0x76, 0x02, 0x76, 0x03, 0x76, 0x04, 0x6a, 0xc8, 0xd0, + 0xec, 0x18, 0x60, 0x81, 0x00, 0x00, 0x00, 0x00, 0x03, 0x7f, 0x5e, 0x56, + 0xcb, 0x79, 0x80, 0x13, 0x9b, 0x0b, 0x64, 0x80, 0x76, 0x38, 0x93, 0x16, + 0x82, 0x38, 0xaa, 0x3b, 0x20, 0x80, 0x35, 0x04, 0xf3, 0x34, 0x81, 0x35, + 0x04, 0xf3, 0x34, 0x80, 0x80, 0x00, 0x00, 0x00, 0x80, 0x31, 0x72, 0x17, + 0xf8, 0x20, 0x82, 0xeb, 0xf0, 0x02, 0x10, 0x03, 0x4c, 0x99, 0xe1, 0xa5, + 0x9d, 0xe9, 0x7f, 0x48, 0xa9, 0x80, 0x85, 0x9d, 0xa9, 0x2d, 0xa0, 0xe9, + 0x20, 0xbe, 0xe7, 0xa9, 0x32, 0xa0, 0xe9, 0x20, 0x66, 0xea, 0xa9, 0x13, + 0xa0, 0xe9, 0x20, 0xa7, 0xe7, 0xa9, 0x18, 0xa0, 0xe9, 0x20, 0x5c, 0xef, + 0xa9, 0x37, 0xa0, 0xe9, 0x20, 0xbe, 0xe7, 0x68, 0x20, 0xd5, 0xec, 0xa9, + 0x3c, 0xa0, 0xe9, 0x20, 0xe3, 0xe9, 0xd0, 0x03, 0x4c, 0xe2, 0xe9, 0x20, + 0x0e, 0xea, 0xa9, 0x00, 0x85, 0x62, 0x85, 0x63, 0x85, 0x64, 0x85, 0x65, + 0xa5, 0xac, 0x20, 0xb0, 0xe9, 0xa5, 0xa1, 0x20, 0xb0, 0xe9, 0xa5, 0xa0, + 0x20, 0xb0, 0xe9, 0xa5, 0x9f, 0x20, 0xb0, 0xe9, 0xa5, 0x9e, 0x20, 0xb5, + 0xe9, 0x4c, 0xe6, 0xea, 0xd0, 0x03, 0x4c, 0xda, 0xe8, 0x4a, 0x09, 0x80, + 0xa8, 0x90, 0x19, 0x18, 0xa5, 0x65, 0x65, 0xa9, 0x85, 0x65, 0xa5, 0x64, + 0x65, 0xa8, 0x85, 0x64, 0xa5, 0x63, 0x65, 0xa7, 0x85, 0x63, 0xa5, 0x62, + 0x65, 0xa6, 0x85, 0x62, 0x66, 0x62, 0x66, 0x63, 0x66, 0x64, 0x66, 0x65, + 0x66, 0xac, 0x98, 0x4a, 0xd0, 0xd6, 0x60, 0x85, 0x5e, 0x84, 0x5f, 0xa0, + 0x04, 0xb1, 0x5e, 0x85, 0xa9, 0x88, 0xb1, 0x5e, 0x85, 0xa8, 0x88, 0xb1, + 0x5e, 0x85, 0xa7, 0x88, 0xb1, 0x5e, 0x85, 0xaa, 0x45, 0xa2, 0x85, 0xab, + 0xa5, 0xaa, 0x09, 0x80, 0x85, 0xa6, 0x88, 0xb1, 0x5e, 0x85, 0xa5, 0xa5, + 0x9d, 0x60, 0xa5, 0xa5, 0xf0, 0x1f, 0x18, 0x65, 0x9d, 0x90, 0x04, 0x30, + 0x1d, 0x18, 0x2c, 0x10, 0x14, 0x69, 0x80, 0x85, 0x9d, 0xd0, 0x03, 0x4c, + 0x52, 0xe8, 0xa5, 0xab, 0x85, 0xa2, 0x60, 0xa5, 0xa2, 0x49, 0xff, 0x30, + 0x05, 0x68, 0x68, 0x4c, 0x4e, 0xe8, 0x4c, 0xd5, 0xe8, 0x20, 0x63, 0xeb, + 0xaa, 0xf0, 0x10, 0x18, 0x69, 0x02, 0xb0, 0xf2, 0xa2, 0x00, 0x86, 0xab, + 0x20, 0xce, 0xe7, 0xe6, 0x9d, 0xf0, 0xe7, 0x60, 0x84, 0x20, 0x00, 0x00, + 0x00, 0x20, 0x63, 0xeb, 0xa9, 0x50, 0xa0, 0xea, 0xa2, 0x00, 0x86, 0xab, + 0x20, 0xf9, 0xea, 0x4c, 0x69, 0xea, 0x20, 0xe3, 0xe9, 0xf0, 0x76, 0x20, + 0x72, 0xeb, 0xa9, 0x00, 0x38, 0xe5, 0x9d, 0x85, 0x9d, 0x20, 0x0e, 0xea, + 0xe6, 0x9d, 0xf0, 0xba, 0xa2, 0xfc, 0xa9, 0x01, 0xa4, 0xa6, 0xc4, 0x9e, + 0xd0, 0x10, 0xa4, 0xa7, 0xc4, 0x9f, 0xd0, 0x0a, 0xa4, 0xa8, 0xc4, 0xa0, + 0xd0, 0x04, 0xa4, 0xa9, 0xc4, 0xa1, 0x08, 0x2a, 0x90, 0x09, 0xe8, 0x95, + 0x65, 0xf0, 0x32, 0x10, 0x34, 0xa9, 0x01, 0x28, 0xb0, 0x0e, 0x06, 0xa9, + 0x26, 0xa8, 0x26, 0xa7, 0x26, 0xa6, 0xb0, 0xe6, 0x30, 0xce, 0x10, 0xe2, + 0xa8, 0xa5, 0xa9, 0xe5, 0xa1, 0x85, 0xa9, 0xa5, 0xa8, 0xe5, 0xa0, 0x85, + 0xa8, 0xa5, 0xa7, 0xe5, 0x9f, 0x85, 0xa7, 0xa5, 0xa6, 0xe5, 0x9e, 0x85, + 0xa6, 0x98, 0x4c, 0xa6, 0xea, 0xa9, 0x40, 0xd0, 0xce, 0x0a, 0x0a, 0x0a, + 0x0a, 0x0a, 0x0a, 0x85, 0xac, 0x28, 0x4c, 0xe6, 0xea, 0xa2, 0x85, 0x4c, + 0x12, 0xd4, 0xa5, 0x62, 0x85, 0x9e, 0xa5, 0x63, 0x85, 0x9f, 0xa5, 0x64, + 0x85, 0xa0, 0xa5, 0x65, 0x85, 0xa1, 0x4c, 0x2e, 0xe8, 0x85, 0x5e, 0x84, + 0x5f, 0xa0, 0x04, 0xb1, 0x5e, 0x85, 0xa1, 0x88, 0xb1, 0x5e, 0x85, 0xa0, + 0x88, 0xb1, 0x5e, 0x85, 0x9f, 0x88, 0xb1, 0x5e, 0x85, 0xa2, 0x09, 0x80, + 0x85, 0x9e, 0x88, 0xb1, 0x5e, 0x85, 0x9d, 0x84, 0xac, 0x60, 0xa2, 0x98, + 0x2c, 0xa2, 0x93, 0xa0, 0x00, 0xf0, 0x04, 0xa6, 0x85, 0xa4, 0x86, 0x20, + 0x72, 0xeb, 0x86, 0x5e, 0x84, 0x5f, 0xa0, 0x04, 0xa5, 0xa1, 0x91, 0x5e, + 0x88, 0xa5, 0xa0, 0x91, 0x5e, 0x88, 0xa5, 0x9f, 0x91, 0x5e, 0x88, 0xa5, + 0xa2, 0x09, 0x7f, 0x25, 0x9e, 0x91, 0x5e, 0x88, 0xa5, 0x9d, 0x91, 0x5e, + 0x84, 0xac, 0x60, 0xa5, 0xaa, 0x85, 0xa2, 0xa2, 0x05, 0xb5, 0xa4, 0x95, + 0x9c, 0xca, 0xd0, 0xf9, 0x86, 0xac, 0x60, 0x20, 0x72, 0xeb, 0xa2, 0x06, + 0xb5, 0x9c, 0x95, 0xa4, 0xca, 0xd0, 0xf9, 0x86, 0xac, 0x60, 0xa5, 0x9d, + 0xf0, 0xfb, 0x06, 0xac, 0x90, 0xf7, 0x20, 0xc6, 0xe8, 0xd0, 0xf2, 0x4c, + 0x8f, 0xe8, 0xa5, 0x9d, 0xf0, 0x09, 0xa5, 0xa2, 0x2a, 0xa9, 0xff, 0xb0, + 0x02, 0xa9, 0x01, 0x60, 0x20, 0x82, 0xeb, 0x85, 0x9e, 0xa9, 0x00, 0x85, + 0x9f, 0xa2, 0x88, 0xa5, 0x9e, 0x49, 0xff, 0x2a, 0xa9, 0x00, 0x85, 0xa1, + 0x85, 0xa0, 0x86, 0x9d, 0x85, 0xac, 0x85, 0xa2, 0x4c, 0x29, 0xe8, 0x46, + 0xa2, 0x60, 0x85, 0x60, 0x84, 0x61, 0xa0, 0x00, 0xb1, 0x60, 0xc8, 0xaa, + 0xf0, 0xc4, 0xb1, 0x60, 0x45, 0xa2, 0x30, 0xc2, 0xe4, 0x9d, 0xd0, 0x21, + 0xb1, 0x60, 0x09, 0x80, 0xc5, 0x9e, 0xd0, 0x19, 0xc8, 0xb1, 0x60, 0xc5, + 0x9f, 0xd0, 0x12, 0xc8, 0xb1, 0x60, 0xc5, 0xa0, 0xd0, 0x0b, 0xc8, 0xa9, + 0x7f, 0xc5, 0xac, 0xb1, 0x60, 0xe5, 0xa1, 0xf0, 0x28, 0xa5, 0xa2, 0x90, + 0x02, 0x49, 0xff, 0x4c, 0x88, 0xeb, 0xa5, 0x9d, 0xf0, 0x4a, 0x38, 0xe9, + 0xa0, 0x24, 0xa2, 0x10, 0x09, 0xaa, 0xa9, 0xff, 0x85, 0xa4, 0x20, 0xa4, + 0xe8, 0x8a, 0xa2, 0x9d, 0xc9, 0xf9, 0x10, 0x06, 0x20, 0xf0, 0xe8, 0x84, + 0xa4, 0x60, 0xa8, 0xa5, 0xa2, 0x29, 0x80, 0x46, 0x9e, 0x05, 0x9e, 0x85, + 0x9e, 0x20, 0x07, 0xe9, 0x84, 0xa4, 0x60, 0xa5, 0x9d, 0xc9, 0xa0, 0xb0, + 0x20, 0x20, 0xf2, 0xeb, 0x84, 0xac, 0xa5, 0xa2, 0x84, 0xa2, 0x49, 0x80, + 0x2a, 0xa9, 0xa0, 0x85, 0x9d, 0xa5, 0xa1, 0x85, 0x0d, 0x4c, 0x29, 0xe8, + 0x85, 0x9e, 0x85, 0x9f, 0x85, 0xa0, 0x85, 0xa1, 0xa8, 0x60, 0xa0, 0x00, + 0xa2, 0x0a, 0x94, 0x99, 0xca, 0x10, 0xfb, 0x90, 0x0f, 0xc9, 0x2d, 0xd0, + 0x04, 0x86, 0xa3, 0xf0, 0x04, 0xc9, 0x2b, 0xd0, 0x05, 0x20, 0xb1, 0x00, + 0x90, 0x5b, 0xc9, 0x2e, 0xf0, 0x2e, 0xc9, 0x45, 0xd0, 0x30, 0x20, 0xb1, + 0x00, 0x90, 0x17, 0xc9, 0xc9, 0xf0, 0x0e, 0xc9, 0x2d, 0xf0, 0x0a, 0xc9, + 0xc8, 0xf0, 0x08, 0xc9, 0x2b, 0xf0, 0x04, 0xd0, 0x07, 0x66, 0x9c, 0x20, + 0xb1, 0x00, 0x90, 0x5c, 0x24, 0x9c, 0x10, 0x0e, 0xa9, 0x00, 0x38, 0xe5, + 0x9a, 0x4c, 0xa0, 0xec, 0x66, 0x9b, 0x24, 0x9b, 0x50, 0xc3, 0xa5, 0x9a, + 0x38, 0xe5, 0x99, 0x85, 0x9a, 0xf0, 0x12, 0x10, 0x09, 0x20, 0x55, 0xea, + 0xe6, 0x9a, 0xd0, 0xf9, 0xf0, 0x07, 0x20, 0x39, 0xea, 0xc6, 0x9a, 0xd0, + 0xf9, 0xa5, 0xa3, 0x30, 0x01, 0x60, 0x4c, 0xd0, 0xee, 0x48, 0x24, 0x9b, + 0x10, 0x02, 0xe6, 0x99, 0x20, 0x39, 0xea, 0x68, 0x38, 0xe9, 0x30, 0x20, + 0xd5, 0xec, 0x4c, 0x61, 0xec, 0x48, 0x20, 0x63, 0xeb, 0x68, 0x20, 0x93, + 0xeb, 0xa5, 0xaa, 0x45, 0xa2, 0x85, 0xab, 0xa6, 0x9d, 0x4c, 0xc1, 0xe7, + 0xa5, 0x9a, 0xc9, 0x0a, 0x90, 0x09, 0xa9, 0x64, 0x24, 0x9c, 0x30, 0x11, + 0x4c, 0xd5, 0xe8, 0x0a, 0x0a, 0x18, 0x65, 0x9a, 0x0a, 0x18, 0xa0, 0x00, + 0x71, 0xb8, 0x38, 0xe9, 0x30, 0x85, 0x9a, 0x4c, 0x87, 0xec, 0x9b, 0x3e, + 0xbc, 0x1f, 0xfd, 0x9e, 0x6e, 0x6b, 0x27, 0xfd, 0x9e, 0x6e, 0x6b, 0x28, + 0x00, 0xa9, 0x58, 0xa0, 0xd3, 0x20, 0x31, 0xed, 0xa5, 0x76, 0xa6, 0x75, + 0x85, 0x9e, 0x86, 0x9f, 0xa2, 0x90, 0x38, 0x20, 0xa0, 0xeb, 0x20, 0x34, + 0xed, 0x4c, 0x3a, 0xdb, 0xa0, 0x01, 0xa9, 0x2d, 0x88, 0x24, 0xa2, 0x10, + 0x04, 0xc8, 0x99, 0xff, 0x00, 0x85, 0xa2, 0x84, 0xad, 0xc8, 0xa9, 0x30, + 0xa6, 0x9d, 0xd0, 0x03, 0x4c, 0x57, 0xee, 0xa9, 0x00, 0xe0, 0x80, 0xf0, + 0x02, 0xb0, 0x09, 0xa9, 0x14, 0xa0, 0xed, 0x20, 0x7f, 0xe9, 0xa9, 0xf7, + 0x85, 0x99, 0xa9, 0x0f, 0xa0, 0xed, 0x20, 0xb2, 0xeb, 0xf0, 0x1e, 0x10, + 0x12, 0xa9, 0x0a, 0xa0, 0xed, 0x20, 0xb2, 0xeb, 0xf0, 0x02, 0x10, 0x0e, + 0x20, 0x39, 0xea, 0xc6, 0x99, 0xd0, 0xee, 0x20, 0x55, 0xea, 0xe6, 0x99, + 0xd0, 0xdc, 0x20, 0xa0, 0xe7, 0x20, 0xf2, 0xeb, 0xa2, 0x01, 0xa5, 0x99, + 0x18, 0x69, 0x0a, 0x30, 0x09, 0xc9, 0x0b, 0xb0, 0x06, 0x69, 0xff, 0xaa, + 0xa9, 0x02, 0x38, 0xe9, 0x02, 0x85, 0x9a, 0x86, 0x99, 0x8a, 0xf0, 0x02, + 0x10, 0x13, 0xa4, 0xad, 0xa9, 0x2e, 0xc8, 0x99, 0xff, 0x00, 0x8a, 0xf0, + 0x06, 0xa9, 0x30, 0xc8, 0x99, 0xff, 0x00, 0x84, 0xad, 0xa0, 0x00, 0xa2, + 0x80, 0xa5, 0xa1, 0x18, 0x79, 0x6c, 0xee, 0x85, 0xa1, 0xa5, 0xa0, 0x79, + 0x6b, 0xee, 0x85, 0xa0, 0xa5, 0x9f, 0x79, 0x6a, 0xee, 0x85, 0x9f, 0xa5, + 0x9e, 0x79, 0x69, 0xee, 0x85, 0x9e, 0xe8, 0xb0, 0x04, 0x10, 0xde, 0x30, + 0x02, 0x30, 0xda, 0x8a, 0x90, 0x04, 0x49, 0xff, 0x69, 0x0a, 0x69, 0x2f, + 0xc8, 0xc8, 0xc8, 0xc8, 0x84, 0x83, 0xa4, 0xad, 0xc8, 0xaa, 0x29, 0x7f, + 0x99, 0xff, 0x00, 0xc6, 0x99, 0xd0, 0x06, 0xa9, 0x2e, 0xc8, 0x99, 0xff, + 0x00, 0x84, 0xad, 0xa4, 0x83, 0x8a, 0x49, 0xff, 0x29, 0x80, 0xaa, 0xc0, + 0x24, 0xd0, 0xaa, 0xa4, 0xad, 0xb9, 0xff, 0x00, 0x88, 0xc9, 0x30, 0xf0, + 0xf8, 0xc9, 0x2e, 0xf0, 0x01, 0xc8, 0xa9, 0x2b, 0xa6, 0x9a, 0xf0, 0x2e, + 0x10, 0x08, 0xa9, 0x00, 0x38, 0xe5, 0x9a, 0xaa, 0xa9, 0x2d, 0x99, 0x01, + 0x01, 0xa9, 0x45, 0x99, 0x00, 0x01, 0x8a, 0xa2, 0x2f, 0x38, 0xe8, 0xe9, + 0x0a, 0xb0, 0xfb, 0x69, 0x3a, 0x99, 0x03, 0x01, 0x8a, 0x99, 0x02, 0x01, + 0xa9, 0x00, 0x99, 0x04, 0x01, 0xf0, 0x08, 0x99, 0xff, 0x00, 0xa9, 0x00, + 0x99, 0x00, 0x01, 0xa9, 0x00, 0xa0, 0x01, 0x60, 0x80, 0x00, 0x00, 0x00, + 0x00, 0xfa, 0x0a, 0x1f, 0x00, 0x00, 0x98, 0x96, 0x80, 0xff, 0xf0, 0xbd, + 0xc0, 0x00, 0x01, 0x86, 0xa0, 0xff, 0xff, 0xd8, 0xf0, 0x00, 0x00, 0x03, + 0xe8, 0xff, 0xff, 0xff, 0x9c, 0x00, 0x00, 0x00, 0x0a, 0xff, 0xff, 0xff, + 0xff, 0x20, 0x63, 0xeb, 0xa9, 0x64, 0xa0, 0xee, 0x20, 0xf9, 0xea, 0xf0, + 0x70, 0xa5, 0xa5, 0xd0, 0x03, 0x4c, 0x50, 0xe8, 0xa2, 0x8a, 0xa0, 0x00, + 0x20, 0x2b, 0xeb, 0xa5, 0xaa, 0x10, 0x0f, 0x20, 0x23, 0xec, 0xa9, 0x8a, + 0xa0, 0x00, 0x20, 0xb2, 0xeb, 0xd0, 0x03, 0x98, 0xa4, 0x0d, 0x20, 0x55, + 0xeb, 0x98, 0x48, 0x20, 0x41, 0xe9, 0xa9, 0x8a, 0xa0, 0x00, 0x20, 0x7f, + 0xe9, 0x20, 0x09, 0xef, 0x68, 0x4a, 0x90, 0x0a, 0xa5, 0x9d, 0xf0, 0x06, + 0xa5, 0xa2, 0x49, 0xff, 0x85, 0xa2, 0x60, 0x81, 0x38, 0xaa, 0x3b, 0x29, + 0x07, 0x71, 0x34, 0x58, 0x3e, 0x56, 0x74, 0x16, 0x7e, 0xb3, 0x1b, 0x77, + 0x2f, 0xee, 0xe3, 0x85, 0x7a, 0x1d, 0x84, 0x1c, 0x2a, 0x7c, 0x63, 0x59, + 0x58, 0x0a, 0x7e, 0x75, 0xfd, 0xe7, 0xc6, 0x80, 0x31, 0x72, 0x18, 0x10, + 0x81, 0x00, 0x00, 0x00, 0x00, 0xa9, 0xdb, 0xa0, 0xee, 0x20, 0x7f, 0xe9, + 0xa5, 0xac, 0x69, 0x50, 0x90, 0x03, 0x20, 0x7a, 0xeb, 0x85, 0x92, 0x20, + 0x66, 0xeb, 0xa5, 0x9d, 0xc9, 0x88, 0x90, 0x03, 0x20, 0x2b, 0xea, 0x20, + 0x23, 0xec, 0xa5, 0x0d, 0x18, 0x69, 0x81, 0xf0, 0xf3, 0x38, 0xe9, 0x01, + 0x48, 0xa2, 0x05, 0xb5, 0xa5, 0xb4, 0x9d, 0x95, 0x9d, 0x94, 0xa5, 0xca, + 0x10, 0xf5, 0xa5, 0x92, 0x85, 0xac, 0x20, 0xaa, 0xe7, 0x20, 0xd0, 0xee, + 0xa9, 0xe0, 0xa0, 0xee, 0x20, 0x72, 0xef, 0xa9, 0x00, 0x85, 0xab, 0x68, + 0x20, 0x10, 0xea, 0x60, 0x85, 0xad, 0x84, 0xae, 0x20, 0x21, 0xeb, 0xa9, + 0x93, 0x20, 0x7f, 0xe9, 0x20, 0x76, 0xef, 0xa9, 0x93, 0xa0, 0x00, 0x4c, + 0x7f, 0xe9, 0x85, 0xad, 0x84, 0xae, 0x20, 0x1e, 0xeb, 0xb1, 0xad, 0x85, + 0xa3, 0xa4, 0xad, 0xc8, 0x98, 0xd0, 0x02, 0xe6, 0xae, 0x85, 0xad, 0xa4, + 0xae, 0x20, 0x7f, 0xe9, 0xa5, 0xad, 0xa4, 0xae, 0x18, 0x69, 0x05, 0x90, + 0x01, 0xc8, 0x85, 0xad, 0x84, 0xae, 0x20, 0xbe, 0xe7, 0xa9, 0x98, 0xa0, + 0x00, 0xc6, 0xa3, 0xd0, 0xe4, 0x60, 0x98, 0x35, 0x44, 0x7a, 0x68, 0x28, + 0xb1, 0x46, 0x20, 0x82, 0xeb, 0xaa, 0x30, 0x18, 0xa9, 0xc9, 0xa0, 0x00, + 0x20, 0xf9, 0xea, 0x8a, 0xf0, 0xe7, 0xa9, 0xa6, 0xa0, 0xef, 0x20, 0x7f, + 0xe9, 0xa9, 0xaa, 0xa0, 0xef, 0x20, 0xbe, 0xe7, 0xa6, 0xa1, 0xa5, 0x9e, + 0x85, 0xa1, 0x86, 0x9e, 0xa9, 0x00, 0x85, 0xa2, 0xa5, 0x9d, 0x85, 0xac, + 0xa9, 0x80, 0x85, 0x9d, 0x20, 0x2e, 0xe8, 0xa2, 0xc9, 0xa0, 0x00, 0x4c, + 0x2b, 0xeb, 0xa9, 0x66, 0xa0, 0xf0, 0x20, 0xbe, 0xe7, 0x20, 0x63, 0xeb, + 0xa9, 0x6b, 0xa0, 0xf0, 0xa6, 0xaa, 0x20, 0x5e, 0xea, 0x20, 0x63, 0xeb, + 0x20, 0x23, 0xec, 0xa9, 0x00, 0x85, 0xab, 0x20, 0xaa, 0xe7, 0xa9, 0x70, + 0xa0, 0xf0, 0x20, 0xa7, 0xe7, 0xa5, 0xa2, 0x48, 0x10, 0x0d, 0x20, 0xa0, + 0xe7, 0xa5, 0xa2, 0x30, 0x09, 0xa5, 0x16, 0x49, 0xff, 0x85, 0x16, 0x20, + 0xd0, 0xee, 0xa9, 0x70, 0xa0, 0xf0, 0x20, 0xbe, 0xe7, 0x68, 0x10, 0x03, + 0x20, 0xd0, 0xee, 0xa9, 0x75, 0xa0, 0xf0, 0x4c, 0x5c, 0xef, 0x20, 0x21, + 0xeb, 0xa9, 0x00, 0x85, 0x16, 0x20, 0xf1, 0xef, 0xa2, 0x8a, 0xa0, 0x00, + 0x20, 0xe7, 0xef, 0xa9, 0x93, 0xa0, 0x00, 0x20, 0xf9, 0xea, 0xa9, 0x00, + 0x85, 0xa2, 0xa5, 0x16, 0x20, 0x62, 0xf0, 0xa9, 0x8a, 0xa0, 0x00, 0x4c, + 0x66, 0xea, 0x48, 0x4c, 0x23, 0xf0, 0x81, 0x49, 0x0f, 0xda, 0xa2, 0x83, + 0x49, 0x0f, 0xda, 0xa2, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x05, 0x84, 0xe6, + 0x1a, 0x2d, 0x1b, 0x86, 0x28, 0x07, 0xfb, 0xf8, 0x87, 0x99, 0x68, 0x89, + 0x01, 0x87, 0x23, 0x35, 0xdf, 0xe1, 0x86, 0xa5, 0x5d, 0xe7, 0x28, 0x83, + 0x49, 0x0f, 0xda, 0xa2, 0xa6, 0xd3, 0xc1, 0xc8, 0xd4, 0xc8, 0xd5, 0xc4, + 0xce, 0xca, 0xa5, 0xa2, 0x48, 0x10, 0x03, 0x20, 0xd0, 0xee, 0xa5, 0x9d, + 0x48, 0xc9, 0x81, 0x90, 0x07, 0xa9, 0x13, 0xa0, 0xe9, 0x20, 0x66, 0xea, + 0xa9, 0xce, 0xa0, 0xf0, 0x20, 0x5c, 0xef, 0x68, 0xc9, 0x81, 0x90, 0x07, + 0xa9, 0x66, 0xa0, 0xf0, 0x20, 0xa7, 0xe7, 0x68, 0x10, 0x03, 0x4c, 0xd0, + 0xee, 0x60, 0x0b, 0x76, 0xb3, 0x83, 0xbd, 0xd3, 0x79, 0x1e, 0xf4, 0xa6, + 0xf5, 0x7b, 0x83, 0xfc, 0xb0, 0x10, 0x7c, 0x0c, 0x1f, 0x67, 0xca, 0x7c, + 0xde, 0x53, 0xcb, 0xc1, 0x7d, 0x14, 0x64, 0x70, 0x4c, 0x7d, 0xb7, 0xea, + 0x51, 0x7a, 0x7d, 0x63, 0x30, 0x88, 0x7e, 0x7e, 0x92, 0x44, 0x99, 0x3a, + 0x7e, 0x4c, 0xcc, 0x91, 0xc7, 0x7f, 0xaa, 0xaa, 0xaa, 0x13, 0x81, 0x00, + 0x00, 0x00, 0x00, 0xe6, 0xb8, 0xd0, 0x02, 0xe6, 0xb9, 0xad, 0x60, 0xea, + 0xc9, 0x3a, 0xb0, 0x0a, 0xc9, 0x20, 0xf0, 0xef, 0x38, 0xe9, 0x30, 0x38, + 0xe9, 0xd0, 0x60, 0x80, 0x4f, 0xc7, 0x52, 0x58, 0xa2, 0xff, 0x86, 0x76, + 0xa2, 0xfb, 0x9a, 0xa9, 0x28, 0xa0, 0xf1, 0x85, 0x01, 0x84, 0x02, 0x85, + 0x04, 0x84, 0x05, 0x20, 0x73, 0xf2, 0xa9, 0x4c, 0x85, 0x00, 0x85, 0x03, + 0x85, 0x90, 0x85, 0x0a, 0xa9, 0x99, 0xa0, 0xe1, 0x85, 0x0b, 0x84, 0x0c, + 0xa2, 0x1c, 0xbd, 0x0a, 0xf1, 0x95, 0xb0, 0x86, 0xf1, 0xca, 0xd0, 0xf6, + 0x86, 0xf2, 0x8a, 0x85, 0xa4, 0x85, 0x54, 0x48, 0xa9, 0x03, 0x85, 0x8f, + 0x20, 0xfb, 0xda, 0xa9, 0x01, 0x8d, 0xfd, 0x01, 0x8d, 0xfc, 0x01, 0xa2, + 0x55, 0x86, 0x52, 0xa9, 0x00, 0xa0, 0x08, 0x85, 0x50, 0x84, 0x51, 0xa0, + 0x00, 0xe6, 0x51, 0xb1, 0x50, 0x49, 0xff, 0x91, 0x50, 0xd1, 0x50, 0xd0, + 0x08, 0x49, 0xff, 0x91, 0x50, 0xd1, 0x50, 0xf0, 0xec, 0xa4, 0x50, 0xa5, + 0x51, 0x29, 0xf0, 0x84, 0x73, 0x85, 0x74, 0x84, 0x6f, 0x85, 0x70, 0xa2, + 0x00, 0xa0, 0x08, 0x86, 0x67, 0x84, 0x68, 0xa0, 0x00, 0x84, 0xd6, 0x98, + 0x91, 0x67, 0xe6, 0x67, 0xd0, 0x02, 0xe6, 0x68, 0xa5, 0x67, 0xa4, 0x68, + 0x20, 0xe3, 0xd3, 0x20, 0x4b, 0xd6, 0xa9, 0x3a, 0xa0, 0xdb, 0x85, 0x04, + 0x84, 0x05, 0xa9, 0x3c, 0xa0, 0xd4, 0x85, 0x01, 0x84, 0x02, 0x6c, 0x01, + 0x00, 0x20, 0x67, 0xdd, 0x20, 0x52, 0xe7, 0x6c, 0x50, 0x00, 0x20, 0xf8, + 0xe6, 0x8a, 0x4c, 0x8b, 0xfe, 0x20, 0xf8, 0xe6, 0x8a, 0x4c, 0x95, 0xfe, + 0x20, 0xf8, 0xe6, 0xe0, 0x30, 0xb0, 0x13, 0x86, 0xf0, 0xa9, 0x2c, 0x20, + 0xc0, 0xde, 0x20, 0xf8, 0xe6, 0xe0, 0x30, 0xb0, 0x05, 0x86, 0x2c, 0x86, + 0x2d, 0x60, 0x4c, 0x99, 0xe1, 0x20, 0xec, 0xf1, 0xe4, 0xf0, 0xb0, 0x08, + 0xa5, 0xf0, 0x85, 0x2c, 0x85, 0x2d, 0x86, 0xf0, 0xa9, 0xc5, 0x20, 0xc0, + 0xde, 0x20, 0xf8, 0xe6, 0xe0, 0x30, 0xb0, 0xe2, 0x60, 0x20, 0xec, 0xf1, + 0x8a, 0xa4, 0xf0, 0xc0, 0x28, 0xb0, 0xd7, 0x4c, 0x00, 0xf8, 0x20, 0x09, + 0xf2, 0x8a, 0xa4, 0x2c, 0xc0, 0x28, 0xb0, 0xca, 0xa4, 0xf0, 0x4c, 0x19, + 0xf8, 0x20, 0x09, 0xf2, 0x8a, 0xa8, 0xc0, 0x28, 0xb0, 0xbc, 0xa5, 0xf0, + 0x4c, 0x28, 0xf8, 0x20, 0xf8, 0xe6, 0x8a, 0x4c, 0x64, 0xf8, 0x20, 0xf8, + 0xe6, 0xca, 0x8a, 0xc9, 0x18, 0xb0, 0xa7, 0x4c, 0x5b, 0xfb, 0x20, 0xf8, + 0xe6, 0x8a, 0x49, 0xff, 0xaa, 0xe8, 0x86, 0xf1, 0x60, 0x38, 0x90, 0x18, + 0x66, 0xf2, 0x60, 0xa9, 0xff, 0xd0, 0x02, 0xa9, 0x3f, 0xa2, 0x00, 0x85, + 0x32, 0x86, 0xf3, 0x60, 0xa9, 0x7f, 0xa2, 0x40, 0xd0, 0xf5, 0x20, 0x67, + 0xdd, 0x20, 0x52, 0xe7, 0xa5, 0x50, 0xc5, 0x6d, 0xa5, 0x51, 0xe5, 0x6e, + 0xb0, 0x03, 0x4c, 0x10, 0xd4, 0xa5, 0x50, 0x85, 0x73, 0x85, 0x6f, 0xa5, + 0x51, 0x85, 0x74, 0x85, 0x70, 0x60, 0x20, 0x67, 0xdd, 0x20, 0x52, 0xe7, + 0xa5, 0x50, 0xc5, 0x73, 0xa5, 0x51, 0xe5, 0x74, 0xb0, 0xe0, 0xa5, 0x50, + 0xc5, 0x69, 0xa5, 0x51, 0xe5, 0x6a, 0x90, 0xd6, 0xa5, 0x50, 0x85, 0x69, + 0xa5, 0x51, 0x85, 0x6a, 0x4c, 0x6c, 0xd6, 0xa9, 0xab, 0x20, 0xc0, 0xde, + 0xa5, 0xb8, 0x85, 0xf4, 0xa5, 0xb9, 0x85, 0xf5, 0x38, 0x66, 0xd8, 0xa5, + 0x75, 0x85, 0xf6, 0xa5, 0x76, 0x85, 0xf7, 0x20, 0xa6, 0xd9, 0x4c, 0x98, + 0xd9, 0x86, 0xde, 0xa6, 0xf8, 0x86, 0xdf, 0xa5, 0x75, 0x85, 0xda, 0xa5, + 0x76, 0x85, 0xdb, 0xa5, 0x79, 0x85, 0xdc, 0xa5, 0x7a, 0x85, 0xdd, 0xa5, + 0xf4, 0x85, 0xb8, 0xa5, 0xf5, 0x85, 0xb9, 0xa5, 0xf6, 0x85, 0x75, 0xa5, + 0xf7, 0x85, 0x76, 0x20, 0xb7, 0x00, 0x20, 0x3e, 0xd9, 0x4c, 0xd2, 0xd7, + 0xa5, 0xda, 0x85, 0x75, 0xa5, 0xdb, 0x85, 0x76, 0xa5, 0xdc, 0x85, 0xb8, + 0xa5, 0xdd, 0x85, 0xb9, 0xa6, 0xdf, 0x9a, 0x4c, 0xd2, 0xd7, 0x4c, 0xc9, + 0xde, 0xb0, 0xfb, 0xa6, 0xaf, 0x86, 0x69, 0xa6, 0xb0, 0x86, 0x6a, 0x20, + 0x0c, 0xda, 0x20, 0x1a, 0xd6, 0xa5, 0x9b, 0x85, 0x60, 0xa5, 0x9c, 0x85, + 0x61, 0xa9, 0x2c, 0x20, 0xc0, 0xde, 0x20, 0x0c, 0xda, 0xe6, 0x50, 0xd0, + 0x02, 0xe6, 0x51, 0x20, 0x1a, 0xd6, 0xa5, 0x9b, 0xc5, 0x60, 0xa5, 0x9c, + 0xe5, 0x61, 0xb0, 0x01, 0x60, 0xa0, 0x00, 0xb1, 0x9b, 0x91, 0x60, 0xe6, + 0x9b, 0xd0, 0x02, 0xe6, 0x9c, 0xe6, 0x60, 0xd0, 0x02, 0xe6, 0x61, 0xa5, + 0x69, 0xc5, 0x9b, 0xa5, 0x6a, 0xe5, 0x9c, 0xb0, 0xe6, 0xa6, 0x61, 0xa4, + 0x60, 0xd0, 0x01, 0xca, 0x88, 0x86, 0x6a, 0x84, 0x69, 0x4c, 0xf2, 0xd4, + 0xad, 0x56, 0xc0, 0xad, 0x53, 0xc0, 0x4c, 0x40, 0xfb, 0xad, 0x54, 0xc0, + 0x4c, 0x39, 0xfb, 0x20, 0xd9, 0xf7, 0xa0, 0x03, 0xb1, 0x9b, 0xaa, 0x88, + 0xb1, 0x9b, 0xe9, 0x01, 0xb0, 0x01, 0xca, 0x85, 0x50, 0x86, 0x51, 0x20, + 0xcd, 0xfe, 0x20, 0x77, 0xf7, 0x4c, 0xcd, 0xfe, 0x20, 0xd9, 0xf7, 0x20, + 0xfd, 0xfe, 0xa0, 0x02, 0xb1, 0x9b, 0xc5, 0x50, 0xc8, 0xb1, 0x9b, 0xe5, + 0x51, 0xb0, 0x03, 0x4c, 0x10, 0xd4, 0x20, 0x77, 0xf7, 0x4c, 0xfd, 0xfe, + 0x2c, 0x55, 0xc0, 0x2c, 0x52, 0xc0, 0xa9, 0x40, 0xd0, 0x08, 0xa9, 0x20, + 0x2c, 0x54, 0xc0, 0x2c, 0x53, 0xc0, 0x85, 0xe6, 0xad, 0x57, 0xc0, 0xad, + 0x50, 0xc0, 0xa9, 0x00, 0x85, 0x1c, 0xa5, 0xe6, 0x85, 0x1b, 0xa0, 0x00, + 0x84, 0x1a, 0xa5, 0x1c, 0x91, 0x1a, 0x20, 0x7e, 0xf4, 0xc8, 0xd0, 0xf6, + 0xe6, 0x1b, 0xa5, 0x1b, 0x29, 0x1f, 0xd0, 0xee, 0x60, 0x85, 0xe2, 0x86, + 0xe0, 0x84, 0xe1, 0x48, 0x29, 0xc0, 0x85, 0x26, 0x4a, 0x4a, 0x05, 0x26, + 0x85, 0x26, 0x68, 0x85, 0x27, 0x0a, 0x0a, 0x0a, 0x26, 0x27, 0x0a, 0x26, + 0x27, 0x0a, 0x66, 0x26, 0xa5, 0x27, 0x29, 0x1f, 0x05, 0xe6, 0x85, 0x27, + 0x8a, 0xc0, 0x00, 0xf0, 0x05, 0xa0, 0x23, 0x69, 0x04, 0xc8, 0xe9, 0x07, + 0xb0, 0xfb, 0x84, 0xe5, 0xaa, 0xbd, 0xb9, 0xf4, 0x85, 0x30, 0x98, 0x4a, + 0xa5, 0xe4, 0x85, 0x1c, 0xb0, 0x28, 0x60, 0x20, 0x11, 0xf4, 0xa5, 0x1c, + 0x51, 0x26, 0x25, 0x30, 0x51, 0x26, 0x91, 0x26, 0x60, 0x10, 0x23, 0xa5, + 0x30, 0x4a, 0xb0, 0x05, 0x49, 0xc0, 0x85, 0x30, 0x60, 0x88, 0x10, 0x02, + 0xa0, 0x27, 0xa9, 0xc0, 0x85, 0x30, 0x84, 0xe5, 0xa5, 0x1c, 0x0a, 0xc9, + 0xc0, 0x10, 0x06, 0xa5, 0x1c, 0x49, 0x7f, 0x85, 0x1c, 0x60, 0xa5, 0x30, + 0x0a, 0x49, 0x80, 0x30, 0xdd, 0xa9, 0x81, 0xc8, 0xc0, 0x28, 0x90, 0xe0, + 0xa0, 0x00, 0xb0, 0xdc, 0x18, 0xa5, 0xd1, 0x29, 0x04, 0xf0, 0x25, 0xa9, + 0x7f, 0x25, 0x30, 0x31, 0x26, 0xd0, 0x19, 0xe6, 0xea, 0xa9, 0x7f, 0x25, + 0x30, 0x10, 0x11, 0x18, 0xa5, 0xd1, 0x29, 0x04, 0xf0, 0x0e, 0xb1, 0x26, + 0x45, 0x1c, 0x25, 0x30, 0xd0, 0x02, 0xe6, 0xea, 0x51, 0x26, 0x91, 0x26, + 0xa5, 0xd1, 0x65, 0xd3, 0x29, 0x03, 0xc9, 0x02, 0x6a, 0xb0, 0x92, 0x30, + 0x30, 0x18, 0xa5, 0x27, 0x2c, 0xb9, 0xf5, 0xd0, 0x22, 0x06, 0x26, 0xb0, + 0x1a, 0x2c, 0xcd, 0xf4, 0xf0, 0x05, 0x69, 0x1f, 0x38, 0xb0, 0x12, 0x69, + 0x23, 0x48, 0xa5, 0x26, 0x69, 0xb0, 0xb0, 0x02, 0x69, 0xf0, 0x85, 0x26, + 0x68, 0xb0, 0x02, 0x69, 0x1f, 0x66, 0x26, 0x69, 0xfc, 0x85, 0x27, 0x60, + 0x18, 0xa5, 0x27, 0x69, 0x04, 0x2c, 0xb9, 0xf5, 0xd0, 0xf3, 0x06, 0x26, + 0x90, 0x18, 0x69, 0xe0, 0x18, 0x2c, 0x08, 0xf5, 0xf0, 0x12, 0xa5, 0x26, + 0x69, 0x50, 0x49, 0xf0, 0xf0, 0x02, 0x49, 0xf0, 0x85, 0x26, 0xa5, 0xe6, + 0x90, 0x02, 0x69, 0xe0, 0x66, 0x26, 0x90, 0xd1, 0x48, 0xa9, 0x00, 0x85, + 0xe0, 0x85, 0xe1, 0x85, 0xe2, 0x68, 0x48, 0x38, 0xe5, 0xe0, 0x48, 0x8a, + 0xe5, 0xe1, 0x85, 0xd3, 0xb0, 0x0a, 0x68, 0x49, 0xff, 0x69, 0x01, 0x48, + 0xa9, 0x00, 0xe5, 0xd3, 0x85, 0xd1, 0x85, 0xd5, 0x68, 0x85, 0xd0, 0x85, + 0xd4, 0x68, 0x85, 0xe0, 0x86, 0xe1, 0x98, 0x18, 0xe5, 0xe2, 0x90, 0x04, + 0x49, 0xff, 0x69, 0xfe, 0x85, 0xd2, 0x84, 0xe2, 0x66, 0xd3, 0x38, 0xe5, + 0xd0, 0xaa, 0xa9, 0xff, 0xe5, 0xd1, 0x85, 0x1d, 0xa4, 0xe5, 0xb0, 0x05, + 0x0a, 0x20, 0x65, 0xf4, 0x38, 0xa5, 0xd4, 0x65, 0xd2, 0x85, 0xd4, 0xa5, + 0xd5, 0xe9, 0x00, 0x85, 0xd5, 0xb1, 0x26, 0x45, 0x1c, 0x25, 0x30, 0x51, + 0x26, 0x91, 0x26, 0xe8, 0xd0, 0x04, 0xe6, 0x1d, 0xf0, 0x62, 0xa5, 0xd3, + 0xb0, 0xda, 0x20, 0xd3, 0xf4, 0x18, 0xa5, 0xd4, 0x65, 0xd0, 0x85, 0xd4, + 0xa5, 0xd5, 0x65, 0xd1, 0x50, 0xd9, 0x81, 0x82, 0x84, 0x88, 0x90, 0xa0, + 0xc0, 0x1c, 0xff, 0xfe, 0xfa, 0xf4, 0xec, 0xe1, 0xd4, 0xc5, 0xb4, 0xa1, + 0x8d, 0x78, 0x61, 0x49, 0x31, 0x18, 0xff, 0xa5, 0x26, 0x0a, 0xa5, 0x27, + 0x29, 0x03, 0x2a, 0x05, 0x26, 0x0a, 0x0a, 0x0a, 0x85, 0xe2, 0xa5, 0x27, + 0x4a, 0x4a, 0x29, 0x07, 0x05, 0xe2, 0x85, 0xe2, 0xa5, 0xe5, 0x0a, 0x65, + 0xe5, 0x0a, 0xaa, 0xca, 0xa5, 0x30, 0x29, 0x7f, 0xe8, 0x4a, 0xd0, 0xfc, + 0x85, 0xe1, 0x8a, 0x18, 0x65, 0xe5, 0x90, 0x02, 0xe6, 0xe1, 0x85, 0xe0, + 0x60, 0x86, 0x1a, 0x84, 0x1b, 0xaa, 0x4a, 0x4a, 0x4a, 0x4a, 0x85, 0xd3, + 0x8a, 0x29, 0x0f, 0xaa, 0xbc, 0xba, 0xf5, 0x84, 0xd0, 0x49, 0x0f, 0xaa, + 0xbc, 0xbb, 0xf5, 0xc8, 0x84, 0xd2, 0xa4, 0xe5, 0xa2, 0x00, 0x86, 0xea, + 0xa1, 0x1a, 0x85, 0xd1, 0xa2, 0x80, 0x86, 0xd4, 0x86, 0xd5, 0xa6, 0xe7, + 0xa5, 0xd4, 0x38, 0x65, 0xd0, 0x85, 0xd4, 0x90, 0x04, 0x20, 0xb3, 0xf4, + 0x18, 0xa5, 0xd5, 0x65, 0xd2, 0x85, 0xd5, 0x90, 0x03, 0x20, 0xb4, 0xf4, + 0xca, 0xd0, 0xe5, 0xa5, 0xd1, 0x4a, 0x4a, 0x4a, 0xd0, 0xd4, 0xe6, 0x1a, + 0xd0, 0x02, 0xe6, 0x1b, 0xa1, 0x1a, 0xd0, 0xca, 0x60, 0x86, 0x1a, 0x84, + 0x1b, 0xaa, 0x4a, 0x4a, 0x4a, 0x4a, 0x85, 0xd3, 0x8a, 0x29, 0x0f, 0xaa, + 0xbc, 0xba, 0xf5, 0x84, 0xd0, 0x49, 0x0f, 0xaa, 0xbc, 0xbb, 0xf5, 0xc8, + 0x84, 0xd2, 0xa4, 0xe5, 0xa2, 0x00, 0x86, 0xea, 0xa1, 0x1a, 0x85, 0xd1, + 0xa2, 0x80, 0x86, 0xd4, 0x86, 0xd5, 0xa6, 0xe7, 0xa5, 0xd4, 0x38, 0x65, + 0xd0, 0x85, 0xd4, 0x90, 0x04, 0x20, 0x9c, 0xf4, 0x18, 0xa5, 0xd5, 0x65, + 0xd2, 0x85, 0xd5, 0x90, 0x03, 0x20, 0x9d, 0xf4, 0xca, 0xd0, 0xe5, 0xa5, + 0xd1, 0x4a, 0x4a, 0x4a, 0xd0, 0xd4, 0xe6, 0x1a, 0xd0, 0x02, 0xe6, 0x1b, + 0xa1, 0x1a, 0xd0, 0xca, 0x60, 0x20, 0x67, 0xdd, 0x20, 0x52, 0xe7, 0xa4, + 0x51, 0xa6, 0x50, 0xc0, 0x01, 0x90, 0x06, 0xd0, 0x1d, 0xe0, 0x18, 0xb0, + 0x19, 0x8a, 0x48, 0x98, 0x48, 0xa9, 0x2c, 0x20, 0xc0, 0xde, 0x20, 0xf8, + 0xe6, 0xe0, 0xc0, 0xb0, 0x09, 0x86, 0x9d, 0x68, 0xa8, 0x68, 0xaa, 0xa5, + 0x9d, 0x60, 0x4c, 0x06, 0xf2, 0x20, 0xf8, 0xe6, 0xe0, 0x08, 0xb0, 0xf6, + 0xbd, 0xf6, 0xf6, 0x85, 0xe4, 0x60, 0x00, 0x2a, 0x55, 0x7f, 0x80, 0xaa, + 0xd5, 0xff, 0xc9, 0xc1, 0xf0, 0x0d, 0x20, 0xb9, 0xf6, 0x20, 0x57, 0xf4, + 0x20, 0xb7, 0x00, 0xc9, 0xc1, 0xd0, 0xe6, 0x20, 0xc0, 0xde, 0x20, 0xb9, + 0xf6, 0x84, 0x9d, 0xa8, 0x8a, 0xa6, 0x9d, 0x20, 0x3a, 0xf5, 0x4c, 0x08, + 0xf7, 0x20, 0xf8, 0xe6, 0x86, 0xf9, 0x60, 0x20, 0xf8, 0xe6, 0x86, 0xe7, + 0x60, 0x20, 0xf8, 0xe6, 0xa5, 0xe8, 0x85, 0x1a, 0xa5, 0xe9, 0x85, 0x1b, + 0x8a, 0xa2, 0x00, 0xc1, 0x1a, 0xf0, 0x02, 0xb0, 0xa5, 0x0a, 0x90, 0x03, + 0xe6, 0x1b, 0x18, 0xa8, 0xb1, 0x1a, 0x65, 0x1a, 0xaa, 0xc8, 0xb1, 0x1a, + 0x65, 0xe9, 0x85, 0x1b, 0x86, 0x1a, 0x20, 0xb7, 0x00, 0xc9, 0xc5, 0xd0, + 0x09, 0x20, 0xc0, 0xde, 0x20, 0xb9, 0xf6, 0x20, 0x11, 0xf4, 0xa5, 0xf9, + 0x60, 0x20, 0x2d, 0xf7, 0x4c, 0x05, 0xf6, 0x20, 0x2d, 0xf7, 0x4c, 0x61, + 0xf6, 0x38, 0x90, 0x18, 0x8d, 0x07, 0xc0, 0x20, 0x00, 0xc5, 0x8d, 0x06, + 0xc0, 0xb0, 0x01, 0x60, 0x4c, 0x10, 0xd4, 0xbd, 0x01, 0x02, 0x10, 0x11, + 0xa5, 0x0e, 0xf0, 0x16, 0xc9, 0x22, 0xf0, 0x12, 0xa5, 0x13, 0xc9, 0x49, + 0xf0, 0x0c, 0xbd, 0x00, 0x02, 0x08, 0xc9, 0x61, 0x90, 0x02, 0x29, 0x5f, + 0x28, 0x60, 0xbd, 0x00, 0x02, 0x60, 0x48, 0xa9, 0x20, 0x20, 0x5c, 0xdb, + 0x68, 0x4c, 0x24, 0xed, 0xa5, 0x24, 0xc9, 0x21, 0x2c, 0x1f, 0xc0, 0x10, + 0x05, 0xad, 0x7b, 0x05, 0xc9, 0x49, 0x60, 0x8a, 0x2c, 0x1f, 0xc0, 0x30, + 0x08, 0x2c, 0x85, 0x24, 0x38, 0x8a, 0xe5, 0x24, 0x60, 0xed, 0x7b, 0x05, + 0x60, 0x00, 0x00, 0x00, 0x00, 0xa9, 0x40, 0x85, 0x14, 0x20, 0xe3, 0xdf, + 0xa9, 0x00, 0x85, 0x14, 0x4c, 0xf0, 0xd8, 0x20, 0xf8, 0xe6, 0xca, 0xa9, + 0x28, 0xc5, 0x21, 0xb0, 0x02, 0xa5, 0x21, 0x20, 0xca, 0xf7, 0x86, 0x24, + 0x90, 0xd6, 0xaa, 0x20, 0xfb, 0xda, 0xd0, 0xeb, 0x4a, 0x08, 0x20, 0x47, + 0xf8, 0x28, 0xa9, 0x0f, 0x90, 0x02, 0x69, 0xe0, 0x85, 0x2e, 0xb1, 0x26, + 0x45, 0x30, 0x25, 0x2e, 0x51, 0x26, 0x91, 0x26, 0x60, 0x20, 0x00, 0xf8, + 0xc4, 0x2c, 0xb0, 0x11, 0xc8, 0x20, 0x0e, 0xf8, 0x90, 0xf6, 0x69, 0x01, + 0x48, 0x20, 0x00, 0xf8, 0x68, 0xc5, 0x2d, 0x90, 0xf5, 0x60, 0xa0, 0x2f, + 0xd0, 0x02, 0xa0, 0x27, 0x84, 0x2d, 0xa0, 0x27, 0xa9, 0x00, 0x85, 0x30, + 0x20, 0x28, 0xf8, 0x88, 0x10, 0xf6, 0x60, 0x48, 0x4a, 0x29, 0x03, 0x09, + 0x04, 0x85, 0x27, 0x68, 0x29, 0x18, 0x90, 0x02, 0x69, 0x7f, 0x85, 0x26, + 0x0a, 0x0a, 0x05, 0x26, 0x85, 0x26, 0x60, 0xa5, 0x30, 0x18, 0x69, 0x03, + 0x29, 0x0f, 0x85, 0x30, 0x0a, 0x0a, 0x0a, 0x0a, 0x05, 0x30, 0x85, 0x30, + 0x60, 0x4a, 0x08, 0x20, 0x47, 0xf8, 0xb1, 0x26, 0x28, 0x90, 0x04, 0x4a, + 0x4a, 0x4a, 0x4a, 0x29, 0x0f, 0x60, 0xa6, 0x3a, 0xa4, 0x3b, 0x20, 0x96, + 0xfd, 0x20, 0x48, 0xf9, 0xa1, 0x3a, 0xa8, 0x4a, 0x90, 0x09, 0x6a, 0xb0, + 0x10, 0xc9, 0xa2, 0xf0, 0x0c, 0x29, 0x87, 0x4a, 0xaa, 0xbd, 0x62, 0xf9, + 0x20, 0x79, 0xf8, 0xd0, 0x04, 0xa0, 0x80, 0xa9, 0x00, 0xaa, 0xbd, 0xa6, + 0xf9, 0x85, 0x2e, 0xaa, 0x84, 0x2a, 0xa0, 0x10, 0x4c, 0xb4, 0xfb, 0x8d, + 0x06, 0xc0, 0xa2, 0x02, 0xbd, 0x05, 0xc3, 0xdd, 0x9c, 0xfc, 0xd0, 0x07, + 0xca, 0xca, 0x10, 0xf4, 0x88, 0xd0, 0xef, 0x8d, 0x07, 0xc0, 0x60, 0x00, + 0x20, 0x82, 0xf8, 0x48, 0xb1, 0x3a, 0x20, 0xda, 0xfd, 0xa2, 0x01, 0x20, + 0x4a, 0xf9, 0xc4, 0x2f, 0xc8, 0x90, 0xf1, 0xa2, 0x03, 0xc0, 0x04, 0x90, + 0xf2, 0x68, 0xa8, 0xb9, 0xc0, 0xf9, 0x85, 0x2c, 0xb9, 0x00, 0xfa, 0x85, + 0x2d, 0xa9, 0x00, 0xa0, 0x05, 0x06, 0x2d, 0x26, 0x2c, 0x2a, 0x88, 0xd0, + 0xf8, 0x69, 0xbf, 0x20, 0xed, 0xfd, 0xca, 0xd0, 0xec, 0x20, 0x48, 0xf9, + 0xa4, 0x2f, 0xa2, 0x06, 0xe0, 0x03, 0xf0, 0x1c, 0x06, 0x2e, 0x90, 0x0e, + 0xbd, 0xb3, 0xf9, 0x20, 0xed, 0xfd, 0xbd, 0xb9, 0xf9, 0xf0, 0x03, 0x20, + 0xed, 0xfd, 0xca, 0xd0, 0xe7, 0x60, 0x88, 0x30, 0xe7, 0x20, 0xda, 0xfd, + 0xa5, 0x2e, 0xc9, 0xe8, 0xb1, 0x3a, 0x90, 0xf2, 0x20, 0x56, 0xf9, 0xaa, + 0xe8, 0xd0, 0x01, 0xc8, 0x98, 0x20, 0xda, 0xfd, 0x8a, 0x4c, 0xda, 0xfd, + 0xa2, 0x03, 0xa9, 0xa0, 0x20, 0xed, 0xfd, 0xca, 0xd0, 0xf8, 0x60, 0x38, + 0xa5, 0x2f, 0xa4, 0x3b, 0xaa, 0x10, 0x01, 0x88, 0x65, 0x3a, 0x90, 0x01, + 0xc8, 0x60, 0x04, 0x20, 0x54, 0x30, 0x0d, 0x80, 0x04, 0x90, 0x03, 0x22, + 0x54, 0x33, 0x0d, 0x80, 0x04, 0x90, 0x04, 0x20, 0x54, 0x33, 0x0d, 0x80, + 0x04, 0x90, 0x04, 0x20, 0x54, 0x3b, 0x0d, 0x80, 0x04, 0x90, 0x00, 0x22, + 0x44, 0x33, 0x0d, 0xc8, 0x44, 0x00, 0x11, 0x22, 0x44, 0x33, 0x0d, 0xc8, + 0x44, 0xa9, 0x01, 0x22, 0x44, 0x33, 0x0d, 0x80, 0x04, 0x90, 0x01, 0x22, + 0x44, 0x33, 0x0d, 0x80, 0x04, 0x90, 0x26, 0x31, 0x87, 0x9a, 0x00, 0x21, + 0x81, 0x82, 0x00, 0x00, 0x59, 0x4d, 0x91, 0x92, 0x86, 0x4a, 0x85, 0x9d, + 0xac, 0xa9, 0xac, 0xa3, 0xa8, 0xa4, 0xd9, 0x00, 0xd8, 0xa4, 0xa4, 0x00, + 0x1c, 0x8a, 0x1c, 0x23, 0x5d, 0x8b, 0x1b, 0xa1, 0x9d, 0x8a, 0x1d, 0x23, + 0x9d, 0x8b, 0x1d, 0xa1, 0x00, 0x29, 0x19, 0xae, 0x69, 0xa8, 0x19, 0x23, + 0x24, 0x53, 0x1b, 0x23, 0x24, 0x53, 0x19, 0xa1, 0x00, 0x1a, 0x5b, 0x5b, + 0xa5, 0x69, 0x24, 0x24, 0xae, 0xae, 0xa8, 0xad, 0x29, 0x00, 0x7c, 0x00, + 0x15, 0x9c, 0x6d, 0x9c, 0xa5, 0x69, 0x29, 0x53, 0x84, 0x13, 0x34, 0x11, + 0xa5, 0x69, 0x23, 0xa0, 0xd8, 0x62, 0x5a, 0x48, 0x26, 0x62, 0x94, 0x88, + 0x54, 0x44, 0xc8, 0x54, 0x68, 0x44, 0xe8, 0x94, 0x00, 0xb4, 0x08, 0x84, + 0x74, 0xb4, 0x28, 0x6e, 0x74, 0xf4, 0xcc, 0x4a, 0x72, 0xf2, 0xa4, 0x8a, + 0x00, 0xaa, 0xa2, 0xa2, 0x74, 0x74, 0x74, 0x72, 0x44, 0x68, 0xb2, 0x32, + 0xb2, 0x00, 0x22, 0x00, 0x1a, 0x1a, 0x26, 0x26, 0x72, 0x72, 0x88, 0xc8, + 0xc4, 0xca, 0x26, 0x48, 0x44, 0x44, 0xa2, 0xc8, 0x85, 0x45, 0xa5, 0x45, + 0x4c, 0xfa, 0xc3, 0x8d, 0x06, 0xc0, 0x85, 0x45, 0x28, 0x20, 0x4c, 0xff, + 0x68, 0x85, 0x3a, 0x68, 0x85, 0x3b, 0x6c, 0xf0, 0x03, 0x20, 0x82, 0xf8, + 0x20, 0xda, 0xfa, 0x4c, 0x65, 0xff, 0xd8, 0x20, 0x84, 0xfe, 0x20, 0x2f, + 0xfb, 0x20, 0x93, 0xfe, 0x20, 0x89, 0xfe, 0xad, 0x58, 0xc0, 0xad, 0x5a, + 0xc0, 0xa0, 0x09, 0x20, 0xb4, 0xfb, 0xea, 0xad, 0xff, 0xcf, 0x2c, 0x10, + 0xc0, 0xd8, 0x20, 0x3a, 0xff, 0xad, 0xf3, 0x03, 0x49, 0xa5, 0xcd, 0xf4, + 0x03, 0xd0, 0x17, 0xad, 0xf2, 0x03, 0xd0, 0x0f, 0xa9, 0xe0, 0xcd, 0xf3, + 0x03, 0xd0, 0x08, 0xa0, 0x03, 0x8c, 0xf2, 0x03, 0x4c, 0x00, 0xe0, 0x6c, + 0xf2, 0x03, 0x20, 0x60, 0xfb, 0xa2, 0x05, 0xbd, 0xfc, 0xfa, 0x9d, 0xef, + 0x03, 0xca, 0xd0, 0xf7, 0xa9, 0xc8, 0x86, 0x00, 0x85, 0x01, 0xa0, 0x05, + 0xc6, 0x01, 0xa5, 0x01, 0xc9, 0xc0, 0xf0, 0xd7, 0x8d, 0xf8, 0x07, 0xb1, + 0x00, 0xd9, 0x01, 0xfb, 0xd0, 0xec, 0x88, 0x88, 0x10, 0xf5, 0x6c, 0x00, + 0x00, 0x00, 0x00, 0x20, 0x8e, 0xfd, 0xa9, 0x45, 0x85, 0x40, 0xa9, 0x00, + 0x85, 0x41, 0xa2, 0xfb, 0xa9, 0xa0, 0x20, 0xed, 0xfd, 0xbd, 0x1e, 0xfa, + 0x20, 0xed, 0xfd, 0xa9, 0xbd, 0x20, 0xed, 0xfd, 0xb5, 0x4a, 0x20, 0xda, + 0xfd, 0xe8, 0x30, 0xe8, 0x60, 0x59, 0xfa, 0x00, 0xe0, 0x45, 0x20, 0xff, + 0x00, 0xff, 0x03, 0xff, 0x3c, 0xc1, 0xf0, 0xf0, 0xec, 0xe5, 0xa0, 0xdd, + 0xdb, 0xc4, 0xc2, 0xc1, 0xff, 0xc3, 0xff, 0xff, 0xff, 0xc1, 0xd8, 0xd9, + 0xd0, 0xd3, 0xad, 0x70, 0xc0, 0xa0, 0x00, 0xea, 0xea, 0xbd, 0x64, 0xc0, + 0x10, 0x04, 0xc8, 0xd0, 0xf8, 0x88, 0x60, 0xa9, 0x00, 0x85, 0x48, 0xad, + 0x56, 0xc0, 0xad, 0x54, 0xc0, 0xad, 0x51, 0xc0, 0xa9, 0x00, 0xf0, 0x0b, + 0xad, 0x50, 0xc0, 0xad, 0x53, 0xc0, 0x20, 0x36, 0xf8, 0xa9, 0x14, 0x85, + 0x22, 0xa9, 0x00, 0x85, 0x20, 0xa0, 0x0c, 0xd0, 0x5f, 0xa9, 0x18, 0x85, + 0x23, 0xa9, 0x17, 0x85, 0x25, 0x4c, 0x22, 0xfc, 0x20, 0x58, 0xfc, 0xa0, + 0x09, 0xb9, 0x09, 0xff, 0x99, 0x0e, 0x04, 0x88, 0xd0, 0xf7, 0x60, 0xad, + 0xf3, 0x03, 0x49, 0xa5, 0x8d, 0xf4, 0x03, 0x60, 0xc9, 0x8d, 0xd0, 0x18, + 0xac, 0x00, 0xc0, 0x10, 0x13, 0xc0, 0x93, 0xd0, 0x0f, 0x2c, 0x10, 0xc0, + 0xac, 0x00, 0xc0, 0x10, 0xfb, 0xc0, 0x83, 0xf0, 0x03, 0x2c, 0x10, 0xc0, + 0x4c, 0xfd, 0xfb, 0x38, 0x4c, 0x2c, 0xfc, 0xa8, 0xb9, 0x48, 0xfa, 0x20, + 0x97, 0xfb, 0x20, 0x21, 0xfd, 0xc9, 0xce, 0xb0, 0xee, 0xc9, 0xc9, 0x90, + 0xea, 0xc9, 0xcc, 0xf0, 0xe6, 0xd0, 0xe8, 0x06, 0x2c, 0x15, 0xc0, 0x08, + 0x8d, 0x07, 0xc0, 0x4c, 0x00, 0xc1, 0x00, 0x00, 0xe0, 0x48, 0x4a, 0x29, + 0x03, 0x09, 0x04, 0x85, 0x29, 0x68, 0x29, 0x18, 0x90, 0x02, 0x69, 0x7f, + 0x85, 0x28, 0x0a, 0x0a, 0x05, 0x28, 0x85, 0x28, 0x60, 0xc9, 0x87, 0xd0, + 0x12, 0xa9, 0x40, 0x20, 0xa8, 0xfc, 0xa0, 0xc0, 0xa9, 0x0c, 0x20, 0xa8, + 0xfc, 0xad, 0x30, 0xc0, 0x88, 0xd0, 0xf5, 0x60, 0xa4, 0x24, 0x91, 0x28, + 0xe6, 0x24, 0xa5, 0x24, 0xc5, 0x21, 0xb0, 0x66, 0x60, 0xc9, 0xa0, 0xb0, + 0xef, 0xa8, 0x10, 0xec, 0xc9, 0x8d, 0xf0, 0x5a, 0xc9, 0x8a, 0xf0, 0x5a, + 0xc9, 0x88, 0xd0, 0xc9, 0xc6, 0x24, 0x10, 0xe8, 0xa5, 0x21, 0x85, 0x24, + 0xc6, 0x24, 0xa5, 0x22, 0xc5, 0x25, 0xb0, 0xdc, 0xc6, 0x25, 0xa5, 0x25, + 0x85, 0x28, 0x98, 0xa0, 0x04, 0xd0, 0x89, 0x00, 0x49, 0xc0, 0xf0, 0x28, + 0x69, 0xfd, 0x90, 0xc0, 0xf0, 0xda, 0x69, 0xfd, 0x90, 0x2c, 0xf0, 0xde, + 0x69, 0xfd, 0x90, 0x5c, 0xd0, 0xba, 0xa0, 0x0a, 0xd0, 0xe3, 0x2c, 0x1f, + 0xc0, 0x10, 0x04, 0xa0, 0x00, 0xf0, 0x0b, 0x98, 0x48, 0x20, 0x78, 0xfb, + 0x68, 0xa4, 0x35, 0x60, 0xa0, 0x05, 0x4c, 0xb4, 0xfb, 0x53, 0x5c, 0x5c, + 0x00, 0x00, 0xa9, 0x00, 0x85, 0x24, 0xe6, 0x25, 0xa5, 0x25, 0xc5, 0x23, + 0x90, 0xb6, 0xc6, 0x25, 0xa0, 0x06, 0xd0, 0xb5, 0x8d, 0x06, 0xc0, 0x6c, + 0xfe, 0x03, 0x68, 0x8d, 0xf8, 0x07, 0xc9, 0xc1, 0x90, 0x0d, 0x8d, 0xff, + 0xcf, 0xa0, 0x00, 0xa6, 0x01, 0x85, 0x01, 0xb1, 0x00, 0x86, 0x01, 0x8d, + 0x07, 0xc0, 0x4c, 0x7c, 0xc4, 0x90, 0x02, 0x25, 0x32, 0x4c, 0xf7, 0xfd, + 0x38, 0x90, 0x18, 0x84, 0x2a, 0xa0, 0x07, 0xb0, 0x78, 0xc8, 0xd0, 0x75, + 0x38, 0x48, 0xe9, 0x01, 0xd0, 0xfc, 0x68, 0xe9, 0x01, 0xd0, 0xf6, 0x60, + 0xe6, 0x42, 0xd0, 0x02, 0xe6, 0x43, 0xa5, 0x3c, 0xc5, 0x3e, 0xa5, 0x3d, + 0xe5, 0x3f, 0xe6, 0x3c, 0xd0, 0x02, 0xe6, 0x3d, 0x60, 0x8d, 0x07, 0xc0, + 0x20, 0x67, 0xc5, 0x4c, 0xc5, 0xfe, 0x8d, 0x06, 0xc0, 0x20, 0x4a, 0xf9, + 0xa9, 0xde, 0x20, 0xed, 0xfd, 0x20, 0x3a, 0xff, 0x4c, 0xf0, 0xfc, 0x8d, + 0x06, 0xc0, 0x20, 0xd0, 0xf8, 0x20, 0x53, 0xf9, 0x84, 0x3b, 0x85, 0x3a, + 0xa9, 0xa1, 0x85, 0x33, 0x20, 0x67, 0xfd, 0x8d, 0x07, 0xc0, 0x4c, 0x9c, + 0xcf, 0xb9, 0x00, 0x02, 0xc8, 0xc9, 0xe1, 0x90, 0x06, 0xc9, 0xfb, 0xb0, + 0x02, 0x29, 0xdf, 0x60, 0xa0, 0x0b, 0xd0, 0x03, 0x4c, 0x18, 0xfd, 0x20, + 0xb4, 0xfb, 0xea, 0xea, 0x6c, 0x38, 0x00, 0xa0, 0x03, 0x4c, 0xb4, 0xfb, + 0xea, 0x20, 0x0c, 0xfd, 0xa0, 0x01, 0xd0, 0xf5, 0x4e, 0xf8, 0x07, 0x4c, + 0x0c, 0xfd, 0xea, 0x20, 0x21, 0xfd, 0x20, 0xa5, 0xfb, 0x20, 0x28, 0xfd, + 0xc9, 0x9b, 0xf0, 0xf3, 0x60, 0xa0, 0x0f, 0x20, 0xb4, 0xfb, 0xa4, 0x24, + 0x9d, 0x00, 0x02, 0x20, 0xed, 0xfd, 0xea, 0xea, 0xea, 0xbd, 0x00, 0x02, + 0xc9, 0x88, 0xf0, 0x1d, 0xc9, 0x98, 0xf0, 0x0a, 0xe0, 0xf8, 0x90, 0x03, + 0x20, 0x3a, 0xff, 0xe8, 0xd0, 0x13, 0xa9, 0xdc, 0x20, 0xed, 0xfd, 0x20, + 0x8e, 0xfd, 0xa5, 0x33, 0x20, 0xed, 0xfd, 0xa2, 0x01, 0x8a, 0xf0, 0xf3, + 0xca, 0x20, 0x35, 0xfd, 0xc9, 0x95, 0xd0, 0x08, 0xb1, 0x28, 0x2c, 0x1f, + 0xc0, 0x30, 0xba, 0xea, 0x9d, 0x00, 0x02, 0xc9, 0x8d, 0xd0, 0xbc, 0x20, + 0x9c, 0xfc, 0xa9, 0x8d, 0xd0, 0x5b, 0xa4, 0x3d, 0xa6, 0x3c, 0x20, 0x8e, + 0xfd, 0x20, 0x40, 0xf9, 0xa0, 0x00, 0xa9, 0xad, 0x4c, 0xed, 0xfd, 0xa5, + 0x3c, 0x09, 0x07, 0x85, 0x3e, 0xa5, 0x3d, 0x85, 0x3f, 0xa5, 0x3c, 0x29, + 0x07, 0xd0, 0x03, 0x20, 0x92, 0xfd, 0xa9, 0xa0, 0x20, 0xed, 0xfd, 0xb1, + 0x3c, 0x20, 0xda, 0xfd, 0x20, 0xba, 0xfc, 0x90, 0xe8, 0x60, 0x4a, 0x90, + 0xea, 0x4a, 0x4a, 0xa5, 0x3e, 0x90, 0x02, 0x49, 0xff, 0x65, 0x3c, 0x48, + 0xa9, 0xbd, 0x20, 0xed, 0xfd, 0x68, 0x48, 0x4a, 0x4a, 0x4a, 0x4a, 0x20, + 0xe5, 0xfd, 0x68, 0x29, 0x0f, 0x09, 0xb0, 0xc9, 0xba, 0x90, 0x02, 0x69, + 0x06, 0x6c, 0x36, 0x00, 0x48, 0xc9, 0xa0, 0x4c, 0x95, 0xfc, 0x48, 0x84, + 0x35, 0xa8, 0x68, 0x4c, 0x46, 0xfc, 0xea, 0xea, 0xc6, 0x34, 0xf0, 0x9f, + 0xca, 0xd0, 0x16, 0xc9, 0xba, 0xd0, 0xbb, 0x85, 0x31, 0xa5, 0x3e, 0x91, + 0x40, 0xe6, 0x40, 0xd0, 0x02, 0xe6, 0x41, 0x60, 0xa4, 0x34, 0xb9, 0xff, + 0x01, 0x85, 0x31, 0x60, 0xa2, 0x01, 0xb5, 0x3e, 0x95, 0x42, 0x95, 0x44, + 0xca, 0x10, 0xf7, 0x60, 0xb1, 0x3c, 0x91, 0x42, 0x20, 0xb4, 0xfc, 0x90, + 0xf7, 0x60, 0xb1, 0x3c, 0xd1, 0x42, 0xf0, 0x1c, 0x20, 0x92, 0xfd, 0xb1, + 0x3c, 0x20, 0xda, 0xfd, 0xa9, 0xa0, 0x20, 0xed, 0xfd, 0xa9, 0xa8, 0x20, + 0xed, 0xfd, 0xb1, 0x42, 0x20, 0xda, 0xfd, 0xa9, 0xa9, 0x20, 0xed, 0xfd, + 0x20, 0xb4, 0xfc, 0x90, 0xd9, 0x60, 0x20, 0x75, 0xfe, 0xa9, 0x14, 0x48, + 0x20, 0xd0, 0xf8, 0x20, 0x53, 0xf9, 0x85, 0x3a, 0x84, 0x3b, 0x68, 0x38, + 0xe9, 0x01, 0xd0, 0xef, 0x60, 0x8a, 0xf0, 0x07, 0xb5, 0x3c, 0x95, 0x3a, + 0xca, 0x10, 0xf9, 0x60, 0xa0, 0x3f, 0xd0, 0x02, 0xa0, 0xff, 0x84, 0x32, + 0x60, 0xa9, 0x00, 0x85, 0x3e, 0xa2, 0x38, 0xa0, 0x1b, 0xd0, 0x08, 0xa9, + 0x00, 0x85, 0x3e, 0xa2, 0x36, 0xa0, 0xf0, 0xa5, 0x3e, 0x29, 0x0f, 0xf0, + 0x04, 0x09, 0xc0, 0xa0, 0x00, 0x94, 0x00, 0x95, 0x01, 0xa0, 0x0e, 0x4c, + 0xb4, 0xfb, 0xea, 0x00, 0x4c, 0x00, 0xe0, 0x4c, 0x03, 0xe0, 0x20, 0x75, + 0xfe, 0x20, 0x3f, 0xff, 0x6c, 0x3a, 0x00, 0x4c, 0xd7, 0xfa, 0x60, 0xea, + 0x60, 0x8d, 0x06, 0xc0, 0x60, 0xea, 0x4c, 0xf8, 0x03, 0xa9, 0x40, 0x8d, + 0x07, 0xc0, 0x20, 0xaa, 0xc5, 0xf0, 0x2c, 0xa0, 0x01, 0xa5, 0x43, 0xf0, + 0x04, 0xd1, 0x3c, 0xd0, 0x0a, 0x88, 0xa5, 0x42, 0xd1, 0x3c, 0xd0, 0x03, + 0x20, 0x92, 0xfd, 0x20, 0xba, 0xfc, 0x90, 0xe7, 0x60, 0xa0, 0x0d, 0x20, + 0xb4, 0xfb, 0x20, 0x00, 0xfe, 0x68, 0x68, 0xd0, 0x6c, 0x8d, 0x07, 0xc0, + 0x20, 0xd1, 0xc5, 0x8d, 0x06, 0xc0, 0xf0, 0x32, 0xd0, 0x23, 0xc1, 0xf0, + 0xf0, 0xec, 0xe5, 0xa0, 0xaf, 0xaf, 0xe5, 0x20, 0xfd, 0xfc, 0xc9, 0xa0, + 0xf0, 0xf9, 0x60, 0xb0, 0x6d, 0xc9, 0xa0, 0xd0, 0x28, 0xb9, 0x00, 0x02, + 0xa2, 0x07, 0xc9, 0x8d, 0xf0, 0x7d, 0xc8, 0xd0, 0x63, 0xa9, 0xc5, 0x20, + 0xed, 0xfd, 0xa9, 0xd2, 0x20, 0xed, 0xfd, 0x20, 0xed, 0xfd, 0xa9, 0x87, + 0x4c, 0xed, 0xfd, 0xa5, 0x48, 0x48, 0xa5, 0x45, 0xa6, 0x46, 0xa4, 0x47, + 0x28, 0x60, 0x85, 0x45, 0x86, 0x46, 0x84, 0x47, 0x08, 0x68, 0x85, 0x48, + 0xba, 0x86, 0x49, 0xd8, 0x60, 0x20, 0x84, 0xfe, 0x20, 0x2f, 0xfb, 0x20, + 0x93, 0xfe, 0x20, 0x89, 0xfe, 0xd8, 0x20, 0x3a, 0xff, 0xa9, 0xaa, 0x85, + 0x33, 0x20, 0x67, 0xfd, 0x20, 0xc7, 0xff, 0x20, 0xa7, 0xff, 0x84, 0x34, + 0xa0, 0x17, 0x88, 0x30, 0xe8, 0xd9, 0xcc, 0xff, 0xd0, 0xf8, 0x20, 0xbe, + 0xff, 0xa4, 0x34, 0x4c, 0x73, 0xff, 0xa2, 0x03, 0x0a, 0x0a, 0x0a, 0x0a, + 0x0a, 0x26, 0x3e, 0x26, 0x3f, 0xca, 0x10, 0xf8, 0xa5, 0x31, 0xd0, 0x06, + 0xb5, 0x3f, 0x95, 0x3d, 0x95, 0x41, 0xe8, 0xf0, 0xf3, 0xd0, 0x06, 0xa2, + 0x00, 0x86, 0x3e, 0x86, 0x3f, 0x20, 0xfd, 0xfc, 0xea, 0x49, 0xb0, 0xc9, + 0x0a, 0x90, 0xd3, 0x69, 0x88, 0xc9, 0xfa, 0x4c, 0x1b, 0xff, 0xa9, 0xfe, + 0x48, 0xb9, 0xe3, 0xff, 0x48, 0xa5, 0x31, 0xa0, 0x00, 0x84, 0x31, 0x60, + 0xbc, 0xb2, 0xbe, 0x9a, 0xef, 0xc4, 0xec, 0xa9, 0xbb, 0xa6, 0xa4, 0x06, + 0x95, 0x07, 0x02, 0x05, 0xf0, 0x00, 0xeb, 0x93, 0xa7, 0xc6, 0x99, 0xb2, + 0xc9, 0xbe, 0xf0, 0x35, 0x8c, 0xd6, 0x96, 0xaf, 0x17, 0x17, 0x2b, 0x1f, + 0x83, 0x7f, 0x5d, 0xcc, 0xb5, 0xfc, 0x17, 0x17, 0xf5, 0x03, 0xfb, 0x03, + 0x62, 0xfa, 0xfa, 0xc3 +}; +static const unsigned int iie_enhanced_rom_bin_len = 16384; diff --git a/src/roms/mii_rom_iiee_video.h b/src/roms/mii_rom_iiee_video.h new file mode 100644 index 0000000..f47de65 --- /dev/null +++ b/src/roms/mii_rom_iiee_video.h @@ -0,0 +1,346 @@ +#pragma once +static const unsigned char iie_enhanced_video[] = { + 0x1c, 0x22, 0x2a, 0x3a, 0x1a, 0x02, 0x3c, 0x00, 0x08, 0x14, 0x22, 0x22, + 0x3e, 0x22, 0x22, 0x00, 0x1e, 0x22, 0x22, 0x1e, 0x22, 0x22, 0x1e, 0x00, + 0x1c, 0x22, 0x02, 0x02, 0x02, 0x22, 0x1c, 0x00, 0x1e, 0x22, 0x22, 0x22, + 0x22, 0x22, 0x1e, 0x00, 0x3e, 0x02, 0x02, 0x1e, 0x02, 0x02, 0x3e, 0x00, + 0x3e, 0x02, 0x02, 0x1e, 0x02, 0x02, 0x02, 0x00, 0x3c, 0x02, 0x02, 0x02, + 0x32, 0x22, 0x3c, 0x00, 0x22, 0x22, 0x22, 0x3e, 0x22, 0x22, 0x22, 0x00, + 0x1c, 0x08, 0x08, 0x08, 0x08, 0x08, 0x1c, 0x00, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x22, 0x1c, 0x00, 0x22, 0x12, 0x0a, 0x06, 0x0a, 0x12, 0x22, 0x00, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x3e, 0x00, 0x22, 0x36, 0x2a, 0x2a, + 0x22, 0x22, 0x22, 0x00, 0x22, 0x22, 0x26, 0x2a, 0x32, 0x22, 0x22, 0x00, + 0x1c, 0x22, 0x22, 0x22, 0x22, 0x22, 0x1c, 0x00, 0x1e, 0x22, 0x22, 0x1e, + 0x02, 0x02, 0x02, 0x00, 0x1c, 0x22, 0x22, 0x22, 0x2a, 0x12, 0x2c, 0x00, + 0x1e, 0x22, 0x22, 0x1e, 0x0a, 0x12, 0x22, 0x00, 0x1c, 0x22, 0x02, 0x1c, + 0x20, 0x22, 0x1c, 0x00, 0x3e, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, + 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x1c, 0x00, 0x22, 0x22, 0x22, 0x22, + 0x22, 0x14, 0x08, 0x00, 0x22, 0x22, 0x22, 0x2a, 0x2a, 0x36, 0x22, 0x00, + 0x22, 0x22, 0x14, 0x08, 0x14, 0x22, 0x22, 0x00, 0x22, 0x22, 0x14, 0x08, + 0x08, 0x08, 0x08, 0x00, 0x3e, 0x20, 0x10, 0x08, 0x04, 0x02, 0x3e, 0x00, + 0x3e, 0x06, 0x06, 0x06, 0x06, 0x06, 0x3e, 0x00, 0x00, 0x02, 0x04, 0x08, + 0x10, 0x20, 0x00, 0x00, 0x3e, 0x30, 0x30, 0x30, 0x30, 0x30, 0x3e, 0x00, + 0x00, 0x00, 0x08, 0x14, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x08, 0x00, 0x14, 0x14, 0x14, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x14, 0x14, 0x3e, 0x14, 0x3e, 0x14, 0x14, 0x00, + 0x08, 0x3c, 0x0a, 0x1c, 0x28, 0x1e, 0x08, 0x00, 0x06, 0x26, 0x10, 0x08, + 0x04, 0x32, 0x30, 0x00, 0x04, 0x0a, 0x0a, 0x04, 0x2a, 0x12, 0x2c, 0x00, + 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x04, 0x02, 0x02, + 0x02, 0x04, 0x08, 0x00, 0x08, 0x10, 0x20, 0x20, 0x20, 0x10, 0x08, 0x00, + 0x08, 0x2a, 0x1c, 0x08, 0x1c, 0x2a, 0x08, 0x00, 0x00, 0x08, 0x08, 0x3e, + 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x04, 0x00, + 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x08, 0x00, 0x00, 0x20, 0x10, 0x08, 0x04, 0x02, 0x00, 0x00, + 0x1c, 0x22, 0x32, 0x2a, 0x26, 0x22, 0x1c, 0x00, 0x08, 0x0c, 0x08, 0x08, + 0x08, 0x08, 0x1c, 0x00, 0x1c, 0x22, 0x20, 0x18, 0x04, 0x02, 0x3e, 0x00, + 0x3e, 0x20, 0x10, 0x18, 0x20, 0x22, 0x1c, 0x00, 0x10, 0x18, 0x14, 0x12, + 0x3e, 0x10, 0x10, 0x00, 0x3e, 0x02, 0x1e, 0x20, 0x20, 0x22, 0x1c, 0x00, + 0x38, 0x04, 0x02, 0x1e, 0x22, 0x22, 0x1c, 0x00, 0x3e, 0x20, 0x10, 0x08, + 0x04, 0x04, 0x04, 0x00, 0x1c, 0x22, 0x22, 0x1c, 0x22, 0x22, 0x1c, 0x00, + 0x1c, 0x22, 0x22, 0x3c, 0x20, 0x10, 0x0e, 0x00, 0x00, 0x00, 0x08, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x08, 0x08, 0x04, 0x00, + 0x10, 0x08, 0x04, 0x02, 0x04, 0x08, 0x10, 0x00, 0x00, 0x00, 0x3e, 0x00, + 0x3e, 0x00, 0x00, 0x00, 0x04, 0x08, 0x10, 0x20, 0x10, 0x08, 0x04, 0x00, + 0x1c, 0x22, 0x10, 0x08, 0x08, 0x00, 0x08, 0x00, 0xef, 0xf7, 0xc9, 0x80, + 0xc0, 0xc0, 0x81, 0xc9, 0xef, 0xf7, 0xc9, 0xbe, 0xde, 0xde, 0xb5, 0xc9, + 0xff, 0xff, 0xfd, 0xf9, 0xf1, 0xe1, 0xc9, 0xbd, 0x80, 0xdd, 0xeb, 0xf7, + 0xf7, 0xeb, 0xd5, 0x80, 0xff, 0xbf, 0xdf, 0xee, 0xf5, 0xfb, 0xfb, 0xff, + 0x80, 0xc0, 0xa0, 0x93, 0x8a, 0x84, 0x84, 0x80, 0x8f, 0x9f, 0x81, 0xce, + 0x86, 0xcf, 0xc0, 0xfd, 0xff, 0xe7, 0xf8, 0xff, 0xf8, 0xf3, 0xf7, 0x8f, + 0xf7, 0xfb, 0xfd, 0x80, 0xfd, 0xfb, 0xf7, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xd5, 0xf7, 0xf7, 0xf7, 0xf7, 0xb6, 0xd5, 0xe3, 0xf7, + 0xf7, 0xe3, 0xd5, 0xb6, 0xf7, 0xf7, 0xf7, 0xf7, 0x80, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xbf, 0xbf, 0xbf, 0xbb, 0xb9, 0x80, 0xf9, 0xfb, + 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xec, 0xe7, 0xe3, 0x81, + 0xe3, 0xe7, 0xef, 0x90, 0x9b, 0xf3, 0xe3, 0xc0, 0xe3, 0xf3, 0xfb, 0x84, + 0xbf, 0xb7, 0xf7, 0x80, 0xc1, 0xe3, 0xb7, 0xbf, 0xbf, 0xb7, 0xe3, 0xc1, + 0x80, 0xf7, 0xb7, 0xbf, 0xff, 0xff, 0xff, 0x80, 0xff, 0xff, 0xff, 0xff, + 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0x80, 0xf7, 0xef, 0xdf, 0x80, + 0xdf, 0xef, 0xf7, 0xff, 0xd5, 0xaa, 0xd5, 0xaa, 0xd5, 0xaa, 0xd5, 0xaa, + 0xaa, 0xd5, 0xaa, 0xd5, 0xaa, 0xd5, 0xaa, 0xd5, 0xff, 0xc1, 0xbe, 0xfe, + 0xfe, 0xfe, 0x80, 0xff, 0xff, 0xff, 0xc0, 0xbf, 0xbf, 0xbf, 0x80, 0xff, + 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xf7, 0xe3, 0xc1, 0x80, + 0xc1, 0xe3, 0xf7, 0xff, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, + 0xeb, 0xeb, 0x88, 0xff, 0x88, 0xeb, 0xeb, 0xff, 0x80, 0xbf, 0xbf, 0xb3, + 0xb3, 0xbf, 0xbf, 0x80, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, + 0x04, 0x08, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x20, + 0x3c, 0x22, 0x3c, 0x00, 0x02, 0x02, 0x1e, 0x22, 0x22, 0x22, 0x1e, 0x00, + 0x00, 0x00, 0x3c, 0x02, 0x02, 0x02, 0x3c, 0x00, 0x20, 0x20, 0x3c, 0x22, + 0x22, 0x22, 0x3c, 0x00, 0x00, 0x00, 0x1c, 0x22, 0x3e, 0x02, 0x3c, 0x00, + 0x18, 0x24, 0x04, 0x1e, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x1c, 0x22, + 0x22, 0x3c, 0x20, 0x1c, 0x02, 0x02, 0x1e, 0x22, 0x22, 0x22, 0x22, 0x00, + 0x08, 0x00, 0x0c, 0x08, 0x08, 0x08, 0x1c, 0x00, 0x10, 0x00, 0x18, 0x10, + 0x10, 0x10, 0x12, 0x0c, 0x02, 0x02, 0x22, 0x12, 0x0e, 0x12, 0x22, 0x00, + 0x0c, 0x08, 0x08, 0x08, 0x08, 0x08, 0x1c, 0x00, 0x00, 0x00, 0x36, 0x2a, + 0x2a, 0x2a, 0x22, 0x00, 0x00, 0x00, 0x1e, 0x22, 0x22, 0x22, 0x22, 0x00, + 0x00, 0x00, 0x1c, 0x22, 0x22, 0x22, 0x1c, 0x00, 0x00, 0x00, 0x1e, 0x22, + 0x22, 0x1e, 0x02, 0x02, 0x00, 0x00, 0x3c, 0x22, 0x22, 0x3c, 0x20, 0x20, + 0x00, 0x00, 0x3a, 0x06, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x3c, 0x02, + 0x1c, 0x20, 0x1e, 0x00, 0x04, 0x04, 0x1e, 0x04, 0x04, 0x24, 0x18, 0x00, + 0x00, 0x00, 0x22, 0x22, 0x22, 0x32, 0x2c, 0x00, 0x00, 0x00, 0x22, 0x22, + 0x22, 0x14, 0x08, 0x00, 0x00, 0x00, 0x22, 0x22, 0x2a, 0x2a, 0x36, 0x00, + 0x00, 0x00, 0x22, 0x14, 0x08, 0x14, 0x22, 0x00, 0x00, 0x00, 0x22, 0x22, + 0x22, 0x3c, 0x20, 0x1c, 0x00, 0x00, 0x3e, 0x10, 0x08, 0x04, 0x3e, 0x00, + 0x38, 0x0c, 0x0c, 0x06, 0x0c, 0x0c, 0x38, 0x00, 0x08, 0x08, 0x08, 0x08, + 0x08, 0x08, 0x08, 0x08, 0x0e, 0x18, 0x18, 0x30, 0x18, 0x18, 0x0e, 0x00, + 0x2c, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2a, 0x14, 0x2a, + 0x14, 0x2a, 0x00, 0x00, 0xe3, 0xdd, 0xd5, 0xc5, 0xe5, 0xfd, 0xc3, 0xff, + 0xf7, 0xeb, 0xdd, 0xdd, 0xc1, 0xdd, 0xdd, 0xff, 0xe1, 0xdd, 0xdd, 0xe1, + 0xdd, 0xdd, 0xe1, 0xff, 0xe3, 0xdd, 0xfd, 0xfd, 0xfd, 0xdd, 0xe3, 0xff, + 0xe1, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xe1, 0xff, 0xc1, 0xfd, 0xfd, 0xe1, + 0xfd, 0xfd, 0xc1, 0xff, 0xc1, 0xfd, 0xfd, 0xe1, 0xfd, 0xfd, 0xfd, 0xff, + 0xc3, 0xfd, 0xfd, 0xfd, 0xcd, 0xdd, 0xc3, 0xff, 0xdd, 0xdd, 0xdd, 0xc1, + 0xdd, 0xdd, 0xdd, 0xff, 0xe3, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xe3, 0xff, + 0xdf, 0xdf, 0xdf, 0xdf, 0xdf, 0xdd, 0xe3, 0xff, 0xdd, 0xed, 0xf5, 0xf9, + 0xf5, 0xed, 0xdd, 0xff, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xc1, 0xff, + 0xdd, 0xc9, 0xd5, 0xd5, 0xdd, 0xdd, 0xdd, 0xff, 0xdd, 0xdd, 0xd9, 0xd5, + 0xcd, 0xdd, 0xdd, 0xff, 0xe3, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xe3, 0xff, + 0xe1, 0xdd, 0xdd, 0xe1, 0xfd, 0xfd, 0xfd, 0xff, 0xe3, 0xdd, 0xdd, 0xdd, + 0xd5, 0xed, 0xd3, 0xff, 0xe1, 0xdd, 0xdd, 0xe1, 0xf5, 0xed, 0xdd, 0xff, + 0xe3, 0xdd, 0xfd, 0xe3, 0xdf, 0xdd, 0xe3, 0xff, 0xc1, 0xf7, 0xf7, 0xf7, + 0xf7, 0xf7, 0xf7, 0xff, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xe3, 0xff, + 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xeb, 0xf7, 0xff, 0xdd, 0xdd, 0xdd, 0xd5, + 0xd5, 0xc9, 0xdd, 0xff, 0xdd, 0xdd, 0xeb, 0xf7, 0xeb, 0xdd, 0xdd, 0xff, + 0xdd, 0xdd, 0xeb, 0xf7, 0xf7, 0xf7, 0xf7, 0xff, 0xc1, 0xdf, 0xef, 0xf7, + 0xfb, 0xfd, 0xc1, 0xff, 0xc1, 0xf9, 0xf9, 0xf9, 0xf9, 0xf9, 0xc1, 0xff, + 0xff, 0xfd, 0xfb, 0xf7, 0xef, 0xdf, 0xff, 0xff, 0xc1, 0xcf, 0xcf, 0xcf, + 0xcf, 0xcf, 0xc1, 0xff, 0xff, 0xff, 0xf7, 0xeb, 0xdd, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xff, 0xf7, 0xff, + 0xeb, 0xeb, 0xeb, 0xff, 0xff, 0xff, 0xff, 0xff, 0xeb, 0xeb, 0xc1, 0xeb, + 0xc1, 0xeb, 0xeb, 0xff, 0xf7, 0xc3, 0xf5, 0xe3, 0xd7, 0xe1, 0xf7, 0xff, + 0xf9, 0xd9, 0xef, 0xf7, 0xfb, 0xcd, 0xcf, 0xff, 0xfb, 0xf5, 0xf5, 0xfb, + 0xd5, 0xed, 0xd3, 0xff, 0xf7, 0xf7, 0xf7, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xf7, 0xfb, 0xfd, 0xfd, 0xfd, 0xfb, 0xf7, 0xff, 0xf7, 0xef, 0xdf, 0xdf, + 0xdf, 0xef, 0xf7, 0xff, 0xf7, 0xd5, 0xe3, 0xf7, 0xe3, 0xd5, 0xf7, 0xff, + 0xff, 0xf7, 0xf7, 0xc1, 0xf7, 0xf7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xf7, 0xf7, 0xfb, 0xff, 0xff, 0xff, 0xff, 0xc1, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf7, 0xff, 0xff, 0xdf, 0xef, 0xf7, + 0xfb, 0xfd, 0xff, 0xff, 0xe3, 0xdd, 0xcd, 0xd5, 0xd9, 0xdd, 0xe3, 0xff, + 0xf7, 0xf3, 0xf7, 0xf7, 0xf7, 0xf7, 0xe3, 0xff, 0xe3, 0xdd, 0xdf, 0xe7, + 0xfb, 0xfd, 0xc1, 0xff, 0xc1, 0xdf, 0xef, 0xe7, 0xdf, 0xdd, 0xe3, 0xff, + 0xef, 0xe7, 0xeb, 0xed, 0xc1, 0xef, 0xef, 0xff, 0xc1, 0xfd, 0xe1, 0xdf, + 0xdf, 0xdd, 0xe3, 0xff, 0xc7, 0xfb, 0xfd, 0xe1, 0xdd, 0xdd, 0xe3, 0xff, + 0xc1, 0xdf, 0xef, 0xf7, 0xfb, 0xfb, 0xfb, 0xff, 0xe3, 0xdd, 0xdd, 0xe3, + 0xdd, 0xdd, 0xe3, 0xff, 0xe3, 0xdd, 0xdd, 0xc3, 0xdf, 0xef, 0xf1, 0xff, + 0xff, 0xff, 0xf7, 0xff, 0xf7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf7, 0xff, + 0xf7, 0xf7, 0xfb, 0xff, 0xef, 0xf7, 0xfb, 0xfd, 0xfb, 0xf7, 0xef, 0xff, + 0xff, 0xff, 0xc1, 0xff, 0xc1, 0xff, 0xff, 0xff, 0xfb, 0xf7, 0xef, 0xdf, + 0xef, 0xf7, 0xfb, 0xff, 0xe3, 0xdd, 0xef, 0xf7, 0xf7, 0xff, 0xf7, 0xff, + 0xe3, 0xdd, 0xd5, 0xc5, 0xe5, 0xfd, 0xc3, 0xff, 0xf7, 0xeb, 0xdd, 0xdd, + 0xc1, 0xdd, 0xdd, 0xff, 0xe1, 0xdd, 0xdd, 0xe1, 0xdd, 0xdd, 0xe1, 0xff, + 0xe3, 0xdd, 0xfd, 0xfd, 0xfd, 0xdd, 0xe3, 0xff, 0xe1, 0xdd, 0xdd, 0xdd, + 0xdd, 0xdd, 0xe1, 0xff, 0xc1, 0xfd, 0xfd, 0xe1, 0xfd, 0xfd, 0xc1, 0xff, + 0xc1, 0xfd, 0xfd, 0xe1, 0xfd, 0xfd, 0xfd, 0xff, 0xc3, 0xfd, 0xfd, 0xfd, + 0xcd, 0xdd, 0xc3, 0xff, 0xdd, 0xdd, 0xdd, 0xc1, 0xdd, 0xdd, 0xdd, 0xff, + 0xe3, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xe3, 0xff, 0xdf, 0xdf, 0xdf, 0xdf, + 0xdf, 0xdd, 0xe3, 0xff, 0xdd, 0xed, 0xf5, 0xf9, 0xf5, 0xed, 0xdd, 0xff, + 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xc1, 0xff, 0xdd, 0xc9, 0xd5, 0xd5, + 0xdd, 0xdd, 0xdd, 0xff, 0xdd, 0xdd, 0xd9, 0xd5, 0xcd, 0xdd, 0xdd, 0xff, + 0xe3, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xe3, 0xff, 0xe1, 0xdd, 0xdd, 0xe1, + 0xfd, 0xfd, 0xfd, 0xff, 0xe3, 0xdd, 0xdd, 0xdd, 0xd5, 0xed, 0xd3, 0xff, + 0xe1, 0xdd, 0xdd, 0xe1, 0xf5, 0xed, 0xdd, 0xff, 0xe3, 0xdd, 0xfd, 0xe3, + 0xdf, 0xdd, 0xe3, 0xff, 0xc1, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xff, + 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xe3, 0xff, 0xdd, 0xdd, 0xdd, 0xdd, + 0xdd, 0xeb, 0xf7, 0xff, 0xdd, 0xdd, 0xdd, 0xd5, 0xd5, 0xc9, 0xdd, 0xff, + 0xdd, 0xdd, 0xeb, 0xf7, 0xeb, 0xdd, 0xdd, 0xff, 0xdd, 0xdd, 0xeb, 0xf7, + 0xf7, 0xf7, 0xf7, 0xff, 0xc1, 0xdf, 0xef, 0xf7, 0xfb, 0xfd, 0xc1, 0xff, + 0xc1, 0xf9, 0xf9, 0xf9, 0xf9, 0xf9, 0xc1, 0xff, 0xff, 0xfd, 0xfb, 0xf7, + 0xef, 0xdf, 0xff, 0xff, 0xc1, 0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 0xc1, 0xff, + 0xff, 0xff, 0xf7, 0xeb, 0xdd, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x80, 0xfb, 0xf7, 0xef, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xe3, 0xdf, 0xc3, 0xdd, 0xc3, 0xff, 0xfd, 0xfd, 0xe1, 0xdd, + 0xdd, 0xdd, 0xe1, 0xff, 0xff, 0xff, 0xc3, 0xfd, 0xfd, 0xfd, 0xc3, 0xff, + 0xdf, 0xdf, 0xc3, 0xdd, 0xdd, 0xdd, 0xc3, 0xff, 0xff, 0xff, 0xe3, 0xdd, + 0xc1, 0xfd, 0xc3, 0xff, 0xe7, 0xdb, 0xfb, 0xe1, 0xfb, 0xfb, 0xfb, 0xff, + 0xff, 0xff, 0xe3, 0xdd, 0xdd, 0xc3, 0xdf, 0xe3, 0xfd, 0xfd, 0xe1, 0xdd, + 0xdd, 0xdd, 0xdd, 0xff, 0xf7, 0xff, 0xf3, 0xf7, 0xf7, 0xf7, 0xe3, 0xff, + 0xef, 0xff, 0xe7, 0xef, 0xef, 0xef, 0xed, 0xf3, 0xfd, 0xfd, 0xdd, 0xed, + 0xf1, 0xed, 0xdd, 0xff, 0xf3, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xe3, 0xff, + 0xff, 0xff, 0xc9, 0xd5, 0xd5, 0xd5, 0xdd, 0xff, 0xff, 0xff, 0xe1, 0xdd, + 0xdd, 0xdd, 0xdd, 0xff, 0xff, 0xff, 0xe3, 0xdd, 0xdd, 0xdd, 0xe3, 0xff, + 0xff, 0xff, 0xe1, 0xdd, 0xdd, 0xe1, 0xfd, 0xfd, 0xff, 0xff, 0xc3, 0xdd, + 0xdd, 0xc3, 0xdf, 0xdf, 0xff, 0xff, 0xc5, 0xf9, 0xfd, 0xfd, 0xfd, 0xff, + 0xff, 0xff, 0xc3, 0xfd, 0xe3, 0xdf, 0xe1, 0xff, 0xfb, 0xfb, 0xe1, 0xfb, + 0xfb, 0xdb, 0xe7, 0xff, 0xff, 0xff, 0xdd, 0xdd, 0xdd, 0xcd, 0xd3, 0xff, + 0xff, 0xff, 0xdd, 0xdd, 0xdd, 0xeb, 0xf7, 0xff, 0xff, 0xff, 0xdd, 0xdd, + 0xd5, 0xd5, 0xc9, 0xff, 0xff, 0xff, 0xdd, 0xeb, 0xf7, 0xeb, 0xdd, 0xff, + 0xff, 0xff, 0xdd, 0xdd, 0xdd, 0xc3, 0xdf, 0xe3, 0xff, 0xff, 0xc1, 0xef, + 0xf7, 0xfb, 0xc1, 0xff, 0xc7, 0xf3, 0xf3, 0xf9, 0xf3, 0xf3, 0xc7, 0xff, + 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf1, 0xe7, 0xe7, 0xcf, + 0xe7, 0xe7, 0xf1, 0xff, 0xd3, 0xe5, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xd5, 0xeb, 0xd5, 0xeb, 0xd5, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xfe, 0xfe, 0xee, 0xbb, 0xfe, 0xfe, 0xff, 0xff, + 0xfd, 0xfd, 0xdd, 0x77, 0xfd, 0xfd, 0xff, 0xff, 0xfc, 0xfc, 0xcc, 0x33, + 0xfc, 0xfc, 0xff, 0xff, 0xfb, 0xfb, 0xbb, 0xee, 0xfb, 0xfb, 0xff, 0xff, + 0xfa, 0xfa, 0xaa, 0xaa, 0xfa, 0xfa, 0xff, 0xff, 0xf9, 0xf9, 0x99, 0x66, + 0xf9, 0xf9, 0xff, 0xff, 0xf8, 0xf8, 0x88, 0x22, 0xf8, 0xf8, 0xff, 0xff, + 0xf7, 0xf7, 0x77, 0xdd, 0xf7, 0xf7, 0xff, 0xff, 0xf6, 0xf6, 0x66, 0x99, + 0xf6, 0xf6, 0xff, 0xff, 0xf5, 0xf5, 0x55, 0x55, 0xf5, 0xf5, 0xff, 0xff, + 0xf4, 0xf4, 0x44, 0x11, 0xf4, 0xf4, 0xff, 0xff, 0xf3, 0xf3, 0x33, 0xcc, + 0xf3, 0xf3, 0xff, 0xff, 0xf2, 0xf2, 0x22, 0x88, 0xf2, 0xf2, 0xff, 0xff, + 0xf1, 0xf1, 0x11, 0x44, 0xf1, 0xf1, 0xff, 0xff, 0xf0, 0xf0, 0x00, 0x00, + 0xf0, 0xf0, 0xff, 0xff, 0xef, 0xef, 0xff, 0xff, 0xef, 0xef, 0xee, 0xbb, + 0xee, 0xee, 0xee, 0xbb, 0xee, 0xee, 0xee, 0xbb, 0xed, 0xed, 0xdd, 0x77, + 0xed, 0xed, 0xee, 0xbb, 0xec, 0xec, 0xcc, 0x33, 0xec, 0xec, 0xee, 0xbb, + 0xeb, 0xeb, 0xbb, 0xee, 0xeb, 0xeb, 0xee, 0xbb, 0xea, 0xea, 0xaa, 0xaa, + 0xea, 0xea, 0xee, 0xbb, 0xe9, 0xe9, 0x99, 0x66, 0xe9, 0xe9, 0xee, 0xbb, + 0xe8, 0xe8, 0x88, 0x22, 0xe8, 0xe8, 0xee, 0xbb, 0xe7, 0xe7, 0x77, 0xdd, + 0xe7, 0xe7, 0xee, 0xbb, 0xe6, 0xe6, 0x66, 0x99, 0xe6, 0xe6, 0xee, 0xbb, + 0xe5, 0xe5, 0x55, 0x55, 0xe5, 0xe5, 0xee, 0xbb, 0xe4, 0xe4, 0x44, 0x11, + 0xe4, 0xe4, 0xee, 0xbb, 0xe3, 0xe3, 0x33, 0xcc, 0xe3, 0xe3, 0xee, 0xbb, + 0xe2, 0xe2, 0x22, 0x88, 0xe2, 0xe2, 0xee, 0xbb, 0xe1, 0xe1, 0x11, 0x44, + 0xe1, 0xe1, 0xee, 0xbb, 0xe0, 0xe0, 0x00, 0x00, 0xe0, 0xe0, 0xee, 0xbb, + 0xdf, 0xdf, 0xff, 0xff, 0xdf, 0xdf, 0xdd, 0x77, 0xde, 0xde, 0xee, 0xbb, + 0xde, 0xde, 0xdd, 0x77, 0xdd, 0xdd, 0xdd, 0x77, 0xdd, 0xdd, 0xdd, 0x77, + 0xdc, 0xdc, 0xcc, 0x33, 0xdc, 0xdc, 0xdd, 0x77, 0xdb, 0xdb, 0xbb, 0xee, + 0xdb, 0xdb, 0xdd, 0x77, 0xda, 0xda, 0xaa, 0xaa, 0xda, 0xda, 0xdd, 0x77, + 0xd9, 0xd9, 0x99, 0x66, 0xd9, 0xd9, 0xdd, 0x77, 0xd8, 0xd8, 0x88, 0x22, + 0xd8, 0xd8, 0xdd, 0x77, 0xd7, 0xd7, 0x77, 0xdd, 0xd7, 0xd7, 0xdd, 0x77, + 0xd6, 0xd6, 0x66, 0x99, 0xd6, 0xd6, 0xdd, 0x77, 0xd5, 0xd5, 0x55, 0x55, + 0xd5, 0xd5, 0xdd, 0x77, 0xd4, 0xd4, 0x44, 0x11, 0xd4, 0xd4, 0xdd, 0x77, + 0xd3, 0xd3, 0x33, 0xcc, 0xd3, 0xd3, 0xdd, 0x77, 0xd2, 0xd2, 0x22, 0x88, + 0xd2, 0xd2, 0xdd, 0x77, 0xd1, 0xd1, 0x11, 0x44, 0xd1, 0xd1, 0xdd, 0x77, + 0xd0, 0xd0, 0x00, 0x00, 0xd0, 0xd0, 0xdd, 0x77, 0xcf, 0xcf, 0xff, 0xff, + 0xcf, 0xcf, 0xcc, 0x33, 0xce, 0xce, 0xee, 0xbb, 0xce, 0xce, 0xcc, 0x33, + 0xcd, 0xcd, 0xdd, 0x77, 0xcd, 0xcd, 0xcc, 0x33, 0xcc, 0xcc, 0xcc, 0x33, + 0xcc, 0xcc, 0xcc, 0x33, 0xcb, 0xcb, 0xbb, 0xee, 0xcb, 0xcb, 0xcc, 0x33, + 0xca, 0xca, 0xaa, 0xaa, 0xca, 0xca, 0xcc, 0x33, 0xc9, 0xc9, 0x99, 0x66, + 0xc9, 0xc9, 0xcc, 0x33, 0xc8, 0xc8, 0x88, 0x22, 0xc8, 0xc8, 0xcc, 0x33, + 0xc7, 0xc7, 0x77, 0xdd, 0xc7, 0xc7, 0xcc, 0x33, 0xc6, 0xc6, 0x66, 0x99, + 0xc6, 0xc6, 0xcc, 0x33, 0xc5, 0xc5, 0x55, 0x55, 0xc5, 0xc5, 0xcc, 0x33, + 0xc4, 0xc4, 0x44, 0x11, 0xc4, 0xc4, 0xcc, 0x33, 0xc3, 0xc3, 0x33, 0xcc, + 0xc3, 0xc3, 0xcc, 0x33, 0xc2, 0xc2, 0x22, 0x88, 0xc2, 0xc2, 0xcc, 0x33, + 0xc1, 0xc1, 0x11, 0x44, 0xc1, 0xc1, 0xcc, 0x33, 0xc0, 0xc0, 0x00, 0x00, + 0xc0, 0xc0, 0xcc, 0x33, 0xbf, 0xbf, 0xff, 0xff, 0xbf, 0xbf, 0xbb, 0xee, + 0xbe, 0xbe, 0xee, 0xbb, 0xbe, 0xbe, 0xbb, 0xee, 0xbd, 0xbd, 0xdd, 0x77, + 0xbd, 0xbd, 0xbb, 0xee, 0xbc, 0xbc, 0xcc, 0x33, 0xbc, 0xbc, 0xbb, 0xee, + 0xbb, 0xbb, 0xbb, 0xee, 0xbb, 0xbb, 0xbb, 0xee, 0xba, 0xba, 0xaa, 0xaa, + 0xba, 0xba, 0xbb, 0xee, 0xb9, 0xb9, 0x99, 0x66, 0xb9, 0xb9, 0xbb, 0xee, + 0xb8, 0xb8, 0x88, 0x22, 0xb8, 0xb8, 0xbb, 0xee, 0xb7, 0xb7, 0x77, 0xdd, + 0xb7, 0xb7, 0xbb, 0xee, 0xb6, 0xb6, 0x66, 0x99, 0xb6, 0xb6, 0xbb, 0xee, + 0xb5, 0xb5, 0x55, 0x55, 0xb5, 0xb5, 0xbb, 0xee, 0xb4, 0xb4, 0x44, 0x11, + 0xb4, 0xb4, 0xbb, 0xee, 0xb3, 0xb3, 0x33, 0xcc, 0xb3, 0xb3, 0xbb, 0xee, + 0xb2, 0xb2, 0x22, 0x88, 0xb2, 0xb2, 0xbb, 0xee, 0xb1, 0xb1, 0x11, 0x44, + 0xb1, 0xb1, 0xbb, 0xee, 0xb0, 0xb0, 0x00, 0x00, 0xb0, 0xb0, 0xbb, 0xee, + 0xaf, 0xaf, 0xff, 0xff, 0xaf, 0xaf, 0xaa, 0xaa, 0xae, 0xae, 0xee, 0xbb, + 0xae, 0xae, 0xaa, 0xaa, 0xad, 0xad, 0xdd, 0x77, 0xad, 0xad, 0xaa, 0xaa, + 0xac, 0xac, 0xcc, 0x33, 0xac, 0xac, 0xaa, 0xaa, 0xab, 0xab, 0xbb, 0xee, + 0xab, 0xab, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xa9, 0xa9, 0x99, 0x66, 0xa9, 0xa9, 0xaa, 0xaa, 0xa8, 0xa8, 0x88, 0x22, + 0xa8, 0xa8, 0xaa, 0xaa, 0xa7, 0xa7, 0x77, 0xdd, 0xa7, 0xa7, 0xaa, 0xaa, + 0xa6, 0xa6, 0x66, 0x99, 0xa6, 0xa6, 0xaa, 0xaa, 0xa5, 0xa5, 0x55, 0x55, + 0xa5, 0xa5, 0xaa, 0xaa, 0xa4, 0xa4, 0x44, 0x11, 0xa4, 0xa4, 0xaa, 0xaa, + 0xa3, 0xa3, 0x33, 0xcc, 0xa3, 0xa3, 0xaa, 0xaa, 0xa2, 0xa2, 0x22, 0x88, + 0xa2, 0xa2, 0xaa, 0xaa, 0xa1, 0xa1, 0x11, 0x44, 0xa1, 0xa1, 0xaa, 0xaa, + 0xa0, 0xa0, 0x00, 0x00, 0xa0, 0xa0, 0xaa, 0xaa, 0x9f, 0x9f, 0xff, 0xff, + 0x9f, 0x9f, 0x99, 0x66, 0x9e, 0x9e, 0xee, 0xbb, 0x9e, 0x9e, 0x99, 0x66, + 0x9d, 0x9d, 0xdd, 0x77, 0x9d, 0x9d, 0x99, 0x66, 0x9c, 0x9c, 0xcc, 0x33, + 0x9c, 0x9c, 0x99, 0x66, 0x9b, 0x9b, 0xbb, 0xee, 0x9b, 0x9b, 0x99, 0x66, + 0x9a, 0x9a, 0xaa, 0xaa, 0x9a, 0x9a, 0x99, 0x66, 0x99, 0x99, 0x99, 0x66, + 0x99, 0x99, 0x99, 0x66, 0x98, 0x98, 0x88, 0x22, 0x98, 0x98, 0x99, 0x66, + 0x97, 0x97, 0x77, 0xdd, 0x97, 0x97, 0x99, 0x66, 0x96, 0x96, 0x66, 0x99, + 0x96, 0x96, 0x99, 0x66, 0x95, 0x95, 0x55, 0x55, 0x95, 0x95, 0x99, 0x66, + 0x94, 0x94, 0x44, 0x11, 0x94, 0x94, 0x99, 0x66, 0x93, 0x93, 0x33, 0xcc, + 0x93, 0x93, 0x99, 0x66, 0x92, 0x92, 0x22, 0x88, 0x92, 0x92, 0x99, 0x66, + 0x91, 0x91, 0x11, 0x44, 0x91, 0x91, 0x99, 0x66, 0x90, 0x90, 0x00, 0x00, + 0x90, 0x90, 0x99, 0x66, 0x8f, 0x8f, 0xff, 0xff, 0x8f, 0x8f, 0x88, 0x22, + 0x8e, 0x8e, 0xee, 0xbb, 0x8e, 0x8e, 0x88, 0x22, 0x8d, 0x8d, 0xdd, 0x77, + 0x8d, 0x8d, 0x88, 0x22, 0x8c, 0x8c, 0xcc, 0x33, 0x8c, 0x8c, 0x88, 0x22, + 0x8b, 0x8b, 0xbb, 0xee, 0x8b, 0x8b, 0x88, 0x22, 0x8a, 0x8a, 0xaa, 0xaa, + 0x8a, 0x8a, 0x88, 0x22, 0x89, 0x89, 0x99, 0x66, 0x89, 0x89, 0x88, 0x22, + 0x88, 0x88, 0x88, 0x22, 0x88, 0x88, 0x88, 0x22, 0x87, 0x87, 0x77, 0xdd, + 0x87, 0x87, 0x88, 0x22, 0x86, 0x86, 0x66, 0x99, 0x86, 0x86, 0x88, 0x22, + 0x85, 0x85, 0x55, 0x55, 0x85, 0x85, 0x88, 0x22, 0x84, 0x84, 0x44, 0x11, + 0x84, 0x84, 0x88, 0x22, 0x83, 0x83, 0x33, 0xcc, 0x83, 0x83, 0x88, 0x22, + 0x82, 0x82, 0x22, 0x88, 0x82, 0x82, 0x88, 0x22, 0x81, 0x81, 0x11, 0x44, + 0x81, 0x81, 0x88, 0x22, 0x80, 0x80, 0x00, 0x00, 0x80, 0x80, 0x88, 0x22, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x77, 0xdd, 0xfe, 0xfe, 0xee, 0xbb, + 0xfe, 0xfe, 0x77, 0xdd, 0xfd, 0xfd, 0xdd, 0x77, 0xfd, 0xfd, 0x77, 0xdd, + 0xfc, 0xfc, 0xcc, 0x33, 0xfc, 0xfc, 0x77, 0xdd, 0xfb, 0xfb, 0xbb, 0xee, + 0xfb, 0xfb, 0x77, 0xdd, 0xfa, 0xfa, 0xaa, 0xaa, 0xfa, 0xfa, 0x77, 0xdd, + 0xf9, 0xf9, 0x99, 0x66, 0xf9, 0xf9, 0x77, 0xdd, 0xf8, 0xf8, 0x88, 0x22, + 0xf8, 0xf8, 0x77, 0xdd, 0xf7, 0xf7, 0x77, 0xdd, 0xf7, 0xf7, 0x77, 0xdd, + 0xf6, 0xf6, 0x66, 0x99, 0xf6, 0xf6, 0x77, 0xdd, 0xf5, 0xf5, 0x55, 0x55, + 0xf5, 0xf5, 0x77, 0xdd, 0xf4, 0xf4, 0x44, 0x11, 0xf4, 0xf4, 0x77, 0xdd, + 0xf3, 0xf3, 0x33, 0xcc, 0xf3, 0xf3, 0x77, 0xdd, 0xf2, 0xf2, 0x22, 0x88, + 0xf2, 0xf2, 0x77, 0xdd, 0xf1, 0xf1, 0x11, 0x44, 0xf1, 0xf1, 0x77, 0xdd, + 0xf0, 0xf0, 0x00, 0x00, 0xf0, 0xf0, 0x77, 0xdd, 0xef, 0xef, 0xff, 0xff, + 0xef, 0xef, 0x66, 0x99, 0xee, 0xee, 0xee, 0xbb, 0xee, 0xee, 0x66, 0x99, + 0xed, 0xed, 0xdd, 0x77, 0xed, 0xed, 0x66, 0x99, 0xec, 0xec, 0xcc, 0x33, + 0xec, 0xec, 0x66, 0x99, 0xeb, 0xeb, 0xbb, 0xee, 0xeb, 0xeb, 0x66, 0x99, + 0xea, 0xea, 0xaa, 0xaa, 0xea, 0xea, 0x66, 0x99, 0xe9, 0xe9, 0x99, 0x66, + 0xe9, 0xe9, 0x66, 0x99, 0xe8, 0xe8, 0x88, 0x22, 0xe8, 0xe8, 0x66, 0x99, + 0xe7, 0xe7, 0x77, 0xdd, 0xe7, 0xe7, 0x66, 0x99, 0xe6, 0xe6, 0x66, 0x99, + 0xe6, 0xe6, 0x66, 0x99, 0xe5, 0xe5, 0x55, 0x55, 0xe5, 0xe5, 0x66, 0x99, + 0xe4, 0xe4, 0x44, 0x11, 0xe4, 0xe4, 0x66, 0x99, 0xe3, 0xe3, 0x33, 0xcc, + 0xe3, 0xe3, 0x66, 0x99, 0xe2, 0xe2, 0x22, 0x88, 0xe2, 0xe2, 0x66, 0x99, + 0xe1, 0xe1, 0x11, 0x44, 0xe1, 0xe1, 0x66, 0x99, 0xe0, 0xe0, 0x00, 0x00, + 0xe0, 0xe0, 0x66, 0x99, 0xdf, 0xdf, 0xff, 0xff, 0xdf, 0xdf, 0x55, 0x55, + 0xde, 0xde, 0xee, 0xbb, 0xde, 0xde, 0x55, 0x55, 0xdd, 0xdd, 0xdd, 0x77, + 0xdd, 0xdd, 0x55, 0x55, 0xdc, 0xdc, 0xcc, 0x33, 0xdc, 0xdc, 0x55, 0x55, + 0xdb, 0xdb, 0xbb, 0xee, 0xdb, 0xdb, 0x55, 0x55, 0xda, 0xda, 0xaa, 0xaa, + 0xda, 0xda, 0x55, 0x55, 0xd9, 0xd9, 0x99, 0x66, 0xd9, 0xd9, 0x55, 0x55, + 0xd8, 0xd8, 0x88, 0x22, 0xd8, 0xd8, 0x55, 0x55, 0xd7, 0xd7, 0x77, 0xdd, + 0xd7, 0xd7, 0x55, 0x55, 0xd6, 0xd6, 0x66, 0x99, 0xd6, 0xd6, 0x55, 0x55, + 0xd5, 0xd5, 0x55, 0x55, 0xd5, 0xd5, 0x55, 0x55, 0xd4, 0xd4, 0x44, 0x11, + 0xd4, 0xd4, 0x55, 0x55, 0xd3, 0xd3, 0x33, 0xcc, 0xd3, 0xd3, 0x55, 0x55, + 0xd2, 0xd2, 0x22, 0x88, 0xd2, 0xd2, 0x55, 0x55, 0xd1, 0xd1, 0x11, 0x44, + 0xd1, 0xd1, 0x55, 0x55, 0xd0, 0xd0, 0x00, 0x00, 0xd0, 0xd0, 0x55, 0x55, + 0xcf, 0xcf, 0xff, 0xff, 0xcf, 0xcf, 0x44, 0x11, 0xce, 0xce, 0xee, 0xbb, + 0xce, 0xce, 0x44, 0x11, 0xcd, 0xcd, 0xdd, 0x77, 0xcd, 0xcd, 0x44, 0x11, + 0xcc, 0xcc, 0xcc, 0x33, 0xcc, 0xcc, 0x44, 0x11, 0xcb, 0xcb, 0xbb, 0xee, + 0xcb, 0xcb, 0x44, 0x11, 0xca, 0xca, 0xaa, 0xaa, 0xca, 0xca, 0x44, 0x11, + 0xc9, 0xc9, 0x99, 0x66, 0xc9, 0xc9, 0x44, 0x11, 0xc8, 0xc8, 0x88, 0x22, + 0xc8, 0xc8, 0x44, 0x11, 0xc7, 0xc7, 0x77, 0xdd, 0xc7, 0xc7, 0x44, 0x11, + 0xc6, 0xc6, 0x66, 0x99, 0xc6, 0xc6, 0x44, 0x11, 0xc5, 0xc5, 0x55, 0x55, + 0xc5, 0xc5, 0x44, 0x11, 0xc4, 0xc4, 0x44, 0x11, 0xc4, 0xc4, 0x44, 0x11, + 0xc3, 0xc3, 0x33, 0xcc, 0xc3, 0xc3, 0x44, 0x11, 0xc2, 0xc2, 0x22, 0x88, + 0xc2, 0xc2, 0x44, 0x11, 0xc1, 0xc1, 0x11, 0x44, 0xc1, 0xc1, 0x44, 0x11, + 0xc0, 0xc0, 0x00, 0x00, 0xc0, 0xc0, 0x44, 0x11, 0xbf, 0xbf, 0xff, 0xff, + 0xbf, 0xbf, 0x33, 0xcc, 0xbe, 0xbe, 0xee, 0xbb, 0xbe, 0xbe, 0x33, 0xcc, + 0xbd, 0xbd, 0xdd, 0x77, 0xbd, 0xbd, 0x33, 0xcc, 0xbc, 0xbc, 0xcc, 0x33, + 0xbc, 0xbc, 0x33, 0xcc, 0xbb, 0xbb, 0xbb, 0xee, 0xbb, 0xbb, 0x33, 0xcc, + 0xba, 0xba, 0xaa, 0xaa, 0xba, 0xba, 0x33, 0xcc, 0xb9, 0xb9, 0x99, 0x66, + 0xb9, 0xb9, 0x33, 0xcc, 0xb8, 0xb8, 0x88, 0x22, 0xb8, 0xb8, 0x33, 0xcc, + 0xb7, 0xb7, 0x77, 0xdd, 0xb7, 0xb7, 0x33, 0xcc, 0xb6, 0xb6, 0x66, 0x99, + 0xb6, 0xb6, 0x33, 0xcc, 0xb5, 0xb5, 0x55, 0x55, 0xb5, 0xb5, 0x33, 0xcc, + 0xb4, 0xb4, 0x44, 0x11, 0xb4, 0xb4, 0x33, 0xcc, 0xb3, 0xb3, 0x33, 0xcc, + 0xb3, 0xb3, 0x33, 0xcc, 0xb2, 0xb2, 0x22, 0x88, 0xb2, 0xb2, 0x33, 0xcc, + 0xb1, 0xb1, 0x11, 0x44, 0xb1, 0xb1, 0x33, 0xcc, 0xb0, 0xb0, 0x00, 0x00, + 0xb0, 0xb0, 0x33, 0xcc, 0xaf, 0xaf, 0xff, 0xff, 0xaf, 0xaf, 0x22, 0x88, + 0xae, 0xae, 0xee, 0xbb, 0xae, 0xae, 0x22, 0x88, 0xad, 0xad, 0xdd, 0x77, + 0xad, 0xad, 0x22, 0x88, 0xac, 0xac, 0xcc, 0x33, 0xac, 0xac, 0x22, 0x88, + 0xab, 0xab, 0xbb, 0xee, 0xab, 0xab, 0x22, 0x88, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0x22, 0x88, 0xa9, 0xa9, 0x99, 0x66, 0xa9, 0xa9, 0x22, 0x88, + 0xa8, 0xa8, 0x88, 0x22, 0xa8, 0xa8, 0x22, 0x88, 0xa7, 0xa7, 0x77, 0xdd, + 0xa7, 0xa7, 0x22, 0x88, 0xa6, 0xa6, 0x66, 0x99, 0xa6, 0xa6, 0x22, 0x88, + 0xa5, 0xa5, 0x55, 0x55, 0xa5, 0xa5, 0x22, 0x88, 0xa4, 0xa4, 0x44, 0x11, + 0xa4, 0xa4, 0x22, 0x88, 0xa3, 0xa3, 0x33, 0xcc, 0xa3, 0xa3, 0x22, 0x88, + 0xa2, 0xa2, 0x22, 0x88, 0xa2, 0xa2, 0x22, 0x88, 0xa1, 0xa1, 0x11, 0x44, + 0xa1, 0xa1, 0x22, 0x88, 0xa0, 0xa0, 0x00, 0x00, 0xa0, 0xa0, 0x22, 0x88, + 0x9f, 0x9f, 0xff, 0xff, 0x9f, 0x9f, 0x11, 0x44, 0x9e, 0x9e, 0xee, 0xbb, + 0x9e, 0x9e, 0x11, 0x44, 0x9d, 0x9d, 0xdd, 0x77, 0x9d, 0x9d, 0x11, 0x44, + 0x9c, 0x9c, 0xcc, 0x33, 0x9c, 0x9c, 0x11, 0x44, 0x9b, 0x9b, 0xbb, 0xee, + 0x9b, 0x9b, 0x11, 0x44, 0x9a, 0x9a, 0xaa, 0xaa, 0x9a, 0x9a, 0x11, 0x44, + 0x99, 0x99, 0x99, 0x66, 0x99, 0x99, 0x11, 0x44, 0x98, 0x98, 0x88, 0x22, + 0x98, 0x98, 0x11, 0x44, 0x97, 0x97, 0x77, 0xdd, 0x97, 0x97, 0x11, 0x44, + 0x96, 0x96, 0x66, 0x99, 0x96, 0x96, 0x11, 0x44, 0x95, 0x95, 0x55, 0x55, + 0x95, 0x95, 0x11, 0x44, 0x94, 0x94, 0x44, 0x11, 0x94, 0x94, 0x11, 0x44, + 0x93, 0x93, 0x33, 0xcc, 0x93, 0x93, 0x11, 0x44, 0x92, 0x92, 0x22, 0x88, + 0x92, 0x92, 0x11, 0x44, 0x91, 0x91, 0x11, 0x44, 0x91, 0x91, 0x11, 0x44, + 0x90, 0x90, 0x00, 0x00, 0x90, 0x90, 0x11, 0x44, 0x8f, 0x8f, 0xff, 0xff, + 0x8f, 0x8f, 0x00, 0x00, 0x8e, 0x8e, 0xee, 0xbb, 0x8e, 0x8e, 0x00, 0x00, + 0x8d, 0x8d, 0xdd, 0x77, 0x8d, 0x8d, 0x00, 0x00, 0x8c, 0x8c, 0xcc, 0x33, + 0x8c, 0x8c, 0x00, 0x00, 0x8b, 0x8b, 0xbb, 0xee, 0x8b, 0x8b, 0x00, 0x00, + 0x8a, 0x8a, 0xaa, 0xaa, 0x8a, 0x8a, 0x00, 0x00, 0x89, 0x89, 0x99, 0x66, + 0x89, 0x89, 0x00, 0x00, 0x88, 0x88, 0x88, 0x22, 0x88, 0x88, 0x00, 0x00, + 0x87, 0x87, 0x77, 0xdd, 0x87, 0x87, 0x00, 0x00, 0x86, 0x86, 0x66, 0x99, + 0x86, 0x86, 0x00, 0x00, 0x85, 0x85, 0x55, 0x55, 0x85, 0x85, 0x00, 0x00, + 0x84, 0x84, 0x44, 0x11, 0x84, 0x84, 0x00, 0x00, 0x83, 0x83, 0x33, 0xcc, + 0x83, 0x83, 0x00, 0x00, 0x82, 0x82, 0x22, 0x88, 0x82, 0x82, 0x00, 0x00, + 0x81, 0x81, 0x11, 0x44, 0x81, 0x81, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, + 0x80, 0x80, 0x00, 0x00 +}; +static const unsigned int iie_enhanced_video_len = 4096; diff --git a/test/asm/001_jmp_indirect.asm b/test/asm/001_jmp_indirect.asm new file mode 100644 index 0000000..0b309a8 --- /dev/null +++ b/test/asm/001_jmp_indirect.asm @@ -0,0 +1,17 @@ +; 65c02 Indirect Indexed JMP ($xxx,X) + .org $2000 +jump_ad = $3000 + ;.verbose + JMP skip +ind LDA #$99 ; $2003 + BRA pass +skip: LDA #ind + STA jump_ad,Y + LDX #$02 + JMP ($3000,X) ; JMP -> $2003 +fail BRK ; JMP Failed! +pass BRK diff --git a/test/asm/002_jsr_rts.asm b/test/asm/002_jsr_rts.asm new file mode 100644 index 0000000..a25a908 --- /dev/null +++ b/test/asm/002_jsr_rts.asm @@ -0,0 +1,25 @@ +; 65c02 JSR/RTS/SBC/BEQ + .org $2000 + ;.verbose + CLC + LDA #$00 + JSR skip + SEC + SBC #$03 + BEQ back + JMP fail +skip LDA #$03 + RTS +fail BRK ; JSR Failed! +; now test setting some address on the stack and call RTS +jump LDA #>pass + PHA + LDA # $70) + asl ; We need this for the ProDOS unit number (below). + asl ; Format = bits DSSS0000 + asl ; D = drive number (0), SSS = slot number (1-7) + sta unit ; Store ProDOS unit number here + lda #$08 ; Store block (512 bytes) at address $0800 + sta bufhi ; Address high byte + stz buflo ; Address low byte + stz blklo ; Block 0 low byte + stz blkhi ; Block 0 high byte + jsr $07FD ; Read the block (will jmp to our driver and trigger it) + bcs error + lda #$0A ; Store block (512 bytes) at address $0A00 + sta bufhi ; Address high byte + lda #$01 + sta blklo ; Block 1 low byte + jsr $07FD ; Read + bcs error + lda $0801 ; Should be nonzero + beq error + lda #$01 ; Should always be 1 + cmp $0800 + bne error + ldx unit ; ProDOS block 0 code wants ProDOS unit number in X + jmp $801 ; Continue reading the disk +error jmp $E000 ; Out to BASIC on error + + .org $c0c0 +; jump back to mii code +entryHD nop ; Hard drive driver address + bra magicHD + bra magicSM + + .org $c0d0 +magicHD .db $db, $fb, $0 + bra done + + .org $c0e0 +magicSM .db $db, $fb, $0 + bra done + + .org $c0f0 +DONE bcs ERR + lda #$00 + rts +ERR lda #$27 + rts + +; $CnFE status byte +; bit 7 - Medium is removable. +; bit 6 - Device is interruptable. +; bit 5-4 - Number of volumes on the device (0-3). +; bit 3 - The device supports formatting. +; bit 2 - The device can be written to. +; bit 1 - The device can be read from (must be on). +; bit 0 - The device's status can be read (must be on). + .org $c0fe + .db $17 + .db entryOffset ; entry point offset diff --git a/test/asm/mii_smartport_driver.bin b/test/asm/mii_smartport_driver.bin new file mode 100644 index 0000000..a67c1b9 Binary files /dev/null and b/test/asm/mii_smartport_driver.bin differ diff --git a/test/mii_asm.c b/test/mii_asm.c new file mode 100644 index 0000000..cca3720 --- /dev/null +++ b/test/mii_asm.c @@ -0,0 +1,83 @@ +/* + * mii_asm.c + * + * Copyright (C) 2023 Michel Pollet + * + * SPDX-License-Identifier: MIT + * + * Small command line assembler for our own drivers + * + */ + +#include +#include +#include +#include + +#include "mii_65c02.h" +#include "mii_65c02_asm.h" +#include "mii_65c02_disasm.h" +#include "mii_65c02_ops.h" + +int +main( + int argc, + const char * argv[]) +{ + const char *infile = NULL; + const char *outfile = NULL; + int verbose = 0; + // parse arguments + for (int i = 1; i < argc; i++) { + if (!strcmp(argv[i], "-o")) { + if (i + 1 >= argc) { + fprintf(stderr, "%s Missing argument for -o\n", argv[0]); + exit(1); + } + outfile = argv[++i]; + } else if (!strcmp(argv[i], "-v")) { + verbose = 1; + } else if (!infile) { + infile = argv[i]; + } else { + fprintf(stderr, "%s Unknown argument %s\n", argv[0], argv[i]); + exit(1); + } + } + if (!infile || !outfile) { + fprintf(stderr, "Usage: mii_asm [-v] -o outfile infile\n"); + exit(1); + } + char *prog = calloc(1, 65536); + if (verbose) + printf("%s Loading %s\n", argv[0], infile); + FILE *f = fopen(infile, "r"); + if (!f) { + perror(infile); + exit(1); + + } + fread(prog, 1, 65536, f); + fclose(f); + + mii_cpu_asm_program_t p = {}; + p.verbose = verbose; + if (mii_cpu_asm(&p, prog) == 0) { + if (verbose) + mii_cpu_disasm(p.output, p.org, p.output_len); + if (verbose) + printf("%s Writing %s\n", argv[0], outfile); + f = fopen(outfile, "w"); + if (!f) { + perror(outfile); + exit(1); + } + fwrite(p.output, 1, p.output_len, f); + fclose(f); + } else { + fprintf(stderr, "%s: %s error, no output\n", argv[0], infile); + exit(1); + } + + return 0; +} diff --git a/test/mii_cpu_test.c b/test/mii_cpu_test.c new file mode 100644 index 0000000..5145ca9 --- /dev/null +++ b/test/mii_cpu_test.c @@ -0,0 +1,521 @@ +/* + * mii_cpu_test.c + * + * Copyright (C) 2023 Michel Pollet + * + * SPDX-License-Identifier: MIT + * + * This was heavily inspired and converted from + * https://github.com/ct6502/apple2ts/blob/main/src/emulator/instructions.test.ts + * + */ + +#include +#include +#include +#include + +#include "mii_65c02.h" +#include "mii_65c02_asm.h" +#include "mii_65c02_disasm.h" +#include "mii_65c02_ops.h" + + +static void +_run_one_dump_state( + mii_cpu_t *cpu, + mii_cpu_state_t s, + void *p) +{ + printf("PC:%04X A:%02X X:%02X Y:%02X S:%02x #%d %s AD:%04X D:%02x %s ", + cpu->PC, cpu->A, cpu->X, cpu->Y, cpu->S, cpu->cycle, + s.sync ? "I" : " ", s.addr, s.data, s.w ? "W" : "R"); + // display the S flags + static const char *s_flags = "CZIDBRVN"; + for (int i = 0; i < 8; i++) + printf("%c", cpu->P.P[i] ? s_flags[i] : tolower(s_flags[i])); + if (s.sync) { + mii_op_t d = mii_cpu_op[cpu->ram[cpu->PC]]; + printf(" "); + char dis[64]; + mii_cpu_disasm_one(cpu->ram + cpu->PC, cpu->PC, dis, sizeof(dis), + MII_DUMP_DIS_PC | MII_DUMP_DIS_DUMP_HEX); + printf("%s", dis); + if (d.desc.branch) { + if (cpu->P.P[d.desc.s_bit] == d.desc.s_bit_value) + printf(" ; taken"); + } + printf("\n"); + } else + printf("\n"); +} + + +static int +_run_one_test( + const char *prog, + int verbose) +{ + uint8_t *ram = calloc(1, 0x10000); + mii_cpu_asm_program_t p = {}; + { + p.verbose = verbose; + if (mii_cpu_asm(&p, prog) == 0) { + // uint8_t *o = p.output; + if (verbose || p.verbose) + mii_cpu_disasm(p.output, p.org, p.output_len); + memcpy(ram + p.org, p.output, p.output_len); + } else { + printf("error\n"); + exit(1); + } + } + mii_cpu_t cpu = {0}; + mii_cpu_state_t s = {0}; + verbose += p.verbose; + cpu.ram = ram; + if (verbose) { + // cpu.debug = _run_one_dump_state; + } + cpu.P.P[5] = 1; + cpu.S = 0xFF; + cpu.PC = p.org; + cpu.A = 0x01; + int count = 1000; + int error = 1; + do { + s = mii_cpu_run(&cpu, s); + if (s.w) ram[s.addr] = s.data; + else s.data = ram[s.addr]; + if (verbose) + _run_one_dump_state(&cpu, s, NULL); + if (s.sync && !s.w && s.data == 0x00) { + mii_cpu_asm_line_t *l = p.prog; + while (l) { + if (l->addr == s.addr) + break; + l = l->next; + } + if (l && !strcasecmp(l->label, "pass")) { + printf("TEST %-40.40s: PASS\n", p.prog->line + 2); + error = 0; + } else if (l) { + printf("TEST %-40.40s: FAIL\n", p.prog->line + 2); + printf("\t%s\n", l->line); + _run_one_dump_state(&cpu, s, NULL); + } else { + printf("TEST %-40.40s: FAIL (out of program!)\n", + p.prog->line + 2); + _run_one_dump_state(&cpu, s, NULL); + } + break; + } + } while (count--); + if (!count) { + printf("TEST %-40.40s: FAIL (out of _run_this cycles!)\n", + p.prog->line + 2); + _run_one_dump_state(&cpu, s, NULL); + } + free(ram); + return error; +} + +int +_run_this_one( + const char *desc, + const char *prog, + uint8_t expexted_A, + uint8_t expected_flags, + int verbose ) +{ + uint8_t *ram = calloc(1, 0x10000); + mii_cpu_asm_program_t p = {.org = 0x2000}; + { + if (mii_cpu_asm(&p, prog) == 0) { + // uint8_t *o = p.output; + if (verbose || p.verbose) + mii_cpu_disasm(p.output, p.org, p.output_len); + memcpy(ram + p.org, p.output, p.output_len); + } else { + printf("error\n"); + exit(1); + } + } + mii_cpu_t cpu = {0}; + mii_cpu_state_t s = {0}; + verbose += p.verbose; + cpu.ram = ram; + cpu.P.P[B_X] = 1; + expected_flags |= (1 << B_X); + cpu.S = 0xFF; + cpu.PC = p.org; + cpu.A = 0x01; + int count = 1000; + do { + s = mii_cpu_run(&cpu, s); + if (s.w) ram[s.addr] = s.data; + else s.data = ram[s.addr]; + if (verbose) + _run_one_dump_state(&cpu, s, NULL); + if (s.sync && !s.w && s.data == 0x00) { + if (cpu.A == expexted_A) { + int err = 0; + static const char *s_flags = "CZIDBRVN"; + for (int i = 0; i < 8; i++) + if (cpu.P.P[i] != ((expected_flags >> i) & 1)) { + printf("** S bit %c mismatch %d want %d\n", + s_flags[i], cpu.P.P[i], (expected_flags >> i) & 1); + err++; + } + if (err) + goto fail; + printf("TEST %-40.40s: PASS\n", desc); + break; + } else { + printf("** A Mismatch %02x vs %02x\n", cpu.A, expexted_A); +fail: + printf("TEST %-40.40s: FAIL\n", desc); + return -1; + } + } + } while (count--); + free(ram); + return 0; +} + +void +_run_this( + const char *desc, + const char *prog, + uint8_t expexted_A, + uint8_t expected_flags, + int verbose ) +{ + int e = _run_this_one(desc, prog, expexted_A, expected_flags, verbose); + if (e && !verbose) { + if (_run_this_one(desc, prog, expexted_A, expected_flags, 1)) + exit(1); + } +} + +static char * indirect(char *prefix, uint8_t A, uint8_t mem, char *suffix) { + char *s = calloc(1, 256); + sprintf(s, + " %s\n" + " LDA #$01\n" + " STA $12\n" + " LDA #$30\n" + " STA $13\n" + " LDA #$%02x\n" + " STA $3001\n" + " LDA #$%02x\n" + " %s\n", prefix, mem, A, suffix); + return s; +} +static char * doSED_ADC(uint8_t a, uint8_t b) { + char *s = calloc(1, 256); + sprintf(s, + " SED\n" + " LDA #$%02x\n" + " ADC #$%02x\n", + a, b); + return s; +} + +#include +int main() +{ + glob_t globbuf; + glob("test/asm/0*.asm", 0, NULL, &globbuf); + for (int i = 0; i < (int)globbuf.gl_pathc; i++) { + printf("Loading %s\n", globbuf.gl_pathv[i]); + FILE *f = fopen(globbuf.gl_pathv[i], "r"); + if (f) { + char *prog = calloc(1, 65536); + fread(prog, 1, 65536, f); + fclose(f); + _run_one_test(prog, 0); + free(prog); + } + } + globfree(&globbuf); + enum { + C = (1 << B_C), + Z = (1 << B_Z), + I = (1 << B_I), + D = (1 << B_D), + B = (1 << B_B), + X = (1 << B_X), + V = (1 << B_V), + N = (1 << B_N), + }; + _run_this("RMB $12", + " lda #$FF\n" + " sta $12\n" + " rmb1 $12\n" + " lda $12\n", + 0xfd, N, 0); + _run_this("RMB1 $ea", + " ldx $EA\n" + " lda #$FF\n" + " sta $EA\n" + " rmb1 $EA\n" + " cmp $EA\n" + " stx $EA\n", + 0xff, C, 0); + _run_this("ASL Carry", + " clc\n lda #$80\n asl\n", + 0x00, Z|C, 0); + _run_this("ROL Base", + " sec\n lda #$80\n rol\n", + 0x01, C, 0); + + _run_this("SBC Over+", + " sec\n lda #$d0\n sbc #$70\n", + 0x60, V|C, 0); + _run_this("SBC Neg3", + " sec\n lda #$d0\n sbc #$30\n", + 0xA0, N|C, 0); + _run_this("LDA ($aa,X)", + " LDX #$E9\n" + " LDY #$81\n" + " STY $3104\n" + " LDY #$04\n" + " STY $003A\n" + " LDY #$31\n" + " STY $003B\n" + " LDA ($51,X)\n", + 0x81, N, 0); + _run_this("LDA ($aa),Y", + " LDY #$E9\n" + " LDX #$BB\n" + " STX $403A\n" + " LDX #$51\n" + " STX $00A4\n" + " LDX #$3F\n" + " STX $00A5\n" + " LDA ($A4),Y\n", + 0xBB, N, 0); + _run_this("JMP ($3000,X)", + " JMP skip\n" + " LDA #$99 ; $2003\n" + " JMP done\n" + "skip LDA #$03\n" + " STA $3002\n" + " LDA #$20\n" + " STA $3003\n" + " LDX #$02\n" + " JMP ($3000,X) ; JMP -> $2003\n" + " LDA #$01 ; should not reach here\n" + "done NOP ;\n", + 0x99, N, 0); + _run_this("DEC", + " LDA #99\n" " DEC\n", + 0x98, N, 0); + _run_this("PLX", + " LDX #$97\n" " PHX\n" " PLX\n" " TXA\n", + 0x97, N, 0); + + _run_this("ASL", " LDA #$80\n ASL\n", 0x00, Z | C, 0); + _run_this("ROR", " LDA #$81\n ROR\n", 0x40, C, 0); + _run_this("ROL Z", " LDA #$80\n ROL\n", 0x00, Z | C, 0); + _run_this("ROL", " LDA #$81\n ROL\n", 0x02, C, 0); + + + _run_this("LDA ($12)", + indirect("", 0x99, 0xFC, "LDA ($12)"), + 0xFC, N, 0); + _run_this("ADC ($12)", + indirect("", 0x7E, 0xAF, "ADC ($12)"), + 0x2D, C, 0); + _run_this("ADC ($12) SED", + indirect("SED", 0x75, 0x25, "ADC ($12)"), + 0x00, V | C | D, 0); + _run_this("AND ($12)", + indirect("", 0x3F, 0xFC, "AND ($12)"), + 0x3C, 0, 0); + _run_this("CMP ($12)", + indirect("", 0xFC, 0x3F, "CMP ($12)"), + 0xFC, C | N, 0); + _run_this("EOR ($12)", + indirect("", 0x3F, 0xFC, "EOR ($12)"), + 0xC3, N, 0); + _run_this("ORA ($12)", + indirect("", 0x0E, 0xFC, "ORA ($12)"), + 0xFE, N, 0); + _run_this("SBC ($12)", + indirect("SEC", 0xFF, 0xC0, "SBC ($12)"), + 0x3F, C, 0); + _run_this("SBC ($12) SED", + indirect("SEC\n SED", 0x75, 0x25, "SBC ($12)"), + 0x50, C | D, 0); + _run_this("STA ($12)", + indirect("", 0xF1, 0xC0, "STA ($12)\n LDA $3001"), + 0xF1, N, 0); + + _run_this("BIT #$F0", + " LDA #$0F\n BIT #$F0\n", + 0x0F, Z , 0); + _run_this("BIT #$80", + " LDA #$0F\n BIT #$80", 0x0F, Z, 0); + _run_this("BIT #$70", + " LDA #$0F\n BIT #$70", + 0x0F, Z, 0); + _run_this("BIT #$FF", + " LDA #$0F\n BIT #$FF", + 0x0F, 0, 0); + _run_this("BIT $12,X", + " LDY #$F0\n" + " STY $14\n" + " LDA #$0F\n" + " LDX #$02\n" + " BIT $12,X\n", + 0x0F, Z | V | N, 0); + _run_this("BIT $1234,X", + " LDY #$F0\n" + " STY $1236\n" + " LDA #$0F\n" + " LDX #$02\n" + " BIT $1234,X\n", + 0x0F, Z | V | N, 0); + _run_this("DEC $xx", + " LDA #$FF\n" + " STA $12\n" + " DEC $12\n" + " LDA $12\n", + 0xFE, N, 0); + _run_this("INC $xxxx", + " LDA #$FF\n" + " STA $3000\n" + " INC $3000\n" + " LDA $3000\n", + 0x00, Z, 0); + + _run_this("LDA ($9d),Y", + " LDX #$90\n" + " STX $90\n" + " LDY #$D\n" + " STZ $91\n" + " LDX #$de\n" + " STX $9D\n" + " LDA ($90),y\n", + 0xde, N, 0); + + _run_this("LDA ($aa,X)", + " LDX #$E9\n" + " LDY #$81\n" + " STY $3104\n" + " LDY #$04\n" + " STY $003A\n" + " LDY #$31\n" + " STY $003B\n" + " LDA ($51,X)\n", + 0x81, N, 0); + _run_this("LDA ($aa),Y", + " LDY #$E9\n" + " LDX #$BB\n" + " STX $403A\n" + " LDX #$51\n" + " STX $00A4\n" + " LDX #$3F\n" + " STX $00A5\n" + " LDA ($A4),Y\n", + 0xBB, N, 0); + _run_this("LDA ($aa)", + " LDX #$AA\n" + " STX $3F51\n" + " LDX #$51\n" + " STX $00A4\n" + " LDX #$3F\n" + " STX $00A5\n" + " LDA ($A4)\n", + 0xAA, N, 0); + + _run_this("SED ADC 0", doSED_ADC(0, 0), 0x0, Z | D, 0); + _run_this("SED ADC 1", doSED_ADC(1, 0), 0x01, D, 0); + _run_this("SED ADC 9", doSED_ADC(9, 0), 0x09, D, 0); + _run_this("SED ADC 10", doSED_ADC(0x10, 0), 0x10, D, 0); + _run_this("SED ADC 1D", doSED_ADC(0x1D, 0), 0x23, D, 0); + _run_this("SED ADC 99", doSED_ADC(0x99, 0), 0x99, N | D, 0); + _run_this("SED ADC 99", doSED_ADC(0x99, 1), 0x00, C | D, 0); + _run_this("SED ADC BD", doSED_ADC(0xBD, 0), 0x23, C | D, 0); +#if 0 +// _run_this("SED ADC FF", doSED_ADC(0xFF, 0), 0x65, C | D | N, 0); + + _run_this("SED ADC 0,1", doSED_ADC(0, 1), 0x01, D, 0); + _run_this("SED ADC 0,9", doSED_ADC(0, 9), 0x09, D, 0); + _run_this("SED ADC 0,10", doSED_ADC(0, 0x10), 0x10, D, 0); + _run_this("SED ADC 0,1D", doSED_ADC(0, 0x1D), 0x23, D, 0); + _run_this("SED ADC 0,99", doSED_ADC(0, 0x99), 0x99, N | D, 0); + _run_this("SED ADC 0,BD", doSED_ADC(0, 0xBD), 0x23, C | D, 0); +// _run_this("SED ADC 0,FF", doSED_ADC(0, 0xFF), 0x65, C | D, 0); + + _run_this("SED ADC 99,1", doSED_ADC(0x99, 1), 0x0, Z | C | D, 0); + _run_this("SED ADC 35,35", doSED_ADC(0x35, 0x35), 0x70, D, 0); + _run_this("SED ADC 45,45", doSED_ADC(0x45, 0x45), 0x90, N | V | D, 0); + _run_this("SED ADC 50,50", doSED_ADC(0x50, 0x50), 0x0, V | Z | C | D, 0); + _run_this("SED ADC 99,99", doSED_ADC(0x99, 0x99), 0x98, N | V | C | D, 0); +// _run_this("SED ADC B1,C1", doSED_ADC(0xB1, 0xC1), 0xD2, N | V | C | D, 0); +#endif + // create an emulator, load the binary file 6502_functional_test.bin at $0000 + // and run it until we hit a BRK + const char *bigtest[] = { + // "test/asm/6502_functional_test.bin", + // "test/asm/65C02_extended_opcodes_test.bin", + NULL, + }; + for (int ti = 0; bigtest[ti]; ti++) { + FILE *f = fopen(bigtest[ti], "r"); + if (!f) { + fprintf(stderr, "Cannot open %s\n", bigtest[ti]); + continue; + } + printf("TEST %s\n", bigtest[ti]); + uint8_t *ram = calloc(1, 0x10000); + fread(ram + 0x000, 1, 0x10000 - 0x400, f); + fclose(f); + mii_cpu_t cpu = {0}; + mii_cpu_state_t s = {0}; + cpu.ram = ram; +// cpu.debug = _run_one_dump_state; + cpu.P.P[B_X] = 1; + cpu.P.P[B_I] = 1; + cpu.S = 0xFF; + cpu.PC = 0x400; + cpu.A = 0x00; + int count = 100000000; + int same_pc_count = 0; + uint16_t prev_pc = 0; + do { + s = mii_cpu_run(&cpu, s); + if (s.w) ram[s.addr] = s.data; + else s.data = ram[s.addr]; + if (s.sync && !s.w) { + if (cpu.PC == prev_pc) { + same_pc_count++; + if (same_pc_count > 3) { + printf("TEST %s: FAIL (stuck at %04X)\n", + bigtest[ti], cpu.PC); + _run_one_dump_state(&cpu, s, NULL); + printf(" Failed instruction is %c%c%c\n", + cpu.A, cpu.X, cpu.Y); + break; + } + } else { + same_pc_count = 0; + prev_pc = cpu.PC; + } + } + // if (s.sync) + _run_one_dump_state(&cpu, s, NULL); + } while (count--); + printf("TEST run with %d spare\n", count); + _run_one_dump_state(&cpu, s, NULL); + if (!count) { + printf("TEST %s: FAIL (out of _run_this cycles!)\n", + bigtest[ti]); + _run_one_dump_state(&cpu, s, NULL); + } + free(ram); + } +} diff --git a/test/mii_test.c b/test/mii_test.c new file mode 100644 index 0000000..9c1193d --- /dev/null +++ b/test/mii_test.c @@ -0,0 +1,61 @@ +/* + * mii_test.c + * + * Copyright (C) 2023 Michel Pollet + * + * SPDX-License-Identifier: MIT + */ +/* + * This is just a small example on how to use mii as a library + */ +#include +#include +#include +#include +#include + +#include "mii.h" +#include "mish.h" + +// so mii_mish_cmd can access the global mii_t +mii_t g_mii; + +void +_mii_mish_bp( + void * param, + int argc, + const char * argv[]); + +int main() +{ + mii_t *mii = &g_mii; + mii_init(mii); + mii_prepare(mii, MII_INIT_DEFAULT); +// int count = 100000; + + mish_prepare(0); + + // add a breakpoint + const char *av[] = {"bp", "+d5fdr", NULL}; + _mii_mish_bp(NULL, 2, av); + do { + if (mii->state != MII_STOPPED) + mii_run(mii); + if (mii->state == MII_STEP) { +// if (mii->trace_cpu) + mii_dump_trace_state(mii); + if (mii->trace.step_inst) + mii->trace.step_inst--; + if (mii->trace.step_inst == 0) + mii->state = MII_STOPPED; + } + if (mii->state != MII_RUNNING) { + // if (!mii->trace_cpu) { + // printf("mii: stopped\n"); + // mii->trace_cpu = 1; + // } + usleep(1000); + } + } while (1); + return 0; +} diff --git a/utils/clangd_gen.sh b/utils/clangd_gen.sh new file mode 100644 index 0000000..49ba734 --- /dev/null +++ b/utils/clangd_gen.sh @@ -0,0 +1,57 @@ +#!/bin/bash +# Generate a JSON file compatible with clangd for indexing. Parses +# the output of the make process, extract gcc lines, and convert to JSON +# using (gnu) AWK +# Join lines that finish by \ -- then split the large command lines around +# && and ||, then look for gcc, then split and look for a .c argument. +# when found, populate the compile_commands.json file +gawk -v dir="$(pwd)" ' +BEGIN { + acc="";line=0; + print "["; +} +END { + print "]"; +} +/\\ *$/ { + $0 = gensub(/\\ *$/, "", "g", $0); + acc = acc $0 + next; +} +/\|\| *$/ { + acc = acc $0 + next; +} +/^g?make\[([0-9]+)]/ { + if ($2 != "Entering") + next; + dir = gensub(/'\''/, "", "g", $4) + next; +} +{ + acc = acc $0 + acc = gensub(/([^\\])"/, "\\1\\\\\"", "g", acc); + acc = gensub(/ +/, " ", "g", acc); + cnt = split(acc, e, / *\|\| *| *&& */); + acc = ""; + for (cmd in e) { + e[cmd] = gensub(/[ |\t]+$/, "", "g", e[cmd]); + split(e[cmd], arg, / +/); + if (!match(arg[1], /g?cc$/)) + continue; + c_file="" + for (ai in arg) { + if (match(arg[ai], /\.c$/)) { + c_file = arg[ai]; + break; + } + } + if (c_file != "") { + if (line > 0) printf ","; + line++; + printf "{\"directory\":\"%s\",\"file\":\"%s\",\"command\":\"%s\"}\n", + dir, c_file, e[cmd]; + } + } +} +'