Page 2 of 2

Re: Images in listicongadgets columns

Posted: Mon Jul 28, 2014 9:39 am
by marcoagpinto
Fangbeast wrote:

Code: Select all

ChangeIcon(MyGadget.i, MyRow.i, MyColumn.i, MyIcon.i)
MyGadget.i ; The gadget constant to use
MyRow.i ; The row number to change the icon in
MyColumn.i ; The column number to change the icon in
MyIcon.i ; The icon to use

Marco, I am not angry. You just don't have to pm me and then post the same thing in the forum as well. Keep programming things in the forum where they belong so others can see it and help.

As for showing in two columns, I explained the ChangeIcon options above, the fixed code I gave you should work on 5.3, they work here.

Try it this way to see the bug:

Code: Select all

  BuildImageList()
 
  AddGadgetItem(#LISTGADGET_WEAPONS, -1, "1" + Chr(10) + "N/A" + Chr(10) + "Unknown")
  ChangeIcon(#LISTGADGET_WEAPONS, 0, 1, Icon\CatUnknown)
   
  AddGadgetItem(#LISTGADGET_WEAPONS, -1, "2" + Chr(10) + "Gun" + Chr(10) + "Pistol")
  ChangeIcon(#LISTGADGET_WEAPONS, 1, 1, Icon\CatAeroplane)
 
  AddGadgetItem(#LISTGADGET_WEAPONS, -1, "3" + Chr(10) + "TNT" + Chr(10) + "Explosive")
  ChangeIcon(#LISTGADGET_WEAPONS, 2, 1, Icon\CatAmateur)       
 
  AddGadgetItem(#LISTGADGET_WEAPONS, -1, "4" + Chr(10) + "Blade" + Chr(10) + "Knife")
  ChangeIcon(#LISTGADGET_WEAPONS, 3, 1, Icon\CatAmbulance) 
I selected column 1 and it appears in both (0 and 1)

Re: Images in listicongadgets columns

Posted: Mon Jul 28, 2014 10:22 am
by Fangbeast
Looks like column 0 is a special case so I made a transparent (blank icon) and added it to the image list. Then it gets set with the "AddgadgetItem" command:

AddGadgetItem(#LISTGADGET_WEAPONS, -1, "1" + Chr(10) + "N/A" + Chr(10) + "Unknown", Icon\Blank) ; Blank icon from imagelist

; Now set column 1 with changeicon command and it will work. You can change column 0 as well, or any other column.

ChangeIcon(#LISTGADGET_WEAPONS, 0, 1, Icon\Unknown)

Code: Select all

Declare ChangeIcon(MyGadget.i, MyRow.i, MyColumn.i, MyIcon.i)
Declare BuildImageList()
  
Enumeration 1
  #Blank
  #Unknown
  #Pistol
  #Explosives
  #Knife
 
  #WINDOW_WEAPONS
  #LISTGADGET_WEAPONS   
EndEnumeration
 
UsePNGImageDecoder()
 
Structure IconData       ; Icon data structure
  ListIconGadgetHeader.i  ; This is the handle of the listicongadget image list
  Blank.i                 ; Blank icon to fill in column 0 (special case)
  Unknown.i               ; Unknown category icon
  Pistol.i                ; Pistol icon
  Explosives.i            ; Amateur radio icon
  Knife.i                 ; Ambulance icon
EndStructure
   
Global Icon.IconData

LoadImage(#Blank,         "Images\weapons_types_blank.ico")
LoadImage(#Unknown,       "Images\weapons_types_na.ico")   
LoadImage(#Pistol,        "Images\weapons_types_gun.ico") 
LoadImage(#Explosives,    "Images\weapons_types_explosive.ico")         
LoadImage(#Knife,         "Images\weapons_types_blade.ico")

Procedure ChangeIcon(MyGadget.i, MyRow.i, MyColumn.i, MyIcon.i)
  LVG.lv_item     
  LVG\mask     = #LVIF_IMAGE | #LVIF_TEXT
  LVG\iItem    = MyRow.i
  LVG\iSubItem = MyColumn.i
  ChangeText.s = GetGadgetItemText(MyGadget.i, MyRow.i, MyColumn.i)
  LVG\pszText  = @ChangeText.s
  LVG\iImage   = MyIcon.i
  SendMessage_(GadgetID(MyGadget.i), #LVM_SETITEM, 0, @LVG)
EndProcedure

Procedure BuildImageList()
  If Icon\ListIconGadgetHeader = 0
    Icon\ListIconGadgetHeader = ImageList_Create_(16, 16, #ILC_MASK | #ILC_COLOR32, 0, 5)
  EndIf
  Icon\Blank        = ImageList_ReplaceIcon_(Icon\ListIconGadgetHeader, -1, ImageID(#Blank))
  Icon\Unknown      = ImageList_ReplaceIcon_(Icon\ListIconGadgetHeader, -1, ImageID(#Unknown))
  Icon\Pistol       = ImageList_ReplaceIcon_(Icon\ListIconGadgetHeader, -1, ImageID(#Pistol))
  Icon\Explosives   = ImageList_ReplaceIcon_(Icon\ListIconGadgetHeader, -1, ImageID(#Explosives))
  Icon\Knife        = ImageList_ReplaceIcon_(Icon\ListIconGadgetHeader, -1, ImageID(#Knife))
  SendMessage_(GadgetID(#LISTGADGET_WEAPONS), #LVM_SETIMAGELIST, #LVSIL_SMALL, Icon\ListIconGadgetHeader)
  ImageList_SetBkColor_(Icon\ListIconGadgetHeader, #CLR_NONE)
  SendMessage_(GadgetID(#LISTGADGET_WEAPONS), #LVM_SETEXTENDEDLISTVIEWSTYLE, #LVS_EX_SUBITEMIMAGES, #LVS_EX_SUBITEMIMAGES)
EndProcedure     

If OpenWindow(#WINDOW_WEAPONS, 0, 0, 1024, 768, "Weapons Editor", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_ScreenCentered | #PB_Window_Maximize) <> 0
  
  ListIconGadget(#LISTGADGET_WEAPONS, 10, 10, 975, 235, "ID", 60, #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection)
  
  AddGadgetColumn(#LISTGADGET_WEAPONS, 1, "Type", 75)       
  AddGadgetColumn(#LISTGADGET_WEAPONS, 2, "Name", 155)   
 
  BuildImageList()
  
  AddGadgetItem(#LISTGADGET_WEAPONS, -1, "1" + Chr(10) + "N/A"    + Chr(10) + "Unknown", Icon\Blank)
  ChangeIcon(#LISTGADGET_WEAPONS, 0, 1, Icon\Unknown)
   
  AddGadgetItem(#LISTGADGET_WEAPONS, -1, "2" + Chr(10) + "Gun"    + Chr(10) + "Pistol", Icon\Blank)
  ChangeIcon(#LISTGADGET_WEAPONS, 1, 1, Icon\Pistol)
 
  AddGadgetItem(#LISTGADGET_WEAPONS, -1, "3" + Chr(10) + "TNT"    + Chr(10) + "Explosive", Icon\Blank)
  ChangeIcon(#LISTGADGET_WEAPONS, 2, 1, Icon\Explosives)       
  
  AddGadgetItem(#LISTGADGET_WEAPONS, -1, "4" + Chr(10) + "Blade"  + Chr(10) + "Knife", Icon\Blank)
  ChangeIcon(#LISTGADGET_WEAPONS, 3, 1, Icon\Knife)     
 
  cancel = #False
  
  Repeat
    Event = WaitWindowEvent()
    If Event = #PB_Event_CloseWindow   
       cancel = #True
    EndIf
  Until cancel = #True

Else
  MessageRequester("Error", "Can't open a window.")
EndIf
End