diff --git a/windows/_rc2bin/build.bat b/windows/_rc2bin/build.bat new file mode 100644 index 00000000..5aaccf4c --- /dev/null +++ b/windows/_rc2bin/build.bat @@ -0,0 +1,10 @@ +@rem 2 may 2018 +@echo off + +cl /nologo /TP /GR /EHsc /MDd /Ob0 /Od /RTC1 /W4 /wd4100 /bigobj /RTC1 /RTCs /RTCu /FS -c main.cpp +if errorlevel 1 goto out +rc -foresources.res resources.rc +if errorlevel 1 goto out +link /nologo main.obj resources.res /out:main.exe /LARGEADDRESSAWARE /NOLOGO /INCREMENTAL:NO /MANIFEST:NO /debug user32.lib kernel32.lib gdi32.lib comctl32.lib uxtheme.lib msimg32.lib comdlg32.lib d2d1.lib dwrite.lib ole32.lib oleaut32.lib oleacc.lib uuid.lib + +:out diff --git a/windows/_rc2bin/libui.manifest b/windows/_rc2bin/libui.manifest new file mode 100644 index 00000000..8beb6cfc --- /dev/null +++ b/windows/_rc2bin/libui.manifest @@ -0,0 +1,31 @@ + + + +Your application description here. + + + + + + + + + + + + + + + diff --git a/windows/_rc2bin/main.cpp b/windows/_rc2bin/main.cpp new file mode 100644 index 00000000..3f929719 --- /dev/null +++ b/windows/_rc2bin/main.cpp @@ -0,0 +1,67 @@ +// 2 may 2018 +#include "winapi.h" +#include +#include +#include "resources.h" + +void die(const char *f, const char *constname) +{ + DWORD le; + + le = GetLastError(); + fprintf(stderr, "error calling %s for %s: %I32d\n", f, constname, le); + exit(1); +} + +void dumpResource(const char *constname, const WCHAR *name, const WCHAR *type) +{ + HRSRC hrsrc; + HGLOBAL res; + uint8_t *b, *bp; + DWORD i, n; + DWORD j; + + hrsrc = FindResourceW(NULL, name, type); + if (hrsrc == NULL) + die("FindResourceW()", constname); + n = SizeofResource(NULL, hrsrc); + if (n == 0) + die("SizeofResource()", constname); + res = LoadResource(NULL, hrsrc); + if (res == NULL) + die("LoadResource()", constname); + b = (uint8_t *) LockResource(res); + if (b == NULL) + die("LockResource()", constname); + + printf("static const uint8_t %s[] = {\n", constname); + bp = b; + j = 0; + for (i = 0; i < n; i++) { + if (j == 0) + printf("\t"); + printf("0x%02I32X,", (uint32_t) (*bp)); + bp++; + if (j == 15) { + printf("\n"); + j = 0; + } else { + printf(" "); + j++; + } + } + if (j != 0) + printf("\n"); + printf("};\n"); + printf("static_assert(ARRAYSIZE(%s) == %I32d, \"wrong size for resource %s\")\n", constname, n, constname); + printf("\n"); +} + +int main(void) +{ +#define d(c, t) dumpResource(#c, MAKEINTRESOURCEW(c), t) + d(rcTabPageDialog, RT_DIALOG); + d(rcFontDialog, RT_DIALOG); + d(rcColorDialog, RT_DIALOG); + return 0; +} diff --git a/windows/_rc2bin/resources.hpp b/windows/_rc2bin/resources.hpp new file mode 100644 index 00000000..4ae54725 --- /dev/null +++ b/windows/_rc2bin/resources.hpp @@ -0,0 +1,37 @@ +// 30 may 2015 + +#define rcTabPageDialog 29000 +#define rcFontDialog 29001 +#define rcColorDialog 29002 + +// TODO normalize these + +#define rcFontFamilyCombobox 1000 +#define rcFontStyleCombobox 1001 +#define rcFontSizeCombobox 1002 +#define rcFontSamplePlacement 1003 + +#define rcColorSVChooser 1100 +#define rcColorHSlider 1101 +#define rcPreview 1102 +#define rcOpacitySlider 1103 +#define rcH 1104 +#define rcS 1105 +#define rcV 1106 +#define rcRDouble 1107 +#define rcRInt 1108 +#define rcGDouble 1109 +#define rcGInt 1110 +#define rcBDouble 1111 +#define rcBInt 1112 +#define rcADouble 1113 +#define rcAInt 1114 +#define rcHex 1115 +#define rcHLabel 1116 +#define rcSLabel 1117 +#define rcVLabel 1118 +#define rcRLabel 1119 +#define rcGLabel 1120 +#define rcBLabel 1121 +#define rcALabel 1122 +#define rcHexLabel 1123 diff --git a/windows/_rc2bin/resources.rc b/windows/_rc2bin/resources.rc new file mode 100644 index 00000000..989dfc91 --- /dev/null +++ b/windows/_rc2bin/resources.rc @@ -0,0 +1,96 @@ +// 30 may 2015 +#include "winapi.hpp" +#include "resources.hpp" + +// this is a UTF-8 file +#pragma code_page(65001) + +// this is the Common Controls 6 manifest +// we only define it in a shared build; static builds have to include the appropriate parts of the manifest in the output executable +// LONGTERM set up the string values here +#ifndef _UI_STATIC +ISOLATIONAWARE_MANIFEST_RESOURCE_ID RT_MANIFEST "libui.manifest" +#endif + +// this is the dialog template used by tab pages; see windows/tabpage.c for details +rcTabPageDialog DIALOGEX 0, 0, 100, 100 +STYLE DS_CONTROL | WS_CHILD | WS_VISIBLE +EXSTYLE WS_EX_CONTROLPARENT +BEGIN + // nothing +END + +// this is for our custom DirectWrite-based font dialog (see fontdialog.cpp) +// this is based on the "New Font Dialog with Syslink" in Microsoft's font.dlg +// LONGTERM look at localization +// LONGTERM make it look tighter and nicer like the real one, including the actual heights of the font family and style comboboxes +rcFontDialog DIALOGEX 13, 54, 243, 200 +STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU | DS_3DLOOK +CAPTION "Font" +FONT 9, "Segoe UI" +BEGIN + LTEXT "&Font:", -1, 7, 7, 98, 9 + COMBOBOX rcFontFamilyCombobox, 7, 16, 98, 76, + CBS_SIMPLE | CBS_AUTOHSCROLL | CBS_DISABLENOSCROLL | + CBS_SORT | WS_VSCROLL | WS_TABSTOP | CBS_HASSTRINGS + + LTEXT "Font st&yle:", -1, 114, 7, 74, 9 + COMBOBOX rcFontStyleCombobox, 114, 16, 74, 76, + CBS_SIMPLE | CBS_AUTOHSCROLL | CBS_DISABLENOSCROLL | + WS_VSCROLL | WS_TABSTOP | CBS_HASSTRINGS + + LTEXT "&Size:", -1, 198, 7, 36, 9 + COMBOBOX rcFontSizeCombobox, 198, 16, 36, 76, + CBS_SIMPLE | CBS_AUTOHSCROLL | CBS_DISABLENOSCROLL | + CBS_SORT | WS_VSCROLL | WS_TABSTOP | CBS_HASSTRINGS + + GROUPBOX "Sample", -1, 7, 97, 227, 70, WS_GROUP + CTEXT "AaBbYyZz", rcFontSamplePlacement, 9, 106, 224, 60, SS_NOPREFIX | NOT WS_VISIBLE + + DEFPUSHBUTTON "OK", IDOK, 141, 181, 45, 14, WS_GROUP + PUSHBUTTON "Cancel", IDCANCEL, 190, 181, 45, 14, WS_GROUP +END + +rcColorDialog DIALOGEX 13, 54, 344, 209 +STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU | DS_3DLOOK +CAPTION "Color" +FONT 9, "Segoe UI" +BEGIN + // this size should be big enough to get at least 256x256 on font sizes >= 8 pt + CTEXT "AaBbYyZz", rcColorSVChooser, 7, 7, 195, 195, SS_NOPREFIX | SS_BLACKRECT + + // width is the suggested slider height since this is vertical + CTEXT "AaBbYyZz", rcColorHSlider, 206, 7, 15, 195, SS_NOPREFIX | SS_BLACKRECT + + LTEXT "Preview:", -1, 230, 7, 107, 9, SS_NOPREFIX + CTEXT "AaBbYyZz", rcPreview, 230, 16, 107, 20, SS_NOPREFIX | SS_BLACKRECT + + LTEXT "Opacity:", -1, 230, 45, 107, 9, SS_NOPREFIX + CTEXT "AaBbYyZz", rcOpacitySlider, 230, 54, 107, 15, SS_NOPREFIX | SS_BLACKRECT + + LTEXT "&H:", rcHLabel, 230, 81, 8, 8 + EDITTEXT rcH, 238, 78, 30, 14, ES_LEFT | ES_AUTOHSCROLL | WS_TABSTOP, WS_EX_CLIENTEDGE + LTEXT "&S:", rcSLabel, 230, 95, 8, 8 + EDITTEXT rcS, 238, 92, 30, 14, ES_LEFT | ES_AUTOHSCROLL | WS_TABSTOP, WS_EX_CLIENTEDGE + LTEXT "&V:", rcVLabel, 230, 109, 8, 8 + EDITTEXT rcV, 238, 106, 30, 14, ES_LEFT | ES_AUTOHSCROLL | WS_TABSTOP, WS_EX_CLIENTEDGE + + LTEXT "&R:", rcRLabel, 277, 81, 8, 8 + EDITTEXT rcRDouble, 285, 78, 30, 14, ES_LEFT | ES_AUTOHSCROLL | WS_TABSTOP, WS_EX_CLIENTEDGE + EDITTEXT rcRInt, 315, 78, 20, 14, ES_LEFT | ES_AUTOHSCROLL | ES_NUMBER | WS_TABSTOP, WS_EX_CLIENTEDGE + LTEXT "&G:", rcGLabel, 277, 95, 8, 8 + EDITTEXT rcGDouble, 285, 92, 30, 14, ES_LEFT | ES_AUTOHSCROLL | WS_TABSTOP, WS_EX_CLIENTEDGE + EDITTEXT rcGInt, 315, 92, 20, 14, ES_LEFT | ES_AUTOHSCROLL | ES_NUMBER | WS_TABSTOP, WS_EX_CLIENTEDGE + LTEXT "&B:", rcBLabel, 277, 109, 8, 8 + EDITTEXT rcBDouble, 285, 106, 30, 14, ES_LEFT | ES_AUTOHSCROLL | WS_TABSTOP, WS_EX_CLIENTEDGE + EDITTEXT rcBInt, 315, 106, 20, 14, ES_LEFT | ES_AUTOHSCROLL | ES_NUMBER | WS_TABSTOP, WS_EX_CLIENTEDGE + LTEXT "&A:", rcALabel, 277, 123, 8, 8 + EDITTEXT rcADouble, 285, 120, 30, 14, ES_LEFT | ES_AUTOHSCROLL | WS_TABSTOP, WS_EX_CLIENTEDGE + EDITTEXT rcAInt, 315, 120, 20, 14, ES_LEFT | ES_AUTOHSCROLL | ES_NUMBER | WS_TABSTOP, WS_EX_CLIENTEDGE + + LTEXT "He&x:", rcHexLabel, 269, 146, 16, 8 + EDITTEXT rcHex, 285, 143, 50, 14, ES_LEFT | ES_AUTOHSCROLL | WS_TABSTOP, WS_EX_CLIENTEDGE + + DEFPUSHBUTTON "OK", IDOK, 243, 188, 45, 14, WS_GROUP + PUSHBUTTON "Cancel", IDCANCEL, 292, 188, 45, 14, WS_GROUP +END diff --git a/windows/_rc2bin/winapi.hpp b/windows/_rc2bin/winapi.hpp new file mode 100644 index 00000000..4f24f607 --- /dev/null +++ b/windows/_rc2bin/winapi.hpp @@ -0,0 +1,60 @@ +// 31 may 2015 +#define UNICODE +#define _UNICODE +#define STRICT +#define STRICT_TYPED_ITEMIDS + +// see https://github.com/golang/go/issues/9916#issuecomment-74812211 +// TODO get rid of this +#define INITGUID + +// for the manifest +#ifndef _UI_STATIC +#define ISOLATION_AWARE_ENABLED 1 +#endif + +// get Windows version right; right now Windows Vista +// unless otherwise stated, all values from Microsoft's sdkddkver.h +// TODO is all of this necessary? how is NTDDI_VERSION used? +// TODO plaform update sp2 +#define WINVER 0x0600 /* from Microsoft's winnls.h */ +#define _WIN32_WINNT 0x0600 +#define _WIN32_WINDOWS 0x0600 /* from Microsoft's pdh.h */ +#define _WIN32_IE 0x0700 +#define NTDDI_VERSION 0x06000000 + +// The MinGW-w64 header has an unverified IDWriteTypography definition. +// TODO I can confirm this myself, but I don't know how long it will take for them to note my adjustments... Either way, I have to confirm this myself. +// TODO change the check from _MSC_VER to a MinGW-w64-specific check +// TODO keep track of what else is guarded by this +#ifndef _MSC_VER +#define __MINGW_USE_BROKEN_INTERFACE +#endif + +#include + +// Microsoft's resource compiler will segfault if we feed it headers it was not designed to handle +#ifndef RC_INVOKED +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#endif