Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Added page about setIcon and make your own  (Read 10424 times)

0 Members and 1 Guest are viewing this topic.

Cuban-Pete

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
Added page about setIcon and make your own
« on: June 22, 2011, 08:21:19 pm »
On this page: https://github.com/SFML/SFML/wiki/TutorialCreateAndUseSetIcon

Any comments, idea's. Please post them here. Thanks. :)

Oh, I do got myself two comments.

1) The example image and "green loop" are now hosted on my website. This website might not have the eternal life, so perhaps putting them on Github or sfml website might be better.  :)

2) Is it possible to set a 32x32 icon for the taskbar and a 16x16 for the titlebar? Now the 32x32 gets resized, this is not always wanted. For example when the 16x16 looks different as the 32x32.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Added page about setIcon and make your own
« Reply #1 on: June 22, 2011, 10:55:19 pm »
Please please please, read the rules before editing the wiki. At least have a look at other pages names to see what naming conventions must be used.

PS: it's not against you, everybody does this wrong... :cry:
Laurent Gomila - SFML developer

Cuban-Pete

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
Added page about setIcon and make your own
« Reply #2 on: June 23, 2011, 07:41:31 am »
Sorry, I see you already changed it. Thanks.

Question two I see is already answered here: http://www.sfml-dev.org/forum/viewtopic.php?t=1453&sid=68331e3867ad1f26af1fc697439bf23e

Can I adjust the sfml code so that just for windows I can add another icon without breaking the sfml code when compiling on other operating system. Something with #Ifset windows ?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Added page about setIcon and make your own
« Reply #3 on: June 23, 2011, 07:45:23 am »
Quote
Can I adjust the sfml code so that just for windows I can add another icon without breaking the sfml code when compiling on other operating system. Something with #Ifset windows ?

Yes.
Laurent Gomila - SFML developer

JAssange

  • Full Member
  • ***
  • Posts: 104
    • View Profile
Added page about setIcon and make your own
« Reply #4 on: June 23, 2011, 01:15:46 pm »
Why does the tutorial go through the trouble of embedding an icon as an array of values when you can just use Image.GetPixelsPtr()?

Cuban-Pete

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
Added page about setIcon and make your own
« Reply #5 on: June 23, 2011, 01:19:39 pm »
Quote
Why does the tutorial go through the trouble of embedding an icon as an array of values when you can just use Image.GetPixelsPtr()?


I think what you mean is that the icon is as an .png or other format outside the the .exe. I prefer the icon to be "hidden" in the exe. It is not really hidden, they can always get it out, but this looks a bit more professional.

Cuban-Pete

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
Added page about setIcon and make your own
« Reply #6 on: June 26, 2011, 11:15:14 pm »
I got a question about converting an image to a c-source file. Now I just let GIMP do it, but because I want more images to be converted I want to automate it. However I can't figure out how to convert the RGBA value to a unsigned char (in an array) that the compiler accepts.

This is what I figured out by trying. Color value from 0 up to and including 32 are represented with "/number". So for example the color 0 is "/0" or blue color 7 is "/7". But than comes the problem, all the decimal numbers with an 8 or 9 in it are skipped. I think this is because of 8 bit. 0 up to and including 7 makes in total -> 8. Than from 33 up and including 126 is represented with just the ASCII character. So for example the color value 126 is represented as "~", the wave thingy. :) From 127 and up it's again with "/number" and 8 and 9's are avoided.

Now the problem is, how to convert the 0-255 color value to this unsigned char value. I prefer to do this with Python, codes quick for getting such stuff.

Here is an example c code from an image with only 2 pixels. First black (0), second is white (255).

Quote
static const struct {
  unsigned int     width;
  unsigned int     height;
  unsigned int     bytes_per_pixel; /* 3:RGB, 4:RGBA */
  unsigned char    pixel_data[1 * 2 * 4 + 1];
} gimp_image = {
  1, 2, 4,
  "\0\0\0\377\377\377\377\377",
};



The \0 is just zero (black) and the \377 is 255 (white).

Cuban-Pete

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
Added page about setIcon and make your own
« Reply #7 on: June 27, 2011, 01:40:21 pm »
lol, all this trouble, while it was just converting to octal. of course, now that I know it, it makes sense.

For those that want to convert their image to a const unsigned char, like gimp does it. Here is my python code (it uses PIL).

Code: [Select]
"""
Cuban-Pete 2011

- free as beer code snippet
- this code snippet creates from images in the "images" folder one images.c file
- the created file can be loaded in your C(++) program.
- so colors go from decimal to octal format

"""

import os, sys, Image

lol = ''
f = open('images.c', 'w') #global set file. overwriting is 'on'

def run_colors_and_print(image_location, image_name ):
    image = Image.open(image_location) #open image
    pix = image.load() #put info in pix
    width = image.size[0]
    height = image.size[1]
    lol = '' #reset global! string, important
    ten_count = 0
    startbool = True #remove unneeded extra double quotes at start
   
    for y in range(0,height):
        for x in range(0,width):

            if ten_count == 0:
                if startbool == True:
                    lol = lol + "\n\t\""
                    startbool = False
                else:
                    lol = lol + "\"\n\t\""

            # putting in the RGBA.
            temp = "\%o\%o\%o\%o" % (pix[x,y][0], pix[x,y][1], pix[x,y][2], pix[x,y][-1]);
            lol = lol + temp
           
            ten_count += 1
            if ten_count == 10: #make lines as long as this value...
                ten_count = 0
           
    f.write("static const struct {")
    f.write("\n\t unsigned int \t width;")
    f.write("\n\t unsigned int \t height;")
    f.write("\n\t unsigned int \t bytes_per_pixel;")
    f.write("\n\t unsigned char \t pixel_data[%i * %i * 4 + 1];" % (width, height) )
    #the image name is made here (currently set on "normal_" and followed by image file name
    f.write("\n} normal_%s = {" % (image_name[ 0: len(image_name)-4 ]) ) #remove the ".png" tag and backslash
    f.write("\n\t%i, %i, 4," % (width, height) )
    f.write("%s\"," % (lol) ) #the pixel data written
    f.write("\n};")

    print "done %s" % (image_name)
   

## loop in the "images" folder to get all images
image_folder = "images/"
for subdir, dirs, files in os.walk(image_folder):
    for file in files:
        run_colors_and_print(image_folder+file, file)
        f.write("\n\n")


f.close() #important!


##Ouput example below for a 2x2 image in all white:
   
##static const struct {
##  unsigned int width;
##  unsigned int height;
##  unsigned int bytes_per_pixel;
##  unsigned char pixel_data[2 * 2 * 4 + 1];
##} gimp_image = {
##  2, 2, 4,
##  "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377",
##};



Cuban-Pete

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
Added page about setIcon and make your own
« Reply #8 on: June 28, 2011, 06:25:56 pm »
Quote from: "Cuban-Pete"
Can I adjust the sfml code so that just for windows I can add another icon without breaking the sfml code when compiling on other operating system. Something with #Ifset windows ?


I tried that, but it does not work.

These lines are important I think:
Code: [Select]

        SendMessage(myHandle, WM_SETICON, ICON_BIG,   (LPARAM)myIcon);
        SendMessage(myHandle, WM_SETICON, ICON_SMALL, (LPARAM)myIcon);


I tried disabling one, that did not have any effect. I made copy of the function (every where it is used also virtual). One with the same name and one with Large after the name. I called them both in my program, but it has no effect. Also, the program got very unresponsive on the taskbar, very weird.

This also brings me to a different problem. With the basic sfml 2.0 code (so no adjustments) the time it takes after starting the program and showing up on the windows 7 taskbar is sometimes longer than 3 seconds. The program is started, I see the window, but it takes pretty long before it displays itself on the taskbar. How is this possible? On my vista PC it shows up directly on the taskbar.

Cuban-Pete

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
Added page about setIcon and make your own
« Reply #9 on: June 29, 2011, 12:32:28 pm »
Quote
I tried disabling one, that did not have any effect. I made copy of the function (every where it is used also virtual). One with the same name and one with Large after the name. I called them both in my program, but it has no effect. Also, the program got very unresponsive on the taskbar, very weird.

This also brings me to a different problem. With the basic sfml 2.0 code (so no adjustments) the time it takes after starting the program and showing up on the windows 7 taskbar is sometimes longer than 3 seconds. The program is started, I see the window, but it takes pretty long before it displays itself on the taskbar. How is this possible? On my vista PC it shows up directly on the taskbar.


Nobody has this long wait time before the program shows on the taskbar? Or am I the only one with win7 (64bit)?