Add an icon to 32 bit mac build

This commit is contained in:
UnknownShadow200 2020-05-29 23:40:27 +10:00
parent 3ce5b1145a
commit d89d3045c0
4 changed files with 70 additions and 8 deletions

BIN
misc/CCicon_mac32 Normal file

Binary file not shown.

View File

@ -33,7 +33,8 @@ WIN64_CC=x86_64-w64-mingw32-gcc
ALL_FLAGS="-O1 -s -fno-stack-protector -fno-math-errno -Qn -w"
WIN32_FLAGS="-mwindows -nostartfiles -Wl,-e_main_real -DCC_NOMAIN"
WIN64_FLAGS="-mwindows -nostartfiles -Wl,-emain_real -DCC_NOMAIN"
LINUX_FLAGS="-fvisibility=hidden -rdynamic -DCC_BUILD_X11ICON"
LINUX_FLAGS="-fvisibility=hidden -rdynamic -DCC_BUILD_ICON"
MACOS_FLAGS="-fvisibility=hidden -rdynamic -DCC_BUILD_ICON"
# I cloned https://github.com/raspberrypi/tools to get prebuilt cross compilers
# Then I copied across various files/folders from /usr/include and /usr/lib from a real Raspberry pi as needed
@ -72,16 +73,17 @@ build_nix64() {
gcc *.c $ALL_FLAGS $LINUX_FLAGS CCicon_nix64.o -DCC_COMMIT_SHA=\"$LATEST\" -m64 -o cc-nix64 -lX11 -lXi -lpthread -lGL -lm -ldl
}
build_osx32() {
build_mac32() {
echo "Building mac32.."
cp $SOURCE_DIR/misc/CCicon_mac32 $SOURCE_DIR/src/CCicon_mac32.o
rm cc-osx32
$MAC32_CC *.c $ALL_FLAGS -fvisibility=hidden -rdynamic -DCC_COMMIT_SHA=\"$LATEST\" -o cc-osx32 -framework Carbon -framework AGL -framework OpenGL
$MAC32_CC *.c $ALL_FLAGS $MACOS_FLAGS CCicon_mac32.o -DCC_COMMIT_SHA=\"$LATEST\" -o cc-osx32 -framework Carbon -framework AGL -framework OpenGL
}
build_osx64() {
build_mac64() {
echo "Building mac64.."
rm cc-osx64
$MAC64_CC *.c $ALL_FLAGS -fvisibility=hidden -rdynamic -DCC_COMMIT_SHA=\"$LATEST\" -o cc-osx64 -framework Cocoa -framework OpenGL -lobjc
$MAC64_CC *.c $ALL_FLAGS $MACOS_FLAGS -DCC_COMMIT_SHA=\"$LATEST\" -o cc-osx64 -framework Cocoa -framework OpenGL -lobjc
}
build_web() {
@ -116,8 +118,8 @@ build_win32
build_win64
build_nix32
build_nix64
build_osx32
build_osx64
build_mac32
build_mac64
build_web
build_rpi

36
misc/mac_icon_gen.cs Normal file
View File

@ -0,0 +1,36 @@
using System.Drawing.Imaging;
using System.Drawing;
using System.IO;
namespace test {
public static class Program {
const string src = @"H:\PortableApps\GitPortable\App\Git\ClassicalSharp\misc\CCIcon.ico";
const string dst = @"H:\PortableApps\GitPortable\App\Git\ClassicalSharp\misc\CCIcon.c";
static void DumpIcon(StreamWriter sw, int width, int height) {
using (Icon icon = new Icon(src, width, height)) {
using (Bitmap bmp = icon.ToBitmap()) {
for (int y = 0; y < bmp.Height; y++) {
for (int x = 0; x < bmp.Width; x++) {
Color c = bmp.GetPixel(x, y);
int p = (c.B << 24) | (c.G << 16) | (c.R << 8) | c.A;
sw.Write("0x" + ((uint)p).ToString("X8") + ",");
}
sw.WriteLine();
}
}
}
}
public static void Main(string[] args) {
using (StreamWriter sw = new StreamWriter(dst)) {
sw.WriteLine("const unsigned int CCIcon_Data[] = {");
DumpIcon(sw, 64, 64);
sw.WriteLine("};");
sw.WriteLine("const int CCIcon_Width = 64;");
sw.WriteLine("const int CCIcon_Height = 64;");
}
}
}
}

View File

@ -1136,7 +1136,7 @@ void Window_Init(void) {
DisplayInfo.DpiY = 1;
}
#ifdef CC_BUILD_X11ICON
#ifdef CC_BUILD_ICON
static void ApplyIcon(void) {
Atom net_wm_icon = XInternAtom(win_display, "_NET_WM_ICON", false);
Atom xa_cardinal = XInternAtom(win_display, "CARDINAL", false);
@ -2335,6 +2335,29 @@ extern CGContextRef CGWindowContextCreate(CGSConnectionID conn, CGSWindowID win,
static CGSConnectionID conn;
static CGSWindowID winId;
#ifdef CC_BUILD_ICON
static void ApplyIcon(void) {
CGColorSpaceRef colSpace;
CGDataProviderRef provider;
CGImageRef image;
extern const int CCIcon_Data[];
extern const int CCIcon_Width, CCIcon_Height;
colSpace = CGColorSpaceCreateDeviceRGB();
provider = CGDataProviderCreateWithData(NULL, CCIcon_Data,
Bitmap_DataSize(CCIcon_Width, CCIcon_Height), NULL);
image = CGImageCreate(CCIcon_Width, CCIcon_Height, 8, 32, CCIcon_Width * 4, colSpace,
kCGBitmapByteOrder32Little | kCGImageAlphaLast, provider, NULL, 0, 0);
SetApplicationDockTileImage(image);
CGImageRelease(image);
CGDataProviderRelease(provider);
CGColorSpaceRelease(colSpace);
}
#else
static void ApplyIcon(void) { }
#endif
void Window_Create(int width, int height) {
Rect r;
OSStatus res;
@ -2360,6 +2383,7 @@ void Window_Create(int width, int height) {
conn = _CGSDefaultConnection();
winId = GetNativeWindowFromWindowRef(win_handle);
ApplyIcon();
}
void Window_SetTitle(const String* title) {