How to make a CgIcon from code

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

How to make a CgIcon from code

Louis LaBrunda
Hi Guys,

As some of you may know I am working on an inspector window that I can package with a GUI program, because sometimes (at least in one of my programs) I want to see everything in an object (that contains status information about other NT service programs) without having to build screens to display it all.  This is going very well and when I'm finished I intend to put it on the Smalltalk Goodies site.  Since it is a window and the window needs/wants an icon for the upper left hand corner, I want to supply one.  But I don't want to deal with trying to supply it from outside the two objects that are in the app I want to post to Smalltalk Goodies.  To avoid an external icon or a DLL with the icon in it, I want to create the icon from code.

This isn't too had but remembering how to do it is a PITA.  So, I have created an instance side extension to CgIcon (attached and shown below) that when called will compile the code to create the icon in the class and method named.  The extension should live in an "edit" app as it shouldn't get packaged.

You use the method by selecting the open app that houses the class you want to compile the code to and then creating an instance of the CgIcon desired with some workspace code like so:

| icon |
icon := CgIcon fromResource: 685 fileName: 'kscicons.dll'.
icon compileSourceInClass: KscInspectWindow inMethod: #windowIcon.


It will build the icon from the named DLL and resource number.  It then tells the CgIcon to compile its matching code for you in the named class and method.

Now I don't have to remember so much.  Instantiations should feel free to add this extension to an edit app if they like.

Lou


compileSourceInClass: aClass inMethod: aMethodName
"Compile source code that will create this icon (or at least one that looks like it) as a class method in the names class."
"Where aClass is a class and aMethodName is the method name as a string."
"To properly use this method, have the app that owns the class open, create an instance of CgIcon (in a workspace) and send it this message."
| stream |

self maskImage. "Fill in the icon data."

stream := WriteStream on: (String new: 5000).

stream
nextPutAll: aMethodName asString; cr;
tab; nextPutAll: '"Answer an instance of CgIcon."'; cr;
tab; nextPutAll: '| icon palette paletteBytes maskData shapeData |'; cr; cr.

stream tab; nextPutAll: 'maskData := #['.
maskData do: [:i | i printOn: stream] separatedBy: [stream space].
stream nextPutAll: '].'; cr; cr.

stream tab; nextPutAll: 'shapeData := #['.
shapeData do: [:i | i printOn: stream] separatedBy: [stream space].
stream nextPutAll: '].'; cr; cr.

stream tab; nextPutAll: 'paletteBytes := #['.
palette byteRepresentation do: [:i | i printOn: stream] separatedBy: [stream space].
stream nextPutAll: '].'; cr; cr.

stream
tab; nextPutAll: 'palette := CgIndexedPalette new.'; cr;
tab; nextPutAll: 'palette byteRepresentation: paletteBytes; size: '; nextPutAll: palette size printString.
stream nextPut: $.; cr; cr.

stream
tab; nextPutAll: 'icon := CgIcon'; cr;
tab; tab; nextPutAll: 'width: '; nextPutAll: width printString; cr;
tab; tab; nextPutAll: 'height: '; nextPutAll: height printString; cr;
tab; tab; nextPutAll: 'depth: '; nextPutAll: depth printString; cr;
tab; tab; nextPutAll: 'palette: palette'; cr;
tab; tab; nextPutAll: 'shapePad: '; nextPutAll: shapePad printString; cr;
tab; tab; nextPutAll: 'shapeData: shapeData'; cr;
tab; tab; nextPutAll: 'maskPad: '; nextPutAll: maskPad printString; cr;
tab; tab; nextPutAll: 'maskData: maskData.'; cr; cr.

stream tab; nextPutAll: '^icon.'; cr.

^aClass class compile: stream contents.



--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/d/optout.

CgIcon.st (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: How to make a CgIcon from code

dmacq
Hi Lou,

You may or may not already know this, but....

StsImageManager class stores many icons used in the browsers as byteArrays.  You could do the same for your inspector window and then you would not have to rely on anything external.  I have some scripts around that will create the byteArrays from icons that I can dig up if you are interested.

hth,

Donald [|]

On Friday, March 20, 2015 at 12:28:04 PM UTC-4, Louis LaBrunda wrote:
Hi Guys,

As some of you may know I am working on an inspector window that I can package with a GUI program, because sometimes (at least in one of my programs) I want to see everything in an object (that contains status information about other NT service programs) without having to build screens to display it all.  This is going very well and when I'm finished I intend to put it on the Smalltalk Goodies site.  Since it is a window and the window needs/wants an icon for the upper left hand corner, I want to supply one.  But I don't want to deal with trying to supply it from outside the two objects that are in the app I want to post to Smalltalk Goodies.  To avoid an external icon or a DLL with the icon in it, I want to create the icon from code.

This isn't too had but remembering how to do it is a PITA.  So, I have created an instance side extension to CgIcon (attached and shown below) that when called will compile the code to create the icon in the class and method named.  The extension should live in an "edit" app as it shouldn't get packaged.

You use the method by selecting the open app that houses the class you want to compile the code to and then creating an instance of the CgIcon desired with some workspace code like so:

| icon |
icon := CgIcon fromResource: 685 fileName: 'kscicons.dll'.
icon compileSourceInClass: KscInspectWindow inMethod: #windowIcon.


It will build the icon from the named DLL and resource number.  It then tells the CgIcon to compile its matching code for you in the named class and method.

Now I don't have to remember so much.  Instantiations should feel free to add this extension to an edit app if they like.

Lou


compileSourceInClass: aClass inMethod: aMethodName
"Compile source code that will create this icon (or at least one that looks like it) as a class method in the names class."
"Where aClass is a class and aMethodName is the method name as a string."
"To properly use this method, have the app that owns the class open, create an instance of CgIcon (in a workspace) and send it this message."
| stream |

self maskImage. "Fill in the icon data."

stream := WriteStream on: (String new: 5000).

stream
nextPutAll: aMethodName asString; cr;
tab; nextPutAll: '"Answer an instance of CgIcon."'; cr;
tab; nextPutAll: '| icon palette paletteBytes maskData shapeData |'; cr; cr.

stream tab; nextPutAll: 'maskData := #['.
maskData do: [:i | i printOn: stream] separatedBy: [stream space].
stream nextPutAll: '].'; cr; cr.

stream tab; nextPutAll: 'shapeData := #['.
shapeData do: [:i | i printOn: stream] separatedBy: [stream space].
stream nextPutAll: '].'; cr; cr.

stream tab; nextPutAll: 'paletteBytes := #['.
palette byteRepresentation do: [:i | i printOn: stream] separatedBy: [stream space].
stream nextPutAll: '].'; cr; cr.

stream
tab; nextPutAll: 'palette := CgIndexedPalette new.'; cr;
tab; nextPutAll: 'palette byteRepresentation: paletteBytes; size: '; nextPutAll: palette size printString.
stream nextPut: $.; cr; cr.

stream
tab; nextPutAll: 'icon := CgIcon'; cr;
tab; tab; nextPutAll: 'width: '; nextPutAll: width printString; cr;
tab; tab; nextPutAll: 'height: '; nextPutAll: height printString; cr;
tab; tab; nextPutAll: 'depth: '; nextPutAll: depth printString; cr;
tab; tab; nextPutAll: 'palette: palette'; cr;
tab; tab; nextPutAll: 'shapePad: '; nextPutAll: shapePad printString; cr;
tab; tab; nextPutAll: 'shapeData: shapeData'; cr;
tab; tab; nextPutAll: 'maskPad: '; nextPutAll: maskPad printString; cr;
tab; tab; nextPutAll: 'maskData: maskData.'; cr; cr.

stream tab; nextPutAll: '^icon.'; cr.

^aClass class compile: stream contents.



--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to make a CgIcon from code

Louis LaBrunda
Hi Donald,

I didn't know that.  I will have to take a look.  Thanks.

Lou

On Friday, March 20, 2015 at 3:39:25 PM UTC-4, Donald MacQueen wrote:
Hi Lou,

You may or may not already know this, but....

StsImageManager class stores many icons used in the browsers as byteArrays.  You could do the same for your inspector window and then you would not have to rely on anything external.  I have some scripts around that will create the byteArrays from icons that I can dig up if you are interested.

hth,

Donald [|]

On Friday, March 20, 2015 at 12:28:04 PM UTC-4, Louis LaBrunda wrote:
Hi Guys,

As some of you may know I am working on an inspector window that I can package with a GUI program, because sometimes (at least in one of my programs) I want to see everything in an object (that contains status information about other NT service programs) without having to build screens to display it all.  This is going very well and when I'm finished I intend to put it on the Smalltalk Goodies site.  Since it is a window and the window needs/wants an icon for the upper left hand corner, I want to supply one.  But I don't want to deal with trying to supply it from outside the two objects that are in the app I want to post to Smalltalk Goodies.  To avoid an external icon or a DLL with the icon in it, I want to create the icon from code.

This isn't too had but remembering how to do it is a PITA.  So, I have created an instance side extension to CgIcon (attached and shown below) that when called will compile the code to create the icon in the class and method named.  The extension should live in an "edit" app as it shouldn't get packaged.

You use the method by selecting the open app that houses the class you want to compile the code to and then creating an instance of the CgIcon desired with some workspace code like so:

| icon |
icon := CgIcon fromResource: 685 fileName: 'kscicons.dll'.
icon compileSourceInClass: KscInspectWindow inMethod: #windowIcon.


It will build the icon from the named DLL and resource number.  It then tells the CgIcon to compile its matching code for you in the named class and method.

Now I don't have to remember so much.  Instantiations should feel free to add this extension to an edit app if they like.

Lou


compileSourceInClass: aClass inMethod: aMethodName
"Compile source code that will create this icon (or at least one that looks like it) as a class method in the names class."
"Where aClass is a class and aMethodName is the method name as a string."
"To properly use this method, have the app that owns the class open, create an instance of CgIcon (in a workspace) and send it this message."
| stream |

self maskImage. "Fill in the icon data."

stream := WriteStream on: (String new: 5000).

stream
nextPutAll: aMethodName asString; cr;
tab; nextPutAll: '"Answer an instance of CgIcon."'; cr;
tab; nextPutAll: '| icon palette paletteBytes maskData shapeData |'; cr; cr.

stream tab; nextPutAll: 'maskData := #['.
maskData do: [:i | i printOn: stream] separatedBy: [stream space].
stream nextPutAll: '].'; cr; cr.

stream tab; nextPutAll: 'shapeData := #['.
shapeData do: [:i | i printOn: stream] separatedBy: [stream space].
stream nextPutAll: '].'; cr; cr.

stream tab; nextPutAll: 'paletteBytes := #['.
palette byteRepresentation do: [:i | i printOn: stream] separatedBy: [stream space].
stream nextPutAll: '].'; cr; cr.

stream
tab; nextPutAll: 'palette := CgIndexedPalette new.'; cr;
tab; nextPutAll: 'palette byteRepresentation: paletteBytes; size: '; nextPutAll: palette size printString.
stream nextPut: $.; cr; cr.

stream
tab; nextPutAll: 'icon := CgIcon'; cr;
tab; tab; nextPutAll: 'width: '; nextPutAll: width printString; cr;
tab; tab; nextPutAll: 'height: '; nextPutAll: height printString; cr;
tab; tab; nextPutAll: 'depth: '; nextPutAll: depth printString; cr;
tab; tab; nextPutAll: 'palette: palette'; cr;
tab; tab; nextPutAll: 'shapePad: '; nextPutAll: shapePad printString; cr;
tab; tab; nextPutAll: 'shapeData: shapeData'; cr;
tab; tab; nextPutAll: 'maskPad: '; nextPutAll: maskPad printString; cr;
tab; tab; nextPutAll: 'maskData: maskData.'; cr; cr.

stream tab; nextPutAll: '^icon.'; cr.

^aClass class compile: stream contents.



--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to make a CgIcon from code

dmacq
Lou,

Here are a few pieces of code I found that may be helpful:

CgIcon fromFile: 'c:\temp\testicon32.png'

(CfsReadFileStream open: 'c:\some.bmp') contents asByteArray.

CgPixmap fromFile: 'c:\some.bmp'

StsImageManager primImageFromSelector: #FolderMask

StsImageManager loadOneImage: #LargeBallMask

I spen a good bit of time last year in the icon world so ask away.

Donald [|]


--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to make a CgIcon from code

Louis LaBrunda
Thanks - Donald


On Friday, March 20, 2015 at 4:36:02 PM UTC-4, Donald MacQueen wrote:
Lou,

Here are a few pieces of code I found that may be helpful:

CgIcon fromFile: 'c:\temp\testicon32.png'

(CfsReadFileStream open: 'c:\some.bmp') contents asByteArray.

CgPixmap fromFile: 'c:\some.bmp'

StsImageManager primImageFromSelector: #FolderMask

StsImageManager loadOneImage: #LargeBallMask

I spen a good bit of time last year in the icon world so ask away.

Donald [|]


--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to make a CgIcon from code

Louis LaBrunda
In reply to this post by dmacq
Hey Donald,

I hadn't seen everything in StsImageManager but it is basically doing the kinds of things I'm doing to create code to generate a CgIcon.  I think the advantage of my extension is that if you can load an icon in (from any external source or from anything for that matter), you can then generate/compile code that will create the same icon from a method without needing the external form of the icon late.

Lou


On Friday, March 20, 2015 at 4:36:02 PM UTC-4, Donald MacQueen wrote:
Lou,

Here are a few pieces of code I found that may be helpful:

CgIcon fromFile: 'c:\temp\testicon32.png'

(CfsReadFileStream open: 'c:\some.bmp') contents asByteArray.

CgPixmap fromFile: 'c:\some.bmp'

StsImageManager primImageFromSelector: #FolderMask

StsImageManager loadOneImage: #LargeBallMask

I spen a good bit of time last year in the icon world so ask away.

Donald [|]


--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/d/optout.