Widget States
Most widget modules will contain two states: one used to initialize the parameter values and one to display the tag's value and other graphics on a page.
The display functions must monitor properties of the tag. If the tag's units or scaling change, the widget will need to update its appearance to match the new format. It should also be able to display the Questionable or Manual Value markers if those exist and are set in the tag. (An example of the code to do this can be seen in Create a Custom Tag Widget.)
Finally, the tag's main state must launch a call to the tag's Common module if it is to support tool tips, trend windows or right-click navigation menus.
An abbreviated version of the states found in the Analog Status tag's Draw widget is presented here as an example. Features such as the alarm display have not yet been covered in this chapter and so are excluded from the example.
Init [ If 1 Main; [ {***** Set defaults for the parms *****} Digits = PickValid(Digits, 0); ShowUnits = PickValid(ShowUnits, 1); Border = PickValid(Border, 1); BgndColor = PickValid(BgndColor, \DialogBGColor); DisableTrend = PickValid(DisableTrend, 0); DisableNavigation = PickValid(DisableNavigation, 0); DisableTooltip = PickValid(DisableTooltip, 0); ] ] Main [ {***** Work format for display of value *****} Format = Concat(Valid(\Value) ? Concat("%0.", PickValid(Digits, 1), "f") : Concat("*.", MakeBuff(PickValid(Digits, 1), 0x2A { * character })), " ", PickValid(\Questionable, 0) ? "?" : "", Valid(\ManualValue) ? "!" : "", PickValid(\Questionable, 0) || Valid(\ManualValue) ? " " : "", PickValid(ShowUnits, 0) ? "%s" : "", ); {***** Figure out what the text looks like *****} If Watch(1, Format, \ScaledMax, \Units); [ {***** Get the full string - number, decimal, units and all *****} Buff = BuffStream(""); SWrite(Buff, Format, PickValid(PickValid(\ScaledMax, \Value), \Units), \Units); ] {***** Convert font point text name into an object and a font *****} If Watch(1, FontVal); [ DrawFontObj = ValueType(FontVal) == 7 { Tag object } ? FontVal : Scope(\Code, FontVal); ] ChosenFont = Font(DrawFontObj\FontName, DrawFontObj\CharacterSet, DrawFontObj\Height, DrawFontObj\Rotation, DrawFontObj\Weight, DrawFontObj\Italic, DrawFontObj\Fixed); QualityIssue = PickValid(Scope(Root, Quality)\Value != 0, 0); TextColor = PickValid(Questionable, 0) ? \ButtonShadow : (Color == \ButtonTextColor ? 15 : \ButtonTextColor); { Background Button } GUIButton(0, 30, 200, 0, 1, 1, 1, 1, 1, 0, 0, Border, 0, 0, 0, 0, BgndColor, \ButtonHighlight , \ButtonShadow, -1, 4, 0, "", "", 0, 0, 1, 2); { Description } GUIText(4, 30, 200, 0, 1, 1, 1, 1, 1, 0, 0, Border, 1, 0, 0, 0, -1, \ButtonTextColor, PickValid(DrawFontObj\Value, \_DialogFont), 2, 4, { Alignment } \Description); { The indented box } GUIButton(130, 26, 196, 4, 1, 1, 1, 1, 1, 0, 0, Border, 0, 0, 0, 0, -1, \ButtonShadow, \ButtonHighlight, -1, 4, 0, "", "", 0, 0, 1, 2); {***** Display the number *****} GUIText(0, 1, 1, 0, 1 - (Border ? 131 : 0), Border ? 25 : 30, Border ? 195 : 200, 1 - (Border ? 5 : 0), 1, 0, 0, 1, 1, 0, 0, 0, Color, TextColor, PickValid(DrawFontObj\Value, \_DialogFont), 4, 4, { Alignment } Format, PickValid(\Value, \Units), \Units); {***** Display common features *****} \Common(0, 30, 200, 0, DisableTrend, DisableNavigation, DisableTooltip); ]