Named Enumerations
Posted: Tue Apr 10, 2018 11:21 am
Hello Chaps
.... not looking for any other method or work-around, this is just about using Named Enumerations.
Why would we want Named Enumerations? Wouldn't the main reason be to allow constants to have the same value but without conflict?
When Named Enumerations were first introduced, I dabbled with them, could not really find a purpose and have not used them.
However, the app I'm currently working on is getting a bit verbose in the comments. I like to be able easily understand my own code a year later when a mod is required. So, replacing certain gadget Id arrays with constants that have meaningful names seems like a reason to use Named Enumerations. An experiment with that aim:
....but it doesn't work, it seems there is a conflict when Gadget constants have the same value, even though they are members of different Named Enumerations.
Is that a fault in my code or is it the case that Named Enumerations are not that useful?
.... not looking for any other method or work-around, this is just about using Named Enumerations.
Why would we want Named Enumerations? Wouldn't the main reason be to allow constants to have the same value but without conflict?
When Named Enumerations were first introduced, I dabbled with them, could not really find a purpose and have not used them.
However, the app I'm currently working on is getting a bit verbose in the comments. I like to be able easily understand my own code a year later when a mod is required. So, replacing certain gadget Id arrays with constants that have meaningful names seems like a reason to use Named Enumerations. An experiment with that aim:
Code: Select all
Enumeration Window
#Win
#Panel
#FileIO
#Pack
#CntrFilesInOut
#TextFileIn
#TextFileOut
#CntrStrFin
#StrFileIn
#CntrStrFout
#StrFileOut
#BtnImgFileIn
#BtnImgFileOut
#CntrList
#TextList
#EditorList
#Font10R
EndEnumeration
Enumeration ImgContainer
#CntGdtImgList00
#CntGdtImgList01
#CntGdtImgList02
EndEnumeration
Enumeration ImgCanvas
#CnvGdtImgList00
#CnvGdtImgList01
#CnvGdtImgList02
EndEnumeration
Enumeration ImgTxtTitle
#TxtGdtImgList00
#TxtGdtImgList01
#TxtGdtImgList02
EndEnumeration
Enumeration ImgCheckBox
#ChkGdtImgList00
#ChkGdtImgList01
#ChkGdtImgList02
EndEnumeration
LoadFont(#Font10R, "Arial", 10, #PB_Font_HighQuality)
UsePNGImageDecoder()
Global igImgNImg.i = CatchImage(#PB_Any,?ImgN)
If OpenWindow(#Win, 0, 0, 700, 650, "Named Enums", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
iCntrW = 170
iCnvW = (iCntrW - 10)
iTxtW = (iCntrW - 30)
iChkX = (iCntrW - 25)
ContainerGadget(#CntGdtImgList00, 5, 5, iCntrW, 150, #PB_Container_BorderLess)
CanvasGadget(#CnvGdtImgList00, 5, 5, iCnvW, 120)
TextGadget(#TxtGdtImgList00, 5, 125, iTxtW, 20, "")
CanvasGadget(#ChkGdtImgList00, iChkX, 125, 20, 20)
SetGadgetAttribute(#ChkGdtImgList00, #PB_Canvas_Image, ImageID(igImgNImg))
SetGadgetColor(#CntGdtImgList00, #PB_Gadget_BackColor, RGB(185,220,255))
SetGadgetColor(#TxtGdtImgList00, #PB_Gadget_BackColor, RGB(185,220,255))
SetGadgetFont(#TxtGdtImgList00, FontID(#Font10R))
SetGadgetData(#CntGdtImgList00, 0)
SetGadgetData(#CnvGdtImgList00, 0)
CloseGadgetList()
ContainerGadget(#CntGdtImgList01, 5, 160, iCntrW, 150, #PB_Container_BorderLess)
CanvasGadget(#CnvGdtImgList01, 5, 5, iCnvW, 120)
TextGadget(#TxtGdtImgList01, 5, 125, iTxtW, 20, "")
CanvasGadget(#ChkGdtImgList01, iChkX, 125, 20, 20)
SetGadgetAttribute(#ChkGdtImgList01, #PB_Canvas_Image, ImageID(igImgNImg))
SetGadgetColor(#CntGdtImgList01, #PB_Gadget_BackColor, RGB(185,220,255))
SetGadgetColor(#TxtGdtImgList01, #PB_Gadget_BackColor, RGB(185,220,255))
SetGadgetFont(#TxtGdtImgList01, FontID(#Font10R))
SetGadgetData(#CntGdtImgList01, 0)
SetGadgetData(#CnvGdtImgList01, 0)
CloseGadgetList()
ContainerGadget(#CntGdtImgList02, 5, 315, iCntrW, 150, #PB_Container_BorderLess)
CanvasGadget(#CnvGdtImgList02, 5, 5, iCnvW, 120)
TextGadget(#TxtGdtImgList02, 5, 125, iTxtW, 20, "")
CanvasGadget(#ChkGdtImgList02, iChkX, 125, 20, 20)
SetGadgetAttribute(#ChkGdtImgList02, #PB_Canvas_Image, ImageID(igImgNImg))
SetGadgetColor(#CntGdtImgList02, #PB_Gadget_BackColor, RGB(185,220,255))
SetGadgetColor(#TxtGdtImgList02, #PB_Gadget_BackColor, RGB(185,220,255))
SetGadgetFont(#TxtGdtImgList02, FontID(#Font10R))
SetGadgetData(#CntGdtImgList02, 0)
SetGadgetData(#CnvGdtImgList02, 0)
CloseGadgetList()
EndIf
Repeat
Until WaitWindowEvent(1) = #PB_Event_CloseWindow
DataSection ;ImgN
ImgN:
Data.q $0A1A0A0D474E5089,$524448490D000000,$1400000014000000,$1D898D0000000608,$475273010000000D
Data.q $0000E91CCEAE0042,$0000414D41670400,$00000561FC0B8FB1,$0000735948700900,$1501C20E0000C20E
Data.q $49EC010000804A28,$79DC634F38544144,$2A26022A067FFFE7,$2ECA063E8A36059A,$9860C2CEAAE0C19B
Data.q $F4C85C3007B24FEE,$E30339576A8317FB,$1862F6C7420CBFDF,$D170620AC8379208,$D4516B1DF16300E2
Data.q $CB0334E977C81860,$32BFDFCC45604F97,$FCF1C0D70C9A2DC8,$AED883269BB58331,$76B1827EBF4C0CF5
Data.q $30C01812C8031245,$66667FC32A829BF0,$06C0903D398502B8,$7C7CE060728D326A,$F6E7E5CB2045C50F
Data.q $1BC318B097F036E1,$D0623D9EAB846F07,$30C509CFD061C86C,$D79DD1C3079D8DEC,$6233D5C05467EE18
Data.q $C0EA7959AF20874B,$E0614C2831720EBD,$0CF9CE95C33B1B1F,$345B18C331237C2F,$82D453B8659490FE
Data.q $E6E7E19030C915B0,$28F874DE186AC76D,$7D86145FB9E1972E,$E23859DE191382CF,$FD89D0B613384E4C
Data.q $5E946862575B120C,$66251638B7418735,$4EF0F85035611591,$8E4370944F24A306,$048D1C184B8DC979
Data.q $DC9F38198ADBD419,$EFBC30291414B547,$A54063FCCFFFEBF4,$CCFFF2ED637E0A05,$C863B1B2FFFF1DFC
Data.q $C19B8631D47ED481,$C5560F6566EC3300,$13FEBEEFFEF879BF,$F17FFF73A6D8E1AC,$FFFCCCC7FBA8A20B
Data.q $7E5EE10370A3AAE4,$C501DCCEF0CC5C90,$E181B1985E6F20F9,$2196B3FC581B2B1F,$A4449E182F13C1C3
Data.q $862E4E5FCE928031,$C2B2307C3257134B,$823F2F41B9410E9E,$42FCDF8626EF7441,$D8A31BC4AD26970C
Data.q $882699C6C26B1AA2,$70438448794FA090,$5730F99DD100012A,$490000000047F152
Data.b $45,$4E,$44,$AE,$42,$60,$82
EndDataSection
Is that a fault in my code or is it the case that Named Enumerations are not that useful?