B4J Library [B4X] [XUI] xGauges Class

Discussion in 'B4J Libraries & Classes' started by klaus, Nov 2, 2018.

  1. klaus

    klaus Expert Licensed User

    NEW
    The xGauges Class does now also exist as a B4X libary.
    The xGauges.b4xlib and the xGauges.xml files are attached.
    You need to copy the xGauges.b4xlib file to the AdditionlLibraries folder for eace product!
    Don’t copy the xGauges.xml file to the AdditionalLibraries folder, copy it in another folder for all b4xlib xml files.
    The xGauges.xml file is for help purposes and is useful with the B4X Help Viewer or the B4XObjectBrowser.
    The xGauges.xml was generated with this tool: [B4X] Xml2Map - Simple way to parse XML documents.

    Having seen this thread fuel gauge, it challenged me and I wrote this CustomView xGauges Class.
    It works on all three products: B4A, B4i and B4J.
    The xGauges.bas file is located in the B4J project and shared, relative link, in B4A and B4i.
    The code is exactly the same, one class file, for all three products.

    Demoprograms for all three products.
    Tested on PC, Android Samsung S6 and iPhone 6.

    EDIT: 2018.12.20 Version 1.3
    Amended problem reported in post#11.

    EDIT: 2018.12.14 Version 1.2
    Amended problem with GaugeTitle and GaugeUnit not updated in code.

    upload_2018-11-2_16-42-35.gif

    xGauges

    Author: Klaus CHRISTL
    Version: 1.3
    • xGauges
      • Functions:
        • AddToParent (Parent As Object, Left As Int, Top As Int, Width As Int) As String
          adds the xGauge to the Parent view.
          the parent object can be a B4XView or
          an Activity or a Panel in B4A, a Panel in B4i or a Pane in B4J
          there is no Height property, because the Height = Width
        • Initialize (Callback As Object, EventName As String) As String
          Initializes a xGauge
          Callback is the calling module
          EventNam3 is the generic event name, not used
        • IsInitialized As Boolean
          Tests whether the object has been initialized.
      • Properties:
        • BackgroundColor As Int
          sets or gets the BackgroundColor
          it must be an xui.Color
          Example: xGauge1.BackgroundColor = xui.Color_White
        • CustomScaleEndAngle As Int
          sets or gets the CustomScaleEndAngle
          Start angle for Custom scale angle gazge type.
          trigonometric angles 0 at 3 o'clock
          positive counter clockwise
        • CustomScaleStartAngle As Int
          sets or gets the CustomScaleStartAngle
          Start angle for Custom scale angle gazge type.
          trigonometric angles 0 at 3 o'clock
          positive counter clockwise
        • GaugeTitle As String
          sets or gets GaugeTitle property
        • GaugeType As String
          sets or gets GaugeType property
          possible values 90° Top, 180°, 270°, 90° Left, Custom scale angles
          for Custom scale angles you can set the start and the end angle
        • GaugeUnit As String
          sets or gets GaugeUnit property
        • HalfTicks As Boolean
          gets or sets if half (intermedaite) tick are required
          one tick between two main ticks
        • Left As Double
          sets or gets the Left property
        • MainTickNumber As Int
          gets or sets the number of main ticks
          for a scale from 0 to 10 then number must be 11
        • NeedleBitmapFileName As String
          sets or gets the NeedleBitmapFileName
          enter 'no file' without the quotes to use the default needle
        • NeedleColor As Int
          sets or gets the NeedleColor
          it must be an xui.Color
          Example: xGauge1.NeedleColor = xui.Color_Gray
        • ScaleColor As Int
          sets or gets the ScaleColor
          it must be an xui.Color
          Example: xGauge1.ScaleColor = xui.Color_Black
        • ScaleHighLimitColor As Int
          sets or gets the ScaleHighLimitColor
          it must be an xui.Color
          Example: xGauge1.ScaleHighLimitColor = xui.Color_Red
        • ScaleHighLimitPerCent As Double
          sets or gets the ScaleHighLimitPerCent property
          it is drawn from the given percent to the scale end
          given in pecent of the scale
        • ScaleLowLimitColor As Int
          sets or gets the ScaleLowLimitColor
          it must be an xui.Color
          Example: xGauge1.NeedleColor = xui.Color_RGB(526, 165, 0)
        • ScaleLowLimitPerCent As Double
          sets or gets the ScaleLowLimitPerCent property
          given in pecent of the scale
          it drawn from the scale start to the given percent
        • ScaleMidLimitColor As Int
          sets or gets the ScaleMidLimitColor
          it must be an xui.Color
          Example: xGauge1.ScaleMidLimitColor = xui.Color_RGB(526, 165, 0)
        • ScaleMidLimitStartPerCent As Double
          sets or gets the ScaleMidLimitStartPerCent property
          it is drawn from the given start percent over the sweep percent
          given in pecent of the scale
        • ScaleMidLimitSweepPerCent As Double
          sets or gets the ScaleMidLimitSweepPerCent property
          it is drawn from the given start percent over the sweep percent
          given in pecent of the scale
        • SmallTicksNumber As Int
          gets or sets the SmallTickNumber property
          SmallTicksNumber small ticks will drawn between two main ticks
          for a decimal scale SmallTickNumber = 10, eventhough only 9 ticks are seen, the 10th is hidden by the main tick
        • TickText As String
          gets or sets the texts for the ticks
          the values between two || are displayed equally spaced on the scale
          Example: 0|20|40|60|80|100 or E|1/2|F
        • Top As Double
          sets or gets the Top property
        • Value
          sets the value of the gauge
          the value must be between ValueMin and ValueMax
        • ValueMax As Int
          gets or sets the max value of the gauge
        • ValueMin As Int
          gets or sets the min value of the gauge
        • Width As Double
          sets or gets the width of the gauge
          there is no height property because the height is equal to the width
     

    Attached Files:

    Last edited: Jan 22, 2019 at 8:47 AM
  2. Johan Hormaza

    Johan Hormaza Active Member Licensed User

    Thanks Klaus !!!!
     
  3. Roberto P.

    Roberto P. Well-Known Member Licensed User

    excellent work Klaus. Thank for you sharing.

    It's possible change the label in the center of display? for example, it's possibile change Speed and miles widht other text?

    regards
     
  4. Myron

    Myron Active Member Licensed User

    Thank you @klaus , it's seems that in the B4A project missed something like xFuelGauge.bas
     
  5. Myron

    Myron Active Member Licensed User

    In the b4a project
    I copied the file xGauges.bas from b4j to the b4a folder and I added to the project.
    I changed
    Code:
    Private xFuelGauge1 As xFuelGauge
    to
    Code:
    Private xFuelGauge1 As xGauges
     
    Last edited: Nov 3, 2018
  6. klaus

    klaus Expert Licensed User

    You have the properties GaugeTitle and GaugUnit, you can change their value in the Designer.

    Sorry, I uploaded an older version.
    Uploaded the new one in post#1.
     
    Myron likes this.
  7. Erel

    Erel Administrator Staff Member Licensed User

    Great work Klaus!
     
  8. jose luis gudino

    jose luis gudino Member Licensed User

    excellent work Klaus
     
  9. Gandalf

    Gandalf Member Licensed User

    Great! That's exactly what I need now. Thank you so much, Klaus!
     
  10. klaus

    klaus Expert Licensed User

    The xGauge Class has been updatet to version 1.2.
     
  11. iCAB

    iCAB Well-Known Member Licensed User

    Hi Klaus,

    Please check the second gauge (using B4A)

    Thanks
    iCAB
     

    Attached Files:

  12. klaus

    klaus Expert Licensed User

    In the Designer, replace 225 by -225 for the CustomScaleStartAngle property.

    upload_2018-12-20_9-36-45.png

    I will check that the start angle is smaller than the end angle in the next update.
     
  13. klaus

    klaus Expert Licensed User

    The xGauge Class has been updatet to version 1.3.
    Amended problem reported in post#11.
     
    iCAB likes this.
  14. iCAB

    iCAB Well-Known Member Licensed User

    Thanks Klaus for your continuous support!

    Works great
     
  15. Tayfur

    Tayfur Well-Known Member Licensed User

    Again, again.. great works..
    Thanks for sharing @klaus
     
  16. Dudi

    Dudi Member Licensed User

    Thanks Klaus !!!!
     
  17. klaus

    klaus Expert Licensed User

    The xGauge Class (version 1.3) is now also available as a B4X library.
    The xGauges.b4xlib and the xGauges.xml files have been added in the first post.
     
    amaxco likes this.
  18. Dadaista

    Dadaista Member Licensed User

    I have copied both files to the AdditionlLibraries and get this error

    File .jar is missing for xgauges.xml
     
  19. DonManfred

    DonManfred Expert Licensed User

    do not copy the xml to the libs folder. It is only needed to generate an Docu from the xml. For ex with this tool.
     
  20. Dadaista

    Dadaista Member Licensed User

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice