Advertisement
NJ5SkwAg

HSGraph.ahk

Oct 15th, 2015
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
  2. ; #Warn  ; Enable warnings to assist with detecting common errors.
  3. SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
  4. SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
  5. #SingleInstance Force
  6.  
  7. OnMessage(0xF, "WM_PAINT")
  8.  
  9. IfExist, HSGraph.ini
  10. {
  11.     IniRead, maxCurrent, HSGraph.ini, HSGraph, maxCurrent
  12.     IniRead, timeInterval, HSGraph.ini, HSGraph, timeInterval
  13.     IniRead, numIntervals, HSGraph.ini, HSGraph, numIntervals
  14.     IniRead, width, HSGraph.ini, HSGraph, width
  15.     IniRead, height, HSGraph.ini, HSGraph, height
  16.     IniRead, inactive, HSGraph.ini, HSGraph, inactive
  17.     IniRead, playSoundBelowZone, HSGraph.ini, HSGraph, playSoundBelowZone
  18. }
  19. else
  20. {
  21.     maxCurrent := round(((GetZone() - 80) / 25) ** 1.3 * 1.7)
  22.     if !maxCurrent
  23.         maxCurrent := 100
  24.     timeInterval := 8.7
  25.     numIntervals := 3
  26.     width := 1300
  27.     height := 210
  28.     inactive := 20
  29.     playSoundBelowZone := 0
  30.     IniWrite, %maxCurrent%, HSGraph.ini, HSGraph, maxCurrent
  31.     IniWrite, %timeInterval%, HSGraph.ini, HSGraph, timeInterval
  32.     IniWrite, %numIntervals%, HSGraph.ini, HSGraph, numIntervals
  33.     IniWrite, %width%, HSGraph.ini, HSGraph, width
  34.     IniWrite, %height%, HSGraph.ini, HSGraph, height
  35.     IniWrite, %playSoundBelowZone%, HSGraph.ini, HSGraph, playSoundBelowZone
  36. }
  37. inactive *= 1000
  38.  
  39. Gui, Margin, 6, 4
  40. Y := mod(height, 12) / 2
  41. Loop, % height // 12
  42.     Gui, Add, Text, xm+%width% ym+%Y% w18 h11 0x200, % round((height - Y - 6) * maxCurrent / height), Y += 12
  43. Gui, Add, Text, xm-2 ym w%width% h%height% hwndhGraph gXGraph_GetVal
  44. pGraph := XGraph(hGraph, 0, 3, "", 0xAAAA00, 1, True)
  45. Gui, Add, StatusBar
  46. SB_SetParts(90, 92, 108, 86, 85, 90)
  47. SB_SetText("Press F1 for help", 7)
  48. Gui, Show,, Plotting Base Primal Hero Souls
  49. WinGet, winID, ID, Plotting Base Primal Hero Souls
  50.  
  51. helpText =
  52. (
  53. So I thought I'd make a little graphing program to help people identify at a glance their real world optimal zone, help see the value of Iris, and see how their skills are performing.
  54.  
  55. It'll only work for the browser version of the game because of the way the zone is displayed in the title of the browser.
  56.  
  57. How to use:
  58.  
  59. Once it's downloaded double click on it. You'll see an empty graph window appear, as your Clicker Heroes game advances through zones the graph will fill in at fixed intervals with the base primal hero souls that have been collected since the last fixed interval. Once it's been filled in a bit you can click on a point on the graph to show the time since the last ascension and the zone at that point. When your 'Recent' average beings to drop below your 'Ascension' average it's a good time to ascend.
  60.  
  61. On the first run a .ini file will be created with the default variables. They are as follows:
  62.  
  63. * maxCurrent: This is the highest number of base primal hero souls you'll be expecting on a run. It should be a little higher then the highest 'Current' value shown. If it's too high you may have a hard time seeing your graph and if it's too low the graph will be off the screen and a higher suggested value will appear.
  64. * timeInterval: This is the number of seconds between each zone check
  65. * numIntervals: This is the number of intervals the 'Recent' average will consider
  66. * width and height: These control the size of the graph window
  67. * inactive: This is the number of seconds the program will continue to plot while there are no zone changes
  68. * playSoundBelowZone: If you'd like a sound to be played when things slow down, set this to a zone you know should be able to insta kill to (this defaults to zero ie off)
  69.  
  70. In the bottom left you'll see four averages:
  71.  
  72. * Current: is the base primal HS gained over the most recent time interval
  73. * Recent: is the average of the the base primal HS gained over the number of time intervals specified by numIntervals (defaults to three)
  74. * Ascension: is the average of the base primal HS gained since the last time the zone dropped by more then two (this will incorrectly see fighting immortals as ascending)
  75. * Total: is the average since starting the program
  76.  
  77. Once you've clicked on the graph you'll see two more numbers:
  78.  
  79. * Zone: is the zone at the point you've clicked on the graph
  80. * Time: is the time at the point you've clicked on the graph since the last ascension (or immortal fight)
  81. )
  82.  
  83. prevZone := GetZone()
  84. sum := 0, sumSinceLastAscension := 0, i := 0, j := 0, suggestedCurrent := 0, st := A_TickCount, pt := 0, lastSound := 0
  85. timeIntervalMS := timeInterval * 1000
  86. SetTimer, Plot, %timeIntervalMS%
  87.        
  88. Plot:
  89.     zone := GetZone()
  90.     if (zone = prevZone) ; dealing with inactivity/pausing - after a default of 20s, stops plotting, shaves paused time off of time since last ascension time
  91.     {
  92.         if !pt
  93.             pt := A_TickCount
  94.         if (A_TickCount - pt > inactive)
  95.             return
  96.     }
  97.     else if (pt and A_TickCount - pt > inactive)
  98.         st += A_TickCount - pt - inactive, pt := 0
  99.    
  100.     if (zone + 1 < prevZone) ; interprets this as ascending
  101.         sumSinceLastAscension := 0, j := 0, st := A_TickCount
  102.    
  103.     sumPrev := 0
  104.     loop % numIntervals - 1 ; for the 'Recent:' display
  105.     {
  106.         tmp := numIntervals - A_Index + 1
  107.         tmp2 := numIntervals - A_Index
  108.         prev%tmp% := prev%tmp2%
  109.         sumPrev += prev%tmp%
  110.     }
  111.     prev1 := round(GetPrimal(prevZone, zone), 1)
  112.    
  113.     loop % numIntervals ; if all 'Recent:' intervals are over the 'Current:' creates a new suggest maxCurrent value
  114.     {
  115.         if (prev%A_Index% < maxCurrent)
  116.             break
  117.         if (A_Index = numIntervals)
  118.             suggestedCurrent := (round(prev1 * 1.15) > suggestedCurrent) ? round(prev1 * 1.15) : suggestedCurrent
  119.     }
  120.     sumPrev += prev1
  121.     averagePrev := round(sumPrev / numIntervals, 1)
  122.     sum += prev1, sumSinceLastAscension += prev1
  123.     i++, j++
  124.     average := round(sum / i, 1), averageSinceLastAscension := round(sumSinceLastAscension / j, 1)
  125.  
  126.     if (zone < playSoundBelowZone and zone > 100 and timeInterval / (zone - prevZone) > 2.6 and A_TickCount - lastSound > 15000 and A_TickCount - st > 30000) ; plays sound if slowing down
  127.     {
  128.         lastSound := A_TickCount
  129.         SoundPlay *48
  130.         SoundPlay *64
  131.     }
  132.  
  133.     storage := zone + round((A_TickCount - st) / 1000) / 100000 ; XGraph only allows one number to be stored so we sneak two in by using the decminal for time and non decimal section for the zone
  134.     XGraph_Plot(pGraph, height - round(prev1 * height / maxCurrent), storage)
  135.     SB_SetText("Current: " prev1, 1), SB_SetText("Recent: " averagePrev, 2), SB_SetText("Ascension: " averageSinceLastAscension, 3), SB_SetText("Total: " average, 4)
  136.     if suggestedCurrent
  137.         SB_SetText("Press F2 to reload with the suggested new maxCurrent value: " suggestedCurrent, 7)
  138.     prevZone := zone
  139. Return
  140.  
  141. GetZone()
  142. {
  143.     loop 30
  144.     {
  145.         WinGetTitle, Title, Lvl
  146.         zone := SubStr(Title, 5, InStr(Title, "-") - 6)
  147.         if zone is integer
  148.             return zone
  149.         sleep 1
  150.     }
  151.     return 0
  152. }
  153.  
  154. GetPrimal(a, b)
  155. {
  156.     reward := 0
  157.     if (a < 95)
  158.         return 0
  159.     loop % b - a
  160.     {
  161.         if (a + A_Index - 1 > 99)
  162.             reward += round(((a + A_Index - 81) / 25) ** 1.3 / 5, 1)
  163.     }
  164.     return reward
  165. }
  166.  
  167. WM_PAINT()
  168. {
  169.     global
  170.     sleep 1
  171.     WinGet, activeID, ID, A
  172.     if (activeID = winID)
  173.         XGraph_Plot(pGraph)
  174. }
  175.  
  176. ~F1::
  177.     WinGet, activeID, ID, A
  178.     if (activeID = winID)
  179.         MsgBox, %helpText%
  180. Return
  181.  
  182. ~F2::
  183.     WinGet, activeID, ID, A
  184.     if (activeID = winID and suggestedCurrent)
  185.     {
  186.         IniWrite, %suggestedCurrent%, HSGraph.ini, HSGraph, maxCurrent
  187.         reload
  188.     }
  189. Return
  190.  
  191. GuiClose:
  192.     pGraph := XGraph_Detach(pGraph)
  193.     OnExit
  194.     ExitApp
  195.    
  196. ;storage := zone + round((A_TickCount - st) / 1000) / 100000
  197. XGraph_GetVal:
  198.     tempGetVal := XGraph_GetVal(pGraph)
  199.     zoneValue := floor(tempGetVal)
  200.     timeValue := round((tempGetVal - zoneValue) * 100000)
  201.     ; If (Col := ErrorLevel)
  202.    SB_SetText("`Time: " timeValue "s", 5 ), SB_SetText("Zone: " zoneValue, 6)
  203. return
  204.  
  205.  
  206. /*
  207.      __    __  __          __ __       __    __                 _       __                  
  208.     / /_  / /_/ /_____  _ / // /____ _/ /_  / /________________(_)___  / /_ ____  _______
  209.    / __ \/ __/ __/ __ \(_) // // __ '/ __ \/ //_/ ___/ ___/ __/ / __ \/ __// __ \/ __/ _ \    
  210.   / / / / /_/ /_/ /_/ / / // // /_/ / / / / ,< (__  ) /__/ / / / /_/ / /__/ /_/ / / / // /
  211.  /_/ /_/\__/\__/ .___(_) // / \__,_/_/ /_/_/|_/____/\___/_/ /_/ .___/\__(_)____/_/  \__ /  
  212.               /_/     /_//_/                                 /_/                   (___/  
  213.              
  214.   Script      :  XGraph v1.1.1.0 : Real time data plotting.
  215.                  http://ahkscript.org/boards/viewtopic.php?t=3492
  216.                  Created: 24-Apr-2014,  Last Modified: 09-May-2014
  217.  
  218.   Description :  Easy to use, Light weight, fast, efficient GDI based function library for
  219.                  graphically plotting real time data.
  220.  
  221.   Author      :  SKAN - Suresh Kumar A N ( [email protected] )
  222.   Demos       :  CPU Load Monitor > http://ahkscript.org/boards/viewtopic.php?t=3413
  223.  
  224. - -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
  225. */
  226.  
  227. XGraph( hCtrl, hBM := 0, ColumnW := 3, LTRB := "0,2,0,2", PenColor := 0x808080, PenSize := 1, SV := 0 ) {
  228. Static WM_SETREDRAW := 0xB, STM_SETIMAGE := 0x172, PS_SOLID := 0, cbSize := 136, SRCCOPY := 0x00CC0020
  229.      , GPTR := 0x40, OBJ_BMP := 0x7, LR_CREATEDIBSECTION := 0x2000, LR_COPYDELETEORG := 0x8
  230.  
  231. ; Validate control  
  232.   WinGetClass, Class,   ahk_id %hCtrl%  
  233.   Control, Style, +0x5000010E,, ahk_id %hCtrl%
  234.   ControlGet, Style, Style,,, ahk_id %hCtrl%
  235.   ControlGet, ExStyle, ExStyle,,, ahk_id %hCtrl%
  236.   ControlGetPos,,, CtrlW, CtrlH,, ahk_id %hCtrl%
  237.   If not ( Class == "Static" and Style = 0x5000010E and ExStyle = 0 and CtrlW > 0 and CtrlH > 0 )
  238.      Return 0, ErrorLevel := -1
  239.  
  240. ; Validate Bitmap
  241.   If ( DllCall( "GetObjectType", "Ptr",hBM ) <> OBJ_BMP )
  242.        hTargetBM := DllCall( "CreateBitmap", "Int",2, "Int",2, "UInt",1, "UInt",16, "Ptr",0, "Ptr" )
  243.     ,  hTargetBM := DllCall( "CopyImage", "Ptr",hTargetBM, "UInt",0, "Int",CtrlW, "Int",CtrlH
  244.                            , "UInt",LR_CREATEDIBSECTION|LR_COPYDELETEORG, "Ptr" )
  245.   else hTargetBM := hBM  
  246.  
  247.   VarSetCapacity( BITMAP,32,0 )    
  248.   DllCall( "GetObject", "Ptr",hTargetBM, "Int",( A_PtrSize = 8 ? 32 : 24 ), "Ptr",&BITMAP )
  249.   If NumGet( BITMAP, 18, "UInt" ) < 16 ; Checking if BPP < 16  
  250.      Return 0, ErrorLevel := -2
  251.   Else BitmapW := NumGet( BITMAP,  4, "UInt" ),  BitmapH := NumGet( BITMAP, 8, "UInt" )    
  252.   If ( BitmapW <> CtrlW or BitmapH <> CtrlH )              
  253.      Return 0, ErrorLevel := -3
  254.  
  255. ; Validate Margins and Column width  
  256.   StringSplit, M, LTRB, `, , %A_Space% ; Left,Top,Right,Bottom
  257.   MarginL := ( M1+0 < 0 ? 0 : M1 ),    MarginT     := ( M2+0 < 0 ? 0 : M2 )
  258.   MarginR := ( M3+0 < 0 ? 0 : M3 ),    MarginB     := ( M4+0 < 0 ? 0 : M4 )  
  259.   ColumnW := ( ColumnW+0 < 0 ? 3 : ColumnW & 0xff ) ; 1 - 255
  260.  
  261. ; Derive Columns, BitBlt dimensions, Movement coords for Lineto() and MoveToEx()  
  262.   Columns := ( BitmapW - MarginL - MarginR ) // ColumnW
  263.   BitBltW := Columns * ColumnW,                BitBltH := BitmapH - MarginT - MarginB
  264.   MX1     := BitBltW - ColumnW,                    MY1 := BitBltH - 1
  265.   MX2     := MX1 + ColumnW - ( PenSize < 1 ) ;     MY2 := < user defined >
  266.  
  267. ; Initialize Memory Bitmap
  268.   hSourceDC  := DllCall( "CreateCompatibleDC", "Ptr",0, "Ptr" )
  269.   hSourceBM  := DllCall( "CopyImage", "Ptr",hTargetBM, "UInt",0, "Int",ColumnW * 2 + BitBltW
  270.                        , "Int",BitBltH, "UInt",LR_CREATEDIBSECTION, "Ptr" )  
  271.   DllCall( "SaveDC", "Ptr",hSourceDC )
  272.   DllCall( "SelectObject", "Ptr",hSourceDC, "Ptr",hSourceBM )
  273.  
  274.   hTempDC    := DllCall( "CreateCompatibleDC", "Ptr",0, "Ptr" )
  275.   DllCall( "SaveDC", "Ptr",hTempDC )
  276.   DllCall( "SelectObject", "Ptr",hTempDC, "Ptr",hTargetBM )
  277.  
  278.   If ( hTargetBM <> hBM )
  279.     hBrush := DllCall( "CreateSolidBrush", UInt,hBM & 0xFFFFFF, "Ptr" )
  280.   , VarSetCapacity( RECT, 16, 0 )
  281.   , NumPut( BitmapW, RECT, 8, "UInt" ),  NumPut( BitmapH, RECT,12, "UInt" )
  282.   , DllCall( "FillRect", "Ptr",hTempDC, "Ptr",&RECT, "Ptr",hBrush )
  283.   , DllCall( "DeleteObject", "Ptr",hBrush )
  284.  
  285.   DllCall( "BitBlt", "Ptr",hSourceDC, "Int",ColumnW * 2, "Int",0, "Int",BitBltW, "Int",BitBltH
  286.                    , "Ptr",hTempDC,   "Int",MarginL, "Int",MarginT, "UInt",SRCCOPY )
  287.   DllCall( "BitBlt", "Ptr",hSourceDC, "Int",0, "Int",0, "Int",BitBltW, "Int",BitBltH
  288.                    , "Ptr",hTempDC,   "Int",MarginL, "Int",MarginT, "UInt",SRCCOPY )
  289.  
  290. ; Validate Pen color / Size                                                                    
  291.   PenColor   := ( PenColor + 0 <> "" ? PenColor & 0xffffff : 0x808080 ) ; Range: 000000 - ffffff
  292.   PenSize    := ( PenSize  + 0 <> "" ? PenSize & 0xf : 1 )              ; Range: 0 - 15                
  293.   hSourcePen := DllCall( "CreatePen", "Int",PS_SOLID, "Int",PenSize, "UInt",PenColor, "Ptr" )
  294.   DllCall( "SelectObject", "Ptr",hSourceDC, "Ptr",hSourcePen )
  295.   DllCall( "MoveToEx", "Ptr",hSourceDC, "Int",MX1, "Int",MY1, "Ptr",0 )
  296.  
  297.   hTargetDC := DllCall( "GetDC", "Ptr",hCtrl, "Ptr" )
  298.   DllCall( "BitBlt", "Ptr",hTargetDC, "Int",0, "Int",0, "Int",BitmapW, "Int",BitmapH
  299.                    , "Ptr",hTempDC,   "Int",0, "Int",0, "UInt",SRCCOPY )
  300.  
  301.   DllCall( "RestoreDC", "Ptr",hTempDC, "Int",-1 )
  302.   DllCall( "DeleteDC",  "Ptr",hTempDC )    
  303.  
  304.   DllCall( "SendMessage", "Ptr",hCtrl, "UInt",WM_SETREDRAW, "Ptr",False, "Ptr",0 )
  305.   hOldBM := DllCall( "SendMessage", "Ptr",hCtrl, "UInt",STM_SETIMAGE, "Ptr",0, "Ptr",hTargetBM )    
  306.   DllCall( "SendMessage", "Ptr",hCtrl, "UInt",WM_SETREDRAW, "Ptr",True,  "Ptr",0 )
  307.   DllCall( "DeleteObject", "Ptr",hOldBM )
  308.  
  309. ; Create / Update Graph structure
  310.   DataSz := ( SV = 1 ? Columns * 8 : 0 )
  311.   pGraph := DllCall( "GlobalAlloc", "UInt",GPTR, "Ptr",cbSize + DataSz, "UPtr" )
  312.   NumPut( DataSz, pGraph + cbSize - 8   )    
  313.   VarL := "cbSize / hCtrl / hTargetDC / hSourceDC / hSourceBM / hSourcePen / ColumnW / Columns / "
  314.         . "MarginL / MarginT / MarginR / MarginB / MX1 / MX2 / BitBltW / BitBltH"
  315.   Loop, Parse, VarL, /, %A_Space%
  316.     NumPut( %A_LoopField%, pGraph + 0, ( A_Index - 1 ) * 8 )
  317.  
  318. Return pGraph          
  319. }
  320.  
  321. ; -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
  322.  
  323. XGraph_Info( pGraph, FormatFloat := "" ) {
  324. Static STM_GETIMAGE := 0x173
  325.   IfEqual, pGraph, 0, Return "",    ErrorLevel := -1
  326.   T := "`t",  TT := "`t:`t",  LF := "`n", SP := "                "
  327.  
  328.   pData := pGraph + NumGet( pGraph + 0 ), DataSz := Numget( pData-8 )
  329.   If ( FormatFloat <> "" and DataSz )
  330.     GoTo, XGraph_Info_Data  
  331.  
  332.   VarL := "cbSize / hCtrl / hTargetDC / hSourceDC / hSourceBM / hSourcePen / ColumnW / Columns / "
  333.         . "MarginL / MarginT / MarginR / MarginB / MX1 / MX2 / BitBltW / BitBltH"
  334.   Loop, Parse, VarL, /, %A_Space%
  335.     Offset := ( A_Index - 1 ) * 8,         %A_LoopField% := NumGet( pGraph + 0, OffSet )
  336.   , RAW    .= SubStr( Offset SP,1,3 ) T SubStr( A_LoopField SP,1,16 ) T %A_LoopField% LF
  337.  
  338.   hTargetBM := DllCall( "SendMessage", "Ptr",hCtrl, "UInt",STM_GETIMAGE, "Ptr",0, "Ptr",0 )
  339.   VarSetCapacity( BITMAP,32,0 )
  340.   DllCall( "GetObject", "Ptr",hTargetBM, "Int",( A_PtrSize = 8 ? 32 : 24 ), "Ptr",&BITMAP )
  341.   TBMW := NumGet( BITMAP,  4, "UInt" ),            TBMH := NumGet( BITMAP, 8, "UInt" )
  342.   TBMB := NumGet( BITMAP, 12, "UInt" ) * TBMH,     TBMZ := Round( TBMB/1024,2 )
  343.   TBPP := NumGet( BITMAP, 18, "UShort" )
  344.   Adj := ( Adj := TBMW - MarginL - BitBltW - MarginR ) ? " (-" Adj ")" : ""
  345.  
  346.   DllCall( "GetObject", "Ptr",hSourceBM, "Int",( A_PtrSize = 8 ? 32 : 24 ), "Ptr",&BITMAP )
  347.   SBMW := NumGet( BITMAP,  4, "UInt" ),            SBMH := NumGet( BITMAP, 8, "UInt" )
  348.   SBMB := NumGet( BITMAP, 12, "UInt" ) * SBMH,     SBMZ := Round( SBMB/1024,2 )
  349.   SBPP := NumGet( BITMAP, 18, "UShort" )
  350.    
  351. Return "GRAPH Properties" LF LF
  352.  . "Screen BG Bitmap   " TT TBMW ( Adj ) "x" TBMH " " TBPP "bpp ( " TBMZ " KB )" LF
  353.  . "Margins ( L,T,R,B )" TT MarginL "," MarginT "," MarginR "," MarginB LF
  354.  . "Client Area        " TT MarginL "," MarginT "," MarginL+BitBltW-1 "," MarginT+BitBltH-1 LF LF
  355.  . "Memory Bitmap      " TT SBMW         "x" SBMH " " SBPP "bpp ( " SBMZ " KB )" LF
  356.  . "Graph Width        " TT BitBltW " px ( " Columns " cols x " ColumnW " px )" LF
  357.  . "Graph Height (MY2) " TT BitBltH " px ( y0 to y" BitBltH - 1 " )" LF  
  358.  . "Graph Array        " TT ( DataSz=0 ? "NA" : Columns " cols x 8 bytes = " DataSz " bytes" ) LF LF
  359.  . "Pen start position " TT MX1 "," BitBltH - 1 LF
  360.  . "LineTo position    " TT MX2 "," "MY2" LF
  361.  . "MoveTo position    " TT MX1 "," "MY2" LF LF
  362.  . "STRUCTURE ( Offset / Variable / Raw value )" LF LF RAW
  363.  
  364. XGraph_Info_Data:
  365.  
  366.   AFF := A_FormatFloat
  367.   SetFormat, FloatFast, %FormatFloat%
  368.   Loop % DataSz // 8  
  369.     Values .= SubStr( A_Index "   ", 1, 4  ) T NumGet( pData - 8, A_Index * 8, "Double" ) LF
  370.   SetFormat, FloatFast, %AFF%
  371.   StringTrimRight, Values, Values, 1                                                                          
  372.  
  373. Return Values      
  374. }
  375.  
  376. ; -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
  377.  
  378. XGraph_Plot( pGraph, MY2 := "", SetVal := "", Draw := 1 ) {
  379. Static SRCCOPY := 0x00CC0020
  380.  
  381.   IfEqual, pGraph, 0, Return "",    ErrorLevel := -1
  382.   pData     := pGraph + NumGet( pGraph + 0 ),     DataSz     := Numget( pData - 8 )
  383.  
  384. , hSourceDC := NumGet( pGraph + 24 ),             BitBltW    := NumGet( pGraph + 112 )    
  385. , hTargetDC := NumGet( pGraph + 16 ),             BitBltH    := NumGet( pGraph + 120 )
  386. , ColumnW   := NumGet( pGraph + 48 )          
  387.  
  388. , MarginL   := NumGet( pGraph + 64 ),             MX1 := NumGet( pGraph + 096 )
  389. , MarginT   := NumGet( pGraph + 72 ),             MX2 := NumGet( pGraph + 104 )
  390.  
  391.   If not ( MY2 = "" )                                
  392.      DllCall( "BitBlt", "Ptr",hSourceDC, "Int",0, "Int",0, "Int",BitBltW + ColumnW, "Int",BitBltH
  393.                     , "Ptr",hSourceDC, "Int",ColumnW, "Int",0, "UInt",SRCCOPY )
  394.   ,  DllCall( "LineTo",   "Ptr",hSourceDC, "Int",MX2, "Int",MY2 )
  395.   ,  DllCall( "MoveToEx", "Ptr",hSourceDC, "Int",MX1, "Int",MY2, "Ptr",0 )
  396.                    
  397.   If ( Draw = 1 )
  398.      DllCall( "BitBlt", "Ptr",hTargetDC, "Int",MarginL, "Int",MarginT, "Int",BitBltW, "Int",BitBltH
  399.                       , "Ptr",hSourceDC, "Int",0, "Int",0, "UInt",SRCCOPY )
  400.  
  401.   If not ( MY2 = "" or SetVal = "" or DataSz = 0 )
  402.      DllCall( "RtlMoveMemory", "Ptr",pData, "Ptr",pData + 8, "Ptr",DataSz - 8 )
  403.   ,  NumPut( SetVal, pData + DataSz - 8, 0, "Double" )
  404.  
  405. Return 1
  406. }
  407.  
  408. ; -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
  409.  
  410. XGraph_SetVal( pGraph, Double := 0, Column := "" ) {
  411.  
  412.   IfEqual, pGraph, 0, Return "",    ErrorLevel := -1
  413.   pData := pGraph + NumGet( pGraph + 0 ), DataSz := Numget( pData - 8 )
  414.   IfEqual, DataSz, 0, Return 0
  415.  
  416.   If ( Column = "" )
  417.        DllCall( "RtlMoveMemory", "Ptr",pData, "Ptr",pData + 8, "Ptr",DataSz - 8 )
  418.      , pNumPut := pData + DataSz
  419.   else Columns := NumGet( pGraph + 56 )
  420.      , pNumPut := pData + ( Column < 0 or Column > Columns ? Columns * 8 : Column * 8 )
  421.  
  422. Return NumPut( Double, pNumPut - 8, 0, "Double" ) - 8      
  423. }
  424.  
  425. ; -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
  426.  
  427. XGraph_GetVal( pGraph, Column := "" ) {
  428. Static RECT
  429.   If not VarSetCapacity( RECT )
  430.          VarSetCapacity( RECT, 16, 0 )
  431.  
  432.   IfEqual, pGraph, 0, Return "",    ErrorLevel := -1
  433.   pData   := pGraph + NumGet( pGraph + 0 ),   DataSz  := Numget( pData - 8 )
  434.   Columns := NumGet( pGraph + 56 )
  435.   If not ( Column = "" or DataSz = 0 or Column < 1 or Column > Columns )
  436.     Return NumGet( pData - 8, Column * 8, "Double" ),    ErrorLevel := Column
  437.  
  438.   hCtrl   := NumGet( pGraph + 8   ),          ColumnW := NumGet( pGraph + 48 )                      
  439. , BitBltW := NumGet( pGraph + 112 ),          MarginL := NumGet( pGraph + 64 )
  440. , BitBltH := NumGet( pGraph + 120 ),          MarginT := NumGet( pGraph + 72 )
  441.  
  442. , Numput( MarginL, RECT, 0, "Int" ),          Numput( MarginT, RECT, 4, "Int" )
  443. , DllCall( "ClientToScreen", "Ptr",hCtrl, "Ptr",&RECT )
  444. , DllCall( "GetCursorPos", "Ptr",&RECT + 8 )
  445.  
  446. , MX := NumGet( RECT, 8, "Int" ) - NumGet( RECT, 0, "Int" )
  447. , MY := NumGet( RECT,12, "Int" ) - NumGet( RECT, 4, "Int" )
  448.  
  449. , Column := ( MX >= 0 and MY >= 0 and MX < BitBltW and MY < BitBltH ) ? MX // ColumnW + 1 : 0
  450. Return ( DataSz and Column ) ? NumGet( pData - 8, Column * 8, "Double" ) : "",    ErrorLevel := Column  
  451. }
  452.  
  453. ; -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
  454.  
  455. XGraph_GetMean( pGraph, TailCols := "" ) {
  456.  
  457.   IfEqual, pGraph, 0, Return "",    ErrorLevel := -1
  458.   pData := pGraph + NumGet( pGraph + 0 ), DataSz := Numget( pData - 8 )
  459.   IfEqual, DataSz, 0, Return 0,     ErrorLevel := 0
  460.  
  461.   Columns := NumGet( pGraph + 56 )
  462.   pDataEnd := pGraph + NumGet( pGraph + 0 ) + ( Columns * 8 )
  463.   TailCols := ( TailCols = "" or TailCols < 1 or Tailcols > Columns ) ? Columns : TailCols
  464.  
  465.   Loop %TailCols%
  466.     Value += NumGet( pDataEnd - ( A_Index * 8 ), 0, "Double"  )
  467.  
  468. Return Value / TailCols,            ErrorLevel := TailCols
  469. }
  470.  
  471. ; -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
  472.  
  473. XGraph_Detach( pGraph ) {
  474.   IfEqual, pGraph, 0, Return 0
  475.  
  476.   VarL := "cbSize / hCtrl / hTargetDC / hSourceDC / hSourceBM / hSourcePen"
  477.   Loop, Parse, VarL, /, %A_Space%
  478.     %A_LoopField% := NumGet( pGraph + 0, ( A_Index - 1 ) * 8 )
  479.  
  480.   DllCall( "ReleaseDC",    "Ptr",hCtrl, "Ptr",hTargetDC )
  481.   DllCall( "RestoreDC",    "Ptr",hSourceDC, "Int",-1  )
  482.   DllCall( "DeleteDC",     "Ptr",hSourceDC  )
  483.   DllCall( "DeleteObject", "Ptr",hSourceBM  )              
  484.   DllCall( "DeleteObject", "Ptr",hSourcePen )
  485.  
  486. Return DllCall( "GlobalFree", "Ptr",pGraph, "Ptr"  )  
  487. }
  488.  
  489. ; -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
  490.  
  491. XGraph_MakeGrid(  CellW, CellH, Cols, Rows, GLClr, BGClr, ByRef BMPW := "", ByRef BMPH := "" ) {
  492. Static LR_Flag1 := 0x2008 ; LR_CREATEDIBSECTION := 0x2000 | LR_COPYDELETEORG := 8
  493.     ,  LR_Flag2 := 0x200C ; LR_CREATEDIBSECTION := 0x2000 | LR_COPYDELETEORG := 8 | LR_COPYRETURNORG := 4
  494.     ,  DC_PEN := 19
  495.  
  496.   BMPW := CellW * Cols + 1,  BMPH := CellH * Rows + 1
  497.   hTempDC := DllCall( "CreateCompatibleDC", "Ptr",0, "Ptr" )
  498.   DllCall( "SaveDC", "Ptr",hTempDC )
  499.  
  500.   If ( DllCall( "GetObjectType", "Ptr",BGClr ) = 0x7 )
  501.     hTBM := DllCall( "CopyImage", "Ptr",BGClr, "Int",0, "Int",BMPW, "Int",BMPH, "UInt",LR_Flag2, "UPtr" )
  502.   , DllCall( "SelectObject", "Ptr",hTempDC, "Ptr",hTBM )
  503.  
  504.   Else
  505.     hTBM := DllCall( "CreateBitmap", "Int",2, "Int",2, "UInt",1, "UInt",24, "Ptr",0, "Ptr" )
  506.   , hTBM := DllCall( "CopyImage", "Ptr",hTBM,  "Int",0, "Int",BMPW, "Int",BMPH, "UInt",LR_Flag1, "UPtr" )
  507.   , DllCall( "SelectObject", "Ptr",hTempDC, "Ptr",hTBM )
  508.   , hBrush := DllCall( "CreateSolidBrush", "UInt",BGClr & 0xFFFFFF, "Ptr" )
  509.   , VarSetCapacity( RECT, 16 )
  510.   , NumPut( BMPW, RECT, 8, "UInt" ),  NumPut( BMPH, RECT, 12, "UInt" )
  511.   , DllCall( "FillRect", "Ptr",hTempDC, "Ptr",&RECT, "Ptr",hBrush )
  512.   , DllCall( "DeleteObject", "Ptr",hBrush )
  513.  
  514.   hPenDC := DllCall( "GetStockObject", "Int",DC_PEN, "Ptr" )
  515.   DllCall( "SelectObject",  "Ptr",hTempDC, "Ptr",hPenDC )
  516.   DllCall( "SetDCPenColor", "Ptr",hTempDC, "UInt",GLClr & 0xFFFFFF )
  517.  
  518.   Loop, % Rows + 1 + ( X := Y := 0 )  
  519.     DllCall( "MoveToEx", "Ptr",hTempDC, "Int",X,    "Int",Y, "Ptr",0  )
  520.   , DllCall( "LineTo",   "Ptr",hTempDC, "Int",BMPW, "Int",Y ),  Y := Y + CellH
  521.  
  522.   Loop, % Cols + 1 + ( X := Y := 0 )
  523.     DllCall( "MoveToEx", "Ptr",hTempDC, "Int",X, "Int",Y, "Ptr",0 )
  524.   , DllCall( "LineTo",   "Ptr",hTempDC, "Int",X, "Int",BMPH ),  X := X + CellW
  525.  
  526.   DllCall( "RestoreDC", "Ptr",hTempDC, "Int",-1 )
  527.   DllCall( "DeleteDC",  "Ptr",hTempDC )    
  528.  
  529. Return hTBM
  530. }
  531.  
  532. ; -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement