
Just a question is it possible a day to insert different jpg image directly, in each case in your splendid tools

Code: Select all
XIncludeFile "MicroGrid03.pbi"
CompilerIf #PB_Compiler_IsMainFile
; *************************************
; Test code
;{ *************************************
Enumeration 4242
#Win_Test
#Gad_Grid3
EndEnumeration
OpenWindow(#Win_Test,0,0,920,500,"MicroGrid Test 0.91",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
uGridEnableCallback(#True)
;- Demo two state Image cells
With uGridDefaults
\Font = "Arial"
\FontH = 8
EndWith
k$ = "Col1[80]|Col2[25]|"
uGridGadget(#Gad_Grid3,0,0,920,500,k$,10,#uGrid_AutoSizeX|#uGrid_AutoSizeY) ; Make grid,
uGridSetCellType(#Gad_Grid3,0,0,-1,-1,#uGrid_CellImageFlip) ; all cells to be images,
; Make right column into Option buttons
For Y = 0 To 7
C = #White
For n = 0 To 1
T = uGridGetFlipImageNum(#Gad_Grid3,1,Y,n) ; Get Image# for state 'n'
If T
W = ImageWidth(T) : H = ImageHeight(T) ; Size of image
If StartDrawing(ImageOutput(T))
Box(0,0,W,H,#White) ; Backdrop for cell
Circle(W/2,H/2,4,#Black) ; Draw the 'Option Button'
Circle(W/2,H/2,3,C)
StopDrawing()
EndIf
EndIf
C = #Red
Next
Next
; Set state of column 1 'Option button'
For Y = 0 To 7
uGridSetFlipImageState(#Gad_Grid3,1,Y,Y&1)
Next
uGridRefreshGrid(#Gad_Grid3) ; show initial states.
Repeat
Select WaitWindowEvent(10)
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Gadget
Select EventGadget()
; 'uGrids' grouped in order simplifies coding
Case #Gad_Grid3, MyGrid3
uGridService(EventGadget())
EndSelect
EndSelect
ForEver
Procedure uGridCallback(uGridNum,uGridEvent,IParam.i,*uGridCell)
EndProcedure
;}
CompilerEndIf
Code: Select all
Procedure uGridDrawFileImage(*uGridCell,state,FileName$,NoScale=#False) ; Load and scale a file image into cell
; Load an image, scale it to fit a specified flip cell and draw
; it onto the specified cell. A grid refresh will required
; after all images have been drawn.
; Filename$ : Full path, name and extension.
; *uGridCell : Pointer to sructure defining the cell
; State : 0 or 1 to specify the cell's state.
; Scaling : Default is to keeping image aspect ratio correct and providing
; a border top & bottom or left & right.
; NoScale = #true the image is scaled to fill the cell and may
; appear distorted
Protected IID,IW,Ih,AR_Image.f,cw,ch,AR_Cell.f,X,Y,*CellDat.CELLOPTIONS,T,F.f
; Check for null pointer
If *uGridCell = 0 : ProcedureReturn #False : EndIf
; Load the specified picture image
If FileSize(FileName$) = 0 : ProcedureReturn #False : EndIf ; No file...
Debug FileName$
IID = LoadImage(#PB_Any,FileName$)
If IID = 0 : ProcedureReturn #False : EndIf ; Will not load...
Debug "here................"
; Get size of picture and calculate the aspect ratio.
IW = ImageWidth(IID) : Ih = ImageHeight(IID)
AR_Image = IW/Ih
*CellDat.CELLOPTIONS = *uGridCell
With *CellDat
; Get size of cell and calculate the aspect ratio.
T = \CellImage[state & 1]
cw = ImageWidth(T) : ch = ImageHeight(T)
AR_Cell = cw / ch
; Calculate scaling factor so major image dimension
; fits the cell, then scale the image.
If NoScale
ResizeImage(IID,cw,ch)
X=0 : Y = 0
Else
If AR_Image > AR_Cell
F = IW / cw
ResizeImage(IID, cw, Ih / F)
X = 0 : Y = (ch-ImageHeight(IID))/2
Else
F = Ih / ch
ResizeImage(IID, IW / F, ch)
X = (cw-ImageWidth(IID))/2 : Y = 0
EndIf
EndIf
; Draw the image on the cell
If StartDrawing(ImageOutput(\CellImage[state & 1]))
Box(0,0,cw,ch,\CellBackColour)
DrawImage(ImageID(IID),X,Y)
StopDrawing()
EndIf
EndWith
FreeImage(IID)
ProcedureReturn #True
EndProcedure
Procedure uGridDrawTextImage(GadNum,*uGridCell,state,Text$,NoClear=#True) ; Render a text string into an image cell.
; Gadnum : Ugrid gadget number
; *uGridCell : Pointer to sructure defining the cell
; State : 0 or 1 to specify the cell's state.
; Text$ ; String to be rendered. Use '|' to force a new line.
Protected IID,IW,Ih,cw,ch,Y,*CellDat.CELLOPTIONS,T,GridIndex,n,k$
GridIndex = uGridGetGridIndex(GadNum) ; Look in table for wanted grid
If GridIndex = -1 : ProcedureReturn #False : EndIf ; Grid not found
If *uGridCell = 0 : ProcedureReturn #False : EndIf ; Check for NULL pointer
*CellDat.CELLOPTIONS = *uGridCell
With *CellDat
; Get cell image dimensions
T = \CellImage[state & 1]
cw = ImageWidth(T) : ch = ImageHeight(T)
If StartDrawing(ImageOutput(\CellImage[state & 1]))
DrawingMode(#PB_2DDrawing_Transparent)
DrawingFont(uGrid(GridIndex)\GridFontID)
If NoClear = #False ; Optionally....
Box(0,0,cw,ch,\CellBackColour) ; clear the cell.
EndIf
Y = 0 ; Initial text position.
For n = 1 To CountString(Text$,"|") + 1
k$ = StringField(Text$,n,"|") ; Isolate the field,
DrawText(1,Y,k$,\CellTextColour) ; show it,
Y + TextHeight("Xy") ; move text position down one row.
If Y+TextHeight("Xy") > \CellH ; Check there is room for another row...
Break ; NO...!
EndIf
Next
StopDrawing()
EndIf
EndWith
ProcedureReturn #True
EndProcedure
Code: Select all
UseJPEGImageDecoder() ; Define libraries
FileName$ = "c:\temp\FredIsHere.jpg"
T = uGridGetCellPtr(#Gad_Grid3,2,0)
uGridDrawFileImage(T,0,FileName$)
FileName$ = "c:\temp\temppic.jpg"
T = uGridGetCellPtr(#Gad_Grid3,2,1)
uGridDrawFileImage(T,0,FileName$,0)
FileName$ = "c:\temp\tall.jpg"
T = uGridGetCellPtr(#Gad_Grid3,2,2)
uGridDrawFileImage(T,0,FileName$)
FileName$ = "c:\temp\wide.jpg"
T = uGridGetCellPtr(#Gad_Grid3,2,2)
uGridDrawFileImage(T,1,FileName$)
uGridDrawTextImage(#Gad_Grid3,uGridGetCellPtr(#Gad_Grid3,2,0),0," Hello| World",1)
uGridDrawTextImage(#Gad_Grid3,uGridGetCellPtr(#Gad_Grid3,2,0),1," Hello| you...",1)
Code: Select all
FreeImage(1)
Code: Select all
FreeImage(IID)
Code: Select all
; Demo two state Image cells
With uGridDefaults
\EditStart = #PB_EventType_LeftButtonDown ; Single click selection
\GridFont = "Arial"
\GridFontH = 12
\TitleFont = "Courier"
\TitleFontH = 12
\ImageCellH = 99 ; Set cell height... used for all cells.
EndWith
Code: Select all
; Rev 0.94
; ========
; Mod - Reworked RowSwap to ONLY move 'variable' data.
; Mod - Faster caret flash
; Fixed - Selection Cell border did not clear properly.
; Rev 0.95 - Linking to a SQL data base
;========
; Added - Callback #uGridEvent_TitleRightClick
; Added = Callback for CNTRL+ A=>Z (Excludes C,V and X, already used.)
; Added - First attempt to make a simple SQL data base that ties in with a uGrid.
; - uGridCreateSQLiteDB() Creates a SQLite DB based on uGrid
; - uGridWriteRowToDatabase() Writes a line grid => to DB
; - uGridGetDataBaseEntries() Reads DB =>grid ***
; - uGridDbSearch() Search for an exact pattern match in a specific column.
; - uGridGetTimeExtent() provides the 'TimeStamp' values for the first and last DB records.
; Mod - Callbacks #uGridEvent_CellSelect
; #uGridEvent_CellXY both report PREVIOUS cell pointer in IParam.
; Mod - Cell's structure now included the Grid's GadgetNumber.
; Rev 0.96 - More SQL stuff.
; ========
; Mod - uGridCreateSQLiteDB() Now has optional options string to define the SQLite variable types.
; Added - uGridDeleteDatabaseRow() Delete row from database identified by TimeStamp ***
; - uGridUpdateDatabaseRow() Re-write database row identified by TimeStamp ***
; NOTE: *** uGridGetDatabaseEntries() Modified to write the TimeStamp to the Data field of the first cell on each row.
; The Delete and Update functions REQUIRE the Data field of the first cell to have the record's TimeStamp.
; Mod - uGridDbSearch() Now uses 'LIKE' instead of '=' to allow partial match options.
; Added - Mouse wheel moves selection box up / down. (Great for scrolling SQL database etc!)
; Exception: If selected cell is list then mouse scrolls the list
; Added - Callback #uGridEvent_UpLimit User trying to move selection above top line. It's scrolly time :-)
; - Callback #uGridEvent_DownLimit User trying to move selection under bottom line. It's scrolly time :-)
; Added - uGridSetListCellState(GadNum,X,Y,CellState) Set ListCell text to match 'State'
; Added - uGridGetListCellState(GadNum,X,Y) Return offset of text in refernce string.
; Mod - CNTRLC/V/X now use the ClipBoard() functions instead of local storage. Allows pasting outside uGrid.
; Needs to have text length limited.
; STILL TO DO... Picture storage is not tested and probably does not work!