Skip to content

Set window icon when the emulator is started#91

Closed
blackknight36 wants to merge 1 commit into
commanderx16:masterfrom
blackknight36:add_window_icon
Closed

Set window icon when the emulator is started#91
blackknight36 wants to merge 1 commit into
commanderx16:masterfrom
blackknight36:add_window_icon

Conversation

@blackknight36
Copy link
Copy Markdown

@blackknight36 blackknight36 commented Sep 19, 2019

This window icon is based on the image displayed on the web site. Fixes #90

@mist64
Copy link
Copy Markdown
Collaborator

mist64 commented Sep 19, 2019

Works on Mac, but

  • the file needs to be taken from the directory the executable resides in. main.c already has logic for this.
  • does SDL support loading a PNG instead of a BMP?
  • asterisk with the variable name, not the type, to be consistent with the existing code :P

@FreeFull
Copy link
Copy Markdown

Should the icon maybe be embedded inside the binary, rather than being a separate file?

@blackknight36
Copy link
Copy Markdown
Author

@FreeFull That is possible I just thought it would be easier to store the data in a file. I'll work on making the changes requested tomorrow.

@blackknight36
Copy link
Copy Markdown
Author

It appears that the SDL base library only support bitmaps however there is the SDL_image library which supports other image formats.

http://gigi.nullneuron.net/gigilabs/loading-images-in-sdl2-with-sdl_image for example.

@mist64 I'm not sure if including the image path matters since the data gets compiled into the binary.

@madebr
Copy link
Copy Markdown
Contributor

madebr commented Sep 20, 2019

My 2c:

  • Create a script that generates a header/source file from a file (python?)
  • Add a build rule to the build system
  • Compile and link the generated source
  • Use SDL_LoadBMP_RW to use the file.

@blackknight36
Copy link
Copy Markdown
Author

@madebr I've actually been working on a lua script to export bitmap data as hex values however I haven't quite been able to make it work yet. It's a lot tougher dealing with binary data than I thought. 😄

@madebr
Copy link
Copy Markdown
Contributor

madebr commented Sep 21, 2019

@blackknight36 #64 is adding CMake support to enable building on other platforms such as Windows and finally adding CI for all platforms.
Python is standard available on all these platforms.
I've taken a try at it and code is at this gist.
Use it as ./embed_c.py icon.bmp -o icon.c -p icon.h -n icondata

@blackknight36
Copy link
Copy Markdown
Author

@madebr Thanks, I'll give that a shot. I've almost got my own script working as well, just need to fix a few bugs when dealing with padded bitmap data.

Comment thread video.c Outdated
Comment thread video.c Outdated
@blackknight36 blackknight36 force-pushed the add_window_icon branch 4 times, most recently from 22a53b2 to 8a38a77 Compare September 24, 2019 13:12
@mist64
Copy link
Copy Markdown
Collaborator

mist64 commented Sep 28, 2019

Sorry I haven't commented on this for a while. As I understand the code, it doesn't do any error checking if the file is not found, right?

@blackknight36
Copy link
Copy Markdown
Author

@mist64 That is correct. I can add error checking if needed.

@blackknight36 blackknight36 force-pushed the add_window_icon branch 2 times, most recently from 418c529 to a80a27c Compare October 2, 2019 18:02
@blackknight36
Copy link
Copy Markdown
Author

blackknight36 commented Oct 2, 2019

@madebr I've updated this PR to use SDL_LoadBMP_RW based on the data created by the embed_c.py script. I had to remove the "const" definition to get compilation to succeed. With the const keyword present I get errors as follows.

4:15 $ make
cc -std=c99 -O3 -Wall -Werror -g -I/usr/include/SDL2 -D_REENTRANT -Iextern/include -Iextern/src -c cpu/fake6502.c -o cpu/fake6502.o
cc -std=c99 -O3 -Wall -Werror -g -I/usr/include/SDL2 -D_REENTRANT -Iextern/include -Iextern/src -c memory.c -o memory.o
cc -std=c99 -O3 -Wall -Werror -g -I/usr/include/SDL2 -D_REENTRANT -Iextern/include -Iextern/src -c disasm.c -o disasm.o
cc -std=c99 -O3 -Wall -Werror -g -I/usr/include/SDL2 -D_REENTRANT -Iextern/include -Iextern/src -c video.c -o video.o
video.c: In function ‘video_init’:
video.c:164:2: error: passing argument 1 of ‘SDL_RWFromMem’ discards ‘const’ qualifier from pointer target type [-Werror]
  SDL_RWops *rw = SDL_RWFromMem(icondata, sizeof(icondata));
  ^
In file included from /usr/include/SDL2/SDL_audio.h:36:0,
                 from /usr/include/SDL2/SDL.h:36,
                 from video.h:11,
                 from video.c:9:
/usr/include/SDL2/SDL_rwops.h:164:36: note: expected ‘void *’ but argument is of type ‘const char *’
 extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromMem(void *mem, int size);
                                    ^
cc1: all warnings being treated as errors
make: *** [video.o] Error 1

Copy link
Copy Markdown
Contributor

@madebr madebr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally,
I would put the icon.xcf and icon.bmp in an assets folder.

Comment thread Makefile
Comment thread video.c Outdated
Comment thread tools/embed_c.py Outdated
Comment thread tools/embed_c.py Outdated
Comment thread tools/embed_c.py Outdated
@blackknight36 blackknight36 force-pushed the add_window_icon branch 3 times, most recently from d711dc1 to 6a9593b Compare October 9, 2019 17:10
@blackknight36
Copy link
Copy Markdown
Author

I've removed the icon.xcf file which now lets the build pass.

@mist64
Copy link
Copy Markdown
Collaborator

mist64 commented Oct 11, 2019

Thanks for your work, and sorry this is taking so long. I don't want to have a dependency on Python for the build process, so can you check in the resulting .c/.h files in addition to the script and remove the dependency in the Makefile (just make it an optional target)?

@blackknight36
Copy link
Copy Markdown
Author

@mist64 No problem, I've updated this branch as suggested.

@mist64
Copy link
Copy Markdown
Collaborator

mist64 commented Oct 16, 2019

CI is unhappy because of spaces vs. tabs in icon.c

@blackknight36
Copy link
Copy Markdown
Author

CI is unhappy because of spaces vs. tabs in icon.c

I've updated the script to use tabs instead of spaces. CI checks should work now.

@blackknight36
Copy link
Copy Markdown
Author

This is no longer needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Set window icon on the emulator

5 participants