ImageButtonGadget images

Share your advanced PureBasic knowledge/code with the community.
User avatar
electrochrisso
Addict
Addict
Posts: 989
Joined: Mon May 14, 2007 2:13 am
Location: Darling River

Re: ImageButtonGadget images

Post by electrochrisso »

You saved me a bit of time to work that bit out TI, so it was worth the mention. :)
PureBasic! Purely the best 8)
User avatar
kernadec
Enthusiast
Enthusiast
Posts: 146
Joined: Tue Jan 05, 2010 10:35 am

Re: ImageButtonGadget images

Post by kernadec »

hi
it could be like that too

Goodday

Code: Select all

#Btnpage_white_office = 1
CatchImage(0,?image)

OpenWindow(#PB_Any, 0, 0, 400, 300, "WindowTitle", #PB_Window_MinimizeGadget|#PB_Window_ScreenCentered) 
ButtonImageGadget(#Btnpage_white_office, 30, 30, 32, 32,ResizeImage(0,32,32)) 
	
Repeat 
Until WaitWindowEvent() = #PB_Event_CloseWindow 

DataSection
  image:
  IncludeBinary #PB_Compiler_Home+"\Examples\Sources\Data\Geebee2.bmp"
EndDataSection
User avatar
electrochrisso
Addict
Addict
Posts: 989
Joined: Mon May 14, 2007 2:13 am
Location: Darling River

Re: ImageButtonGadget images

Post by electrochrisso »

kernadec wrote:hi
it could be like that too

Goodday

Code: Select all

#Btnpage_white_office = 1
CatchImage(0,?image)

OpenWindow(#PB_Any, 0, 0, 400, 300, "WindowTitle", #PB_Window_MinimizeGadget|#PB_Window_ScreenCentered) 
ButtonImageGadget(#Btnpage_white_office, 30, 30, 32, 32,ResizeImage(0,32,32)) 
	
Repeat 
Until WaitWindowEvent() = #PB_Event_CloseWindow 

DataSection
  image:
  IncludeBinary #PB_Compiler_Home+"\Examples\Sources\Data\Geebee2.bmp"
EndDataSection
Not really related to this posting, anyhow why have you got ResizeImage(0,32,32) as the image id for the ButtonImageGadget. :?:
PureBasic! Purely the best 8)
User avatar
TI-994A
Addict
Addict
Posts: 2741
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: ImageButtonGadget images

Post by TI-994A »

electrochrisso wrote:...why have you got ResizeImage(0,32,32) as the image id for the ButtonImageGadget. :?:
Hello again electrochrisso. It's because the image dimensions are larger than the button. If it is not resized to match the dimensions of the button, only a portion of the image will be drawn.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
User avatar
electrochrisso
Addict
Addict
Posts: 989
Joined: Mon May 14, 2007 2:13 am
Location: Darling River

Re: ImageButtonGadget images

Post by electrochrisso »

TI-994A wrote:
electrochrisso wrote:...why have you got ResizeImage(0,32,32) as the image id for the ButtonImageGadget. :?:
Hello again electrochrisso. It's because the image dimensions are larger than the button. If it is not resized to match the dimensions of the button, only a portion of the image will be drawn.
Yes it changes the handle to the newly resized image, I probably have used it before but forgot, I will remember that one in future. :)
PureBasic! Purely the best 8)
User avatar
TI-994A
Addict
Addict
Posts: 2741
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: ImageButtonGadget images

Post by TI-994A »

electrochrisso wrote:Yes it changes the handle to the newly resized image, I probably have used it before but forgot, I will remember that one in future. :)
Wow! I answered your question without understanding it; sorry about that.

You're absolutely correct; it seems that ResizeImage() does return a new image handle - not documented though. Thank you for pointing that out.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
User avatar
kernadec
Enthusiast
Enthusiast
Posts: 146
Joined: Tue Jan 05, 2010 10:35 am

Re: ImageButtonGadget images

Post by kernadec »

@electrochrisso Not really related to this posting????
why this reproach! it is not off topic
excuse me but you misjudge the code as it is in the same kind.
image data is inserted in the compilation with the same principle,


Goodday
User avatar
Bisonte
Addict
Addict
Posts: 1313
Joined: Tue Oct 09, 2007 2:15 am

Re: ImageButtonGadget images

Post by Bisonte »

But with IncludeBinary some virusscanners gone wild ...
I prefer Stargates Method with Quads ... (and his IDE Tool to make these Datasections) ;) All types of Images are possible, and other things...
PureBasic 6.21 (Windows x64) | Windows 11 Pro | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom​​
English is not my native language... (I often use DeepL.)
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: ImageButtonGadget images

Post by IdeasVacuum »

kernadec, please see the first post - this is about an alternative to included data methods.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
kernadec
Enthusiast
Enthusiast
Posts: 146
Joined: Tue Jan 05, 2010 10:35 am

Re: ImageButtonGadget images

Post by kernadec »

@IdeasVacuum, I understand the alternative,
I do not dispute your work, it was not my intention, for me just one example.
thank for the sharing.

@Bisonte, OK :D
would you tell me where I can find the tool, compressed data of Stargate , thanks

Good day
User avatar
VB6_to_PBx
Enthusiast
Enthusiast
Posts: 627
Joined: Mon May 09, 2011 9:36 am

Re: ImageButtonGadget images

Post by VB6_to_PBx »

TI-994A wrote:Hi IdeasVacuum. Thanks for the great work!
VB6_to_PBx wrote:[14:38:05][COMPILER] Line 268: Constant not found: #Btnpage_white_office.
[14:41:04][COMPILER] Line 268: Constant not found: #Btnpage_white_office.
...
a short "complete actual working " source code example showing how to display the image on a button image gadget would help tremendously
Hi VB6_to_PBx. You'll have to either enumerate the ButtonImageGadget() or manually assign it a gadget number. Also, make sure that the ButtonImageGadget() size matches the created image size. Give this a try:

Code: Select all

Enumeration
  #MainWindow
  #Btnpage_white_office
EndEnumeration

Procedure DrawBtnpage_white_office()

  ;the ButtonImageGadget() size should match this image size
  Protected iImage.i = CreateImage(#PB_Any, 100, 30, 24)

    If StartDrawing(ImageOutput(iImage))
          DrawingMode(#PB_2DDrawing_Default)
          Plot(0000,0000,RGB(255,255,255)) ...
          ...
          ...
          ...
          StopDrawing()

          ;#Btnpage_white_office is the assigned constant for the ButtonImageGadget()
          SetGadgetAttribute(#Btnpage_white_office, #PB_Button_Image, ImageID(iImage))

    EndIf
EndProcedure

wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
OpenWindow(#MainWindow, #PB_Any, #PB_Any, 300, 300, "Image Button Example", wFlags)

;create a ButtonImageGadget() with #Btnpage_white_office as the gadget number,
;assign a zero value to the ImageID and ensure that the size matches the output image
ButtonImageGadget(#Btnpage_white_office, 30, 30, 100, 30, 0)

DrawBtnpage_white_office()

While WaitWindowEvent() ! #PB_Event_CloseWindow : CloseWindow : Wend

TI-994A ,
thank you very much for your help !
 
PureBasic .... making tiny electrons do what you want !

"With every mistake we must surely be learning" - George Harrison
User avatar
electrochrisso
Addict
Addict
Posts: 989
Joined: Mon May 14, 2007 2:13 am
Location: Darling River

Re: ImageButtonGadget images

Post by electrochrisso »

TI-994A wrote:
electrochrisso wrote:Yes it changes the handle to the newly resized image, I probably have used it before but forgot, I will remember that one in future. :)
Wow! I answered your question without understanding it; sorry about that.

You're absolutely correct; it seems that ResizeImage() does return a new image handle - not documented though. Thank you for pointing that out.
Actually it is in the docs, it's further down in the remarks section, as stated:- This function changes the handle of the used image. Therefore it must be newly assigned e.g. to an ImageGadget() with SetGadgetState().

I did a quick test:-

a.l=CreateImage(0,100,100)
Debug a
Debug ImageID(0)

-1140517088
-1140517088

b.l=ResizeImage(0,10,10)
Debug b
Debug ImageID(0)

537204954
537204954
PureBasic! Purely the best 8)
User avatar
Bisonte
Addict
Addict
Posts: 1313
Joined: Tue Oct 09, 2007 2:15 am

Re: ImageButtonGadget images

Post by Bisonte »

kernadec wrote:@Bisonte, OK :D
would you tell me where I can find the tool, compressed data of Stargate , thanks

Good day
No problem .... : http://purebasic.fr/german/viewtopic.ph ... 45#p294445
PureBasic 6.21 (Windows x64) | Windows 11 Pro | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom​​
English is not my native language... (I often use DeepL.)
User avatar
TI-994A
Addict
Addict
Posts: 2741
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: ImageButtonGadget images

Post by TI-994A »

VB6_to_PBx wrote:TI-994A ,
thank you very much for your help !
Hello VB6_to_PBx. I am so glad that it was helpful to you; and thank you for saying so.
electrochrisso wrote:Actually it is in the docs, it's further down in the remarks section, as stated:- This function changes the handle of the used image. Therefore it must be newly assigned e.g. to an ImageGadget() with SetGadgetState().
Hello electrochrisso. You're right again. The documentation is a little confusing when it mentioned that ResizeImage() returns nonzero if the operation succeeded and zero if it failed, without indicating that the nonzero is the new handle. Regardless, it's always great to learn something new. Thank you.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
Post Reply