Page 1 of 1

ListIcon with big Images in report view

Posted: Tue Nov 15, 2016 2:35 pm
by javabean
Hi!

I've been trying for hours to get a ListIcon In report view) with big images working - without success. I don't know why, but I get totally different Images in the ListIcon than expected. -What's wrong with this code?

Code: Select all

;Icon size
iconW.i = 200
iconH.i = 200

;Create some images
zeroImg = CreateImage(0, iconW, iconH)
StartDrawing(ImageOutput(0))
Box(0, 0, iconW, iconH, RGB(0, 0, 0))
StopDrawing()

greenImg = CreateImage(1, iconW, iconH)
StartDrawing(ImageOutput(1))
Box(0, 0, iconW, iconH, RGB(0, 255, 0))
StopDrawing()

blueImg = CreateImage(2, iconW, iconH)
StartDrawing(ImageOutput(2))
Box(0, 0, iconW, iconH, RGB(0, 0, 255))
StopDrawing()

redImg = CreateImage(3, iconW, iconH)
StartDrawing(ImageOutput(3))
Box(0, 0, iconW, iconH, RGB(255, 0, 0))
StopDrawing()

If OpenWindow(0,0,0,500,400,"Window",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  ListIconGadget(1,10,10,480,380,"Title",400,#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect)
  
  SetGadgetAttribute(1,#PB_ListIcon_DisplayMode,#PB_ListIcon_Report)
  
  AddGadgetItem(1,-1,"Testitem", blueImg)
  AddGadgetItem(1,-1,"Testitem", blueImg)
  AddGadgetItem(1,-1,"Testitem", blueImg)
  AddGadgetItem(1,-1,"Testitem", blueImg)  
  
  IL_new.i = ImageList_Create_(200,200,#ILC_COLOR32,0,10)
  ImageList_Add_(IL_new, zeroImg, 0)
  ImageList_Add_(IL_new, greenImg, 0)
  ImageList_Add_(IL_new, blueImg, 0)
  ImageList_Add_(IL_new, redImg, 0)

  IL_old.i = SendMessage_(GadgetID(1), #LVM_SETIMAGELIST, #LVSIL_SMALL, IL_new)
  ImageList_Destroy_(IL_old)
  Debug il_old
  
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Thanks for your help in advance!
javabean

Re: ListIcon with big Images in report view

Posted: Tue Nov 15, 2016 9:05 pm
by mrv2k
Works if you change the code to....

Code: Select all

;Icon size
iconW.i = 200
iconH.i = 200

;Create some images
zeroImg = CreateImage(0, iconW, iconH)
StartDrawing(ImageOutput(0))
Box(0, 0, iconW, iconH, RGB(0, 0, 0))
StopDrawing()

greenImg = CreateImage(1, iconW, iconH)
StartDrawing(ImageOutput(1))
Box(0, 0, iconW, iconH, RGB(0, 255, 0))
StopDrawing()

blueImg = CreateImage(2, iconW, iconH)
StartDrawing(ImageOutput(2))
Box(0, 0, iconW, iconH, RGB(0, 0, 255))
StopDrawing()

redImg = CreateImage(3, iconW, iconH)
StartDrawing(ImageOutput(3))
Box(0, 0, iconW, iconH, RGB(255, 0, 0))
StopDrawing()

If OpenWindow(0,0,0,500,400,"Window",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  ListIconGadget(1,10,10,480,380,"Title",400,#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect)
 
  SetGadgetAttribute(1,#PB_ListIcon_DisplayMode,#PB_ListIcon_Report)
 
  AddGadgetItem(1,-1,"Testitem", ImageID(0))
  AddGadgetItem(1,-1,"Testitem", ImageID(1))
  AddGadgetItem(1,-1,"Testitem", ImageID(2))
  AddGadgetItem(1,-1,"Testitem", ImageID(3)) 
 
  IL_new.i = ImageList_Create_(200,200,#ILC_COLOR32,0,10)
  ImageList_Add_(IL_new, zeroImg, 0)
  ImageList_Add_(IL_new, greenImg, 0)
  ImageList_Add_(IL_new, blueImg, 0)
  ImageList_Add_(IL_new, redImg, 0)

  IL_old.i = SendMessage_(GadgetID(1), #LVM_SETIMAGELIST, #LVSIL_SMALL, IL_new)
  ImageList_Destroy_(IL_old)
  Debug il_old
 
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Not quite sure why. Maybe due to ImageID requirement????

Regards

Paul

Re: ListIcon with big Images in report view

Posted: Wed Nov 16, 2016 12:51 pm
by javabean
Thanks Paul,

but this doesn't really solve the problem. If you have a closer look and change the ImageIDs to different values in both AddGadgetItem and the new ImageList, you will see they obviously interfere with each other...a very strange behaviour. It seems that the old ImageList is not fully replaced by the new ImageList.

Any other ideas on how to get this working?

Re: ListIcon with big Images in report view

Posted: Wed Nov 16, 2016 5:13 pm
by javabean
Finally I got it working!

The reason for the weird behavior was that the iImage-Index in the LVITEM structure didn't correspond to the index of the imagelist. After re-indexing ist worked!

Code: Select all

Procedure ReIndex(ListIconGadgetID.i, hImageList.i)
  n.i = ImageList_GetImageCount_(hImageList)  ;number of images in imagelist
  item.LVITEM
  
  ;set the iImage index for each item
  For i=0 To n-1 
    item\Mask     = #LVIF_IMAGE
    item\iItem    = i
    item\iImage   = i
    SendMessage_(ListIconGadgetID, #LVM_SETITEM, 0, @item.LVITEM)
  Next
  
EndProcedure

;Icon size
iconW.i = 200
iconH.i = 200

;Create some images
zeroImg = CreateImage(0, iconW, iconH)
StartDrawing(ImageOutput(0))
Box(0, 0, iconW, iconH, RGB(0, 0, 0))
StopDrawing()

greenImg = CreateImage(1, iconW, iconH)
StartDrawing(ImageOutput(1))
Box(0, 0, iconW, iconH, RGB(0, 255, 0))
StopDrawing()

blueImg = CreateImage(2, iconW, iconH)
StartDrawing(ImageOutput(2))
Box(0, 0, iconW, iconH, RGB(0, 0, 255))
StopDrawing()

redImg = CreateImage(3, iconW, iconH)
StartDrawing(ImageOutput(3))
Box(0, 0, iconW, iconH, RGB(255, 0, 0))
StopDrawing()


If OpenWindow(0,0,0,700,900,"Window",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  ListIconGadget(1,10,10,680,880,"Title",600,#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect)
  
  SetGadgetAttribute(1,#PB_ListIcon_DisplayMode,#PB_ListIcon_Report)
  
  For i=1 To 4
    AddGadgetItem(1,-1,"Testitem " + Str(i))
  Next
  
  ;create new ImageList
  IL_new.i = ImageList_Create_(200,200,#ILC_COLOR32,0,10)
  
  ;add our images to the new ImageList
  ImageList_Add_(IL_new, ImageID(0), 0)
  ImageList_Add_(IL_new, ImageID(1), 0)
  ImageList_Add_(IL_new, ImageID(2), 0)
  ImageList_Add_(IL_new, ImageID(3), 0)
  
  ;set the new ImageList
  SendMessage_(GadgetID(1), #LVM_SETIMAGELIST, #LVSIL_SMALL, IL_new)

  ;reindex the iImage member of LVITEM
  ReIndex(GadgetID(1),IL_new)

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf