Difference between revisions of "How to Add Characters and Icons to the Font"

From The Powder Toy
Jump to: navigation, search
(Text formating and fixed some of my bad grammer)
(Edit the guide with updated instructions)
(16 intermediate revisions by 7 users not shown)
Line 1: Line 1:
==''' Adding an Icon to menus''' ==
+
Defines for the menu sections are located in simulation/SimulationData.h. The names and icons are in LoadMenus() in simulation/SimulationData.cpp. These are what you need to edit to create a new menu.
  
 +
If you downloaded the source from Github, then you'll find a folder called font. If you look inside it, you'll see that there is packer.c, unpacker.c and editor.c. The instructions for Windows and Linux are different, so be sure to follow the correct instructions.
  
If you downloaded the source from github you would have a folder called font if you look in side you will see that there is packer.c, unpacker.c and editor.c, if you don't see it then you either downloaded the source code off the website powdertoy.co.uk or you deleted it somehow, if this is the case re-download it from here [https://github.com/FacialTurd/The-Powder-Toy The-Powder-Toy]  
+
== Windows ==
 +
'''0)''' You will need GNU Make for the next step. You can download GNU Make from here: [https://www.gnu.org/software/make]
  
'''1)''' copy font.h from /includes and paste it into /font.
+
'''1)''' Get a copy of the source.
  
'''2)''' compile the editor, unpacker and packer i am not sure how one would do this on windows but on linux it would just be make editor unpacker packer
+
'''2)''' Copy font.h from /data in the source and and paste it into /font
  
'''3)''' open cmd prompt/terminal and change the directory to /The-Powder-Toy and run
+
'''3)''' Navigate into /font, and open a Command Prompt here. Compile the font editor tools using the following commands:
linux: ./unpacker >> font.bin
+
<syntaxhighlight lang="bash">
windows: not sure it might be similar to linux
+
make unpacker.exe packer.exe editor.exe
 +
</syntaxhighlight>
 +
Alternatively, just download a premade one [https://github.com/downloads/jacob1/The-Powder-Toy/fontexes.zip here], with the added feature of showing the hex id as you edit.
  
'''4)''' you would now have a file called font.bin it is a file that /font that is what is needed to run the editor with the current icons tpt use.  
+
'''4)''' In the same terminal run the following command to create a font.bin file the editor can read:
 +
<syntaxhighlight lang="bash">
 +
unpacker.exe
 +
</syntaxhighlight>
  
'''5)''' run the editor via cmd/terminal and then press space/backspace to find an empty character, it may be a thermometer if it is just erase it via right clicking and left clicking in the drawing field. now draw you character and look in cmd/terminal and the last number you will see there is the char id and it corresponds to what icon you drew.
+
'''5)''' Run the editor from the terminal, and then use the "+" and "-" keys to go the end and find an empty character. Empty characters look like thermometers, although be careful not to confuse it with the actual thermometer. If it is just erase it via right clicking and left clicking in the drawing field. It will take a lot of pressing "+" to get to the end. Now draw your character. Look in the stdout.txt file in the same directory, and the last number in the file is the char id that corresponds to whatever icon you drew Remember the char id. If you used the precompiled one, you should have seen this number when editing instead.
  
'''6)''' close down the editor and delete the font.h then run:
+
'''6)''' Close down the editor and run:
linux: ./packer >> font.h
+
<syntaxhighlight lang="bash">
windows : not sure
+
packer.exe > font.h
 +
</syntaxhighlight>
  
'''7)''' copy the new font.h into /includes replacing the old one.
+
Only use steps 7 and 8 if you downloaded the precompiled version (it's a bit out of date some icons will show different)
  
'''8)''' for your new menu set the char id to what i told you to remember before.
+
'''7)''' Rename stdout.txt to font.h
etc: {"\xFF", "new menu ftw", 0, 1},
 
FF is the char id.  
 
  
'''9)''' recompile and you should be ready to go.
+
'''8)''' Open font.h, at the top of the file you should see something like this
 +
<syntaxhighlight lang="c">
 +
#ifndef FONT_H_CHECK
 +
#define FONT_H_CHECK
 +
#define FONT_H 10
 +
#ifdef INCLUDE_FONTDATA
 +
char font_data[] = {
 +
</syntaxhighlight>
 +
 
 +
Replace
 +
<syntaxhighlight lang="c">
 +
char font_data[] = {
 +
</syntaxhighlight>
 +
With
 +
<syntaxhighlight lang="c">
 +
unsigned char font_data[] = {
 +
</syntaxhighlight>
 +
Go to the bottom of the file and you should see something like this
 +
<syntaxhighlight lang="c">
 +
};
 +
#endif
 +
#endif
 +
</syntaxhighlight>
 +
Change it to this
 +
<syntaxhighlight lang="c">
 +
};
 +
#else
 +
extern unsigned char font_data[];
 +
extern short font_ptrs[];
 +
#endif
 +
#endif
 +
</syntaxhighlight>
 +
 
 +
Or otherwise when you compile "The Powder Toy" you will get errors with the Graphics.cpp
 +
 
 +
'''9)''' Copy the font.h into /data, replacing the old one.
 +
 
 +
'''10)''' For your new menu, replace FF with the char id you remembered from step 5.
 +
<syntaxhighlight lang="c">
 +
{"\xFF", "new menu ftw", 0, 1},
 +
</syntaxhighlight>
 +
 
 +
'''11)''' Recompile The Powder Toy and you should be ready to go.
 +
 
 +
== Linux ==
 +
'''1)''' Open a Terminal and ''cd'' to the /font directory that's included with the Git source code.
 +
 
 +
'''2)''' Enter the following commands to copy font.h from includes to font and compile the font editor tools:
 +
<syntaxhighlight lang="bash">
 +
cp ../includes/font.h .
 +
make unpacker packer editor
 +
</syntaxhighlight>
 +
 
 +
'''3)''' In the same terminal run the following command to create a font.bin file the editor can read:
 +
<syntaxhighlight lang="bash">
 +
./unpacker > output1.txt
 +
</syntaxhighlight>
 +
 
 +
'''5)''' Run the editor from the terminal and then use the "+" and "-" keys to go the end and find an empty character. Empty characters look like thermometers, although be careful not to confuse it with the actual thermometer. If it is just erase it via right clicking and left clicking in the drawing field. It will take a lot of pressing "+" to get to the end. Now draw your character. and look in output1.txt, and the last number there is the char id and it corresponds to what icon you drew.
 +
 
 +
'''6)''' close down the editor and run:
 +
<syntaxhighlight lang="bash">
 +
rm ./font.h
 +
./packer > font.h
 +
cp -f ./font.h ../includes
 +
</syntaxhighlight>
 +
 
 +
'''8)''' for your new menu, replace FF with the last number from the output1.txt file in the font directory.
 +
<syntaxhighlight lang="c">
 +
{"\xFF", "new menu ftw", 0, 1},
 +
</syntaxhighlight>
 +
 
 +
'''9)''' Recompile The Powder Toy and you should be ready to go.
 +
 
 +
[[Category:Development]]

Revision as of 14:16, 4 April 2018

Defines for the menu sections are located in simulation/SimulationData.h. The names and icons are in LoadMenus() in simulation/SimulationData.cpp. These are what you need to edit to create a new menu.

If you downloaded the source from Github, then you'll find a folder called font. If you look inside it, you'll see that there is packer.c, unpacker.c and editor.c. The instructions for Windows and Linux are different, so be sure to follow the correct instructions.

Windows

0) You will need GNU Make for the next step. You can download GNU Make from here: [1]

1) Get a copy of the source.

2) Copy font.h from /data in the source and and paste it into /font

3) Navigate into /font, and open a Command Prompt here. Compile the font editor tools using the following commands:

make unpacker.exe packer.exe editor.exe

Alternatively, just download a premade one here, with the added feature of showing the hex id as you edit.

4) In the same terminal run the following command to create a font.bin file the editor can read:

unpacker.exe

5) Run the editor from the terminal, and then use the "+" and "-" keys to go the end and find an empty character. Empty characters look like thermometers, although be careful not to confuse it with the actual thermometer. If it is just erase it via right clicking and left clicking in the drawing field. It will take a lot of pressing "+" to get to the end. Now draw your character. Look in the stdout.txt file in the same directory, and the last number in the file is the char id that corresponds to whatever icon you drew Remember the char id. If you used the precompiled one, you should have seen this number when editing instead.

6) Close down the editor and run:

packer.exe > font.h

Only use steps 7 and 8 if you downloaded the precompiled version (it's a bit out of date some icons will show different)

7) Rename stdout.txt to font.h

8) Open font.h, at the top of the file you should see something like this

#ifndef FONT_H_CHECK
#define FONT_H_CHECK
#define FONT_H 10
#ifdef INCLUDE_FONTDATA
char font_data[] = {

Replace

char font_data[] = {

With

unsigned char font_data[] = {

Go to the bottom of the file and you should see something like this

};
#endif
#endif

Change it to this

};
#else
extern unsigned char font_data[];
extern short font_ptrs[];
#endif
#endif

Or otherwise when you compile "The Powder Toy" you will get errors with the Graphics.cpp

9) Copy the font.h into /data, replacing the old one.

10) For your new menu, replace FF with the char id you remembered from step 5.

{"\xFF", "new menu ftw", 0, 1},

11) Recompile The Powder Toy and you should be ready to go.

Linux

1) Open a Terminal and cd to the /font directory that's included with the Git source code.

2) Enter the following commands to copy font.h from includes to font and compile the font editor tools:

cp ../includes/font.h .
make unpacker packer editor

3) In the same terminal run the following command to create a font.bin file the editor can read:

./unpacker > output1.txt

5) Run the editor from the terminal and then use the "+" and "-" keys to go the end and find an empty character. Empty characters look like thermometers, although be careful not to confuse it with the actual thermometer. If it is just erase it via right clicking and left clicking in the drawing field. It will take a lot of pressing "+" to get to the end. Now draw your character. and look in output1.txt, and the last number there is the char id and it corresponds to what icon you drew.

6) close down the editor and run:

rm ./font.h
./packer > font.h
cp -f ./font.h ../includes

8) for your new menu, replace FF with the last number from the output1.txt file in the font directory.

{"\xFF", "new menu ftw", 0, 1},

9) Recompile The Powder Toy and you should be ready to go.