ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Assistance with OS X ScaleFactor?
Posted by Mike Cotrone on Aug-03-2016 21:22
Peter,

I have been trying to divide my scalefactor (f) among different varibales throughout my following code that works perfectly on non-retina builds.

For example i get close if I divide my xCoor and xCoor by f, but its not perfect like it is non-retina.

Any advice?

Thanks!


Dim f, i, ii, p, g, pp as Integer
    If Me.ScalingFactor > 1 Then
      f = 2
    Else
      f = 1
    End If

    Dim xValue as Integer = Me.theChart.getNearestXValue(X)
    Dim xCoor as Integer = Me.theChart.getXCoor(xValue)

    for i = 0 to Me.theChart.getLayerCount
      // GET OUR LAYER
      Dim thisLayer as CDLayerMBS = Me.theChart.getLayerByZ(i)
      // The data array index of the x-value
      Dim xIndex as Integer = thisLayer.getXIndexOf(xValue)
      // Iterate through all the data sets in the layer
      for ii = 0 to thisLayer.getDataSetCount
        Dim thisDataSet as CDDataSetMBS = thisLayer.getDataSetByZ(ii)
        // GET Y-COOR
        Dim yCoor as Integer = Me.theChart.getYCoor(thisDataSet.getPosition(xIndex), thisDataSet.getUseYAxis())
        Me.drawMarkerPoint = New REALbasic.Point(xCoor, yCoor)
        Me.drawMarker = True
        Me.mouseOverLayerIndex = ii
        Me.mouseOverSessionIndex = i
        Me.mouseOverXIndex = xIndex
        Me.Invalidate(False)
        Exit Sub

  Re: Assistance with OS X ScaleFactor?
Posted by Peter Kwan on Aug-04-2016 00:35
Hi Mike,

Actually, I have never used Xojo (Real Studio) before, and I am not familiar with the Xojo (Real Studio) environment. The Xojo (Real Studio) ChartDirector is ported by our partner.

For your case, I am not sure how the Me.ScalingFactor works. Also, I am not sure how it is not perfect. Do you mean the track line is not at the position of the mouse? If this is the case, how is the position different. Is it that the track line and the mouse position has a fixed offset (eg. the track line is always 20 pixels to the left of the mouse), or is it a scaling issue (eg, when the mouse moves to the left by 100 pixels, the track line only moves by 95 pixels), or both, or some other behaviour?

Without understanding the Xojo (Real Studio) framework, I am also not certain what exactly is "X" mean in your code. Depending on the GUI systems, the mouse coordinates can be relative to the screen, to the window or to the control. If the X is not relative to the chart image, then scaling it does not work, as you need to scale the offset as well. In some GUI systems, the mouse coordinates are not necessarily equal to the physical screen pixel coordinates. For example, in web pages, the mouse coordinates is reported in CSS pixels, and 1 CSS pixels can equal to 1.5 screen pixels or some other factors.

Finally, whether the chart image is "stretched" will also affect the scale factor.

In your code, I noticed you have "If Me.ScalingFactor > 1 Then f = 2". It seems to imply that f is not equal to the Me.ScalingFactor, otherwise the code should be
f = Me.ScalingFactor (and f can be Double instead of Integer). I am not sure this could be the cause of the problem.

Regards
Peter Kwan

  Re: Assistance with OS X ScaleFactor?
Posted by Mike Cotrone on Aug-04-2016 00:39
Xojo ScaleFactor uses OSX Declares to get either an integer value of 1 or 2 (2 for retina and 1 for non retina). Normally for objects that don't support native scalefactoring I divide or multiple by my scalefactor.

It seems that I can't get this to work properly based on any combination of /f that I have been trying.


That is from my MouseMove event where X/Y are pixel coordinates from the mouse.

It works perfectly when I am in non retina mode (f = 1).

Any other advice would be appreciated. :)
Thanks

  Re: Assistance with OS X ScaleFactor?
Posted by Mike Cotrone on Aug-04-2016 01:07
Found the combination and works perfect on Retina and Non-Retina :)

Sub MouseMouse()

    Dim xValue as Integer = Me.theChart.getNearestXValue(X*f) // HAS TO MULTIPLY
    Dim xCoor as Integer = Me.theChart.getXCoor(xValue)

    for i = 0 to Me.theChart.getLayerCount
      // GET OUR LAYER
      Dim thisLayer as CDLayerMBS = Me.theChart.getLayerByZ(i)
      // The data array index of the x-value
      Dim xIndex as Integer = thisLayer.getXIndexOf(xValue)
      // Iterate through all the data sets in the layer
      for ii = 0 to thisLayer.getDataSetCount
        Dim thisDataSet as CDDataSetMBS = thisLayer.getDataSetByZ(ii)
        // GET Y-COOR
        Dim yCoor as Integer = Me.theChart.getYCoor(thisDataSet.getPosition(xIndex), thisDataSet.getUseYAxis())
        Me.drawMarkerPoint = New REALbasic.Point(xCoor/f, yCoor/f) // HAD TO DIVIDE
        Me.drawMarker = True
        Me.mouseOverLayerIndex = ii
        Me.mouseOverSessionIndex = i
        Me.mouseOverXIndex = xIndex
        Me.Invalidate(False)
        Exit Sub
      next ii
    next i

Thanks!