ScreenRuler

  • soo, jetzt auch mal ein Projekt von mir ;)
    ...nur ein kleines, was mir oft bei anderen Sachen hilft...

    es handelt sich um eine Art "Bildschirm-Lineal", mit dem man Sachen markieren kann - und man bekommt Informationen wie Breite, x-Position, y-Position und Höhe angezeigt.
    Oft nützlich bei Web-Design und GUI-Erstellung, wenn es auf Pixelgenaue Platzierungen ankommt ;)

    Bedienung:
    F10 blendet ScreenRuler ein und aus (Bleibt im Hintergrund/Tray)
    ESC beendet ScreenRuler

    nun kurz ein paar Wörter über den Code:
    ich verwende GUIPlus um aus einem JPG-Farbspektrum einen Array zu erstellen, bei Mausbewegungen ändern die Anzeigen im ScreenRuler die Farben ;)
    Um das Tool möglichst portabel zu machen, wird das JPG-Farbspektrum mit "resources.au3" in den Quellcode eingebunden -> die wunderschönen Farbeffekte gibts nur nach dem compilen ;)

    Spoiler anzeigen
    [autoit]

    #Region ;**** Directives created by AutoIt3Wrapper_GUI ****
    #AutoIt3Wrapper_icon=ScreenRuler.ico
    #AutoIt3Wrapper_outfile=ScreenRuler_v10.exe
    #AutoIt3Wrapper_UseX64=n
    #AutoIt3Wrapper_Res_File_Add=spectrum.jpg, rt_rcdata, SPECTRUM_JPG
    #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <Misc.au3>
    #include <GDIPlus.au3>
    #include <Array.au3>
    #include "resources.au3"

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $version=1.0

    [/autoit] [autoit][/autoit] [autoit]

    #cs
    README:

    [/autoit] [autoit][/autoit] [autoit]

    Das Icon ist GPL, von Alessandro Rei
    resources.au3 gibts bei: ;get it from here: http://www.autoitscript.com/forum/topic/51103-resources-udf/
    ich weiß nicht mehr wo ich die funktion _GDIPlus_BitmapGetPixel her hab....könnt ihr mir helfen?

    [/autoit] [autoit][/autoit] [autoit]

    KNOWN BUGS:
    * die beiden labels flackern....
    * ab und zu stürzt das Programm ab (4% der Fälle) mit "Subscript used with non-Array variable" - deshalb die vielen MsgBoxes überall wo ich Arrays verwende...
    wenn es bei euch abstürzt, sagt mir bitte wo ;)

    [/autoit] [autoit][/autoit] [autoit]

    (c) 2011 by r4lf von autoit.de

    [/autoit] [autoit][/autoit] [autoit]

    #ce

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Opt("MouseCoordMode",2)
    HotKeySet("{ESC}","myshutdown")
    HotKeySet("{F10}","toggleme")

    [/autoit] [autoit][/autoit] [autoit]

    Func toggleme()
    Global $shown
    If $shown=1 Then
    GUISetState(@SW_HIDE)
    $shown=0
    Else
    GUISetState(@SW_SHOW)
    $shown=1
    EndIf
    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func myshutdown()
    Exit
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Global $left,$top,$width,$height,$mousepressed, $shown,$pointer, $colorArray
    $mousepressed=0
    $shown=1

    [/autoit] [autoit][/autoit] [autoit]

    $left=105
    $top=100
    $width=229
    $height=124
    $pointer=0

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ;#########################################################################################################################
    ; Farbinformationen aus Farbspektrum in Array lesen
    _GDIPlus_Startup()
    $hImage=_ResourceGetAsImage("SPECTRUM_JPG")

    [/autoit] [autoit][/autoit] [autoit]

    $iPosY = 10
    $xfrom=0
    $xto=300-1

    [/autoit] [autoit][/autoit] [autoit]

    Dim $colorArray[1]=[0]

    [/autoit] [autoit][/autoit] [autoit]

    For $n=$xfrom To $xto
    $c=_GDIPlus_BitmapGetPixel($hImage, $n, $iPosY)
    _ArrayAdd($colorArray,$c)
    Next
    _ArrayDelete($colorArray,0)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_ShutDown()
    ;#########################################################################################################################

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    #include <GUIConstants.au3>

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $Form1 = GUICreate("ScreenRuler", @DesktopWidth, @DesktopHeight, 0, 0, BitOR($WS_MINIMIZEBOX,$WS_SYSMENU,$WS_POPUP,$WS_GROUP,$WS_CLIPSIBLINGS), BitOR($WS_EX_TOPMOST,$WS_EX_WINDOWEDGE))
    WinSetTrans("ScreenRuler","",127)
    GUISetBkColor(0xFFFFFF)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $LabelInfo = GUICtrlCreateLabel("left:105 top:100 width:229 height:124", 0, @DesktopHeight-27,@DesktopWidth, 27)
    GUICtrlSetFont(-1, 15, 400, 0, "Arial")
    GUICtrlSetColor(-1, 0xFFFFFF)
    GUICtrlSetBkColor(-1,0x08440B)
    $LabelBox = GUICtrlCreateLabel("", 105, 100, 229, 124)
    GUICtrlSetBkColor(-1,0x08440B)
    GUISetState(@SW_SHOW)

    [/autoit] [autoit][/autoit] [autoit]

    $lastpressed=0
    $move=0

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func getNextColor()
    Global $pointer,$colorArray
    If Not IsArray($colorArray) Then
    MsgBox(16,"ERROR",'$colorArray is not an array o_O"')
    EndIf
    $c=$colorArray[$pointer]
    $pointer+=1
    If $pointer=300 Then $pointer=0
    Return $c
    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    While 1
    If $shown=1 Then
    If $lastpressed=0 Then
    If _IsPressed(01) Then
    $lastpressed=1
    $i=GUIGetCursorInfo()
    If IsArray($i) And $i[4]=$LabelBox Then
    ;move the box
    $move=1
    $rel=MouseGetPos()
    If Not IsArray($rel) Then MsgBox(16,"ERROR","MOUSE POSITION ERROR. - rel")
    $relx1=$rel[0]
    $rely1=$rel[1]
    $relx=$relx1-$left
    $rely=$rely1-$top
    Else
    $mousepressed=1
    $startpos=MouseGetPos()
    If Not IsArray($startpos) Then MsgBox(16,"ERROR","MOUSE POSITION ERROR. - startpos")
    $left=$startpos[0]
    $top=$startpos[1]
    GUICtrlSetPos($LabelBox,$left,$top,1,1)
    $move=0
    EndIf
    EndIf
    Else
    If Not _IsPressed(01) Then
    $lastpressed=0
    primup()
    Else
    updateInfo()
    If $move=1 Then
    ;move the field
    $p=MouseGetPos()
    If Not IsArray($p) Then MsgBox(16,"ERROR","MOUSE POSITION ERROR. - p")
    $left=$p[0]-$relx
    $top=$p[1]-$rely
    GUICtrlSetPos($LabelBox,$left,$top)
    Else
    ;draw the field
    $pos=MouseGetPos()
    If Not IsArray($pos) Then MsgBox(16,"ERROR","MOUSE POSITION ERROR. - pos")
    $mx=$pos[0]
    $my=$pos[1]
    $width=$mx-$left
    $height=$my-$top

    [/autoit] [autoit][/autoit] [autoit]

    If $width>0 And $height>0 Then
    ;quadrant 4
    GUICtrlSetPos($LabelBox,$left,$top,$width,$height)
    ElseIf $width>0 And $height<0 Then
    ;quadrant 1
    $mheight=-$height
    $mtop=$my
    GUICtrlSetPos($LabelBox,$left,$mtop,$width,$mheight)
    ElseIf $width<0 And $height>0 Then
    ;quadrant 3
    $mwidth=-$width
    $mleft=$mx
    GUICtrlSetPos($LabelBox,$mleft,$top,$mwidth,$height)
    ElseIf $width<0 And $height<0 Then
    ;quadrant 2
    $mwidth=-$width
    $mleft=$mx
    $mheight=-$height
    $mtop=$my
    GUICtrlSetPos($LabelBox,$mleft,$mtop,$mwidth,$mheight)
    Else
    GUICtrlSetPos($LabelBox,$left,$top,1,1)
    EndIf
    EndIf
    EndIf

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    EndIf
    EndIf ;shown

    [/autoit] [autoit][/autoit] [autoit]

    WEnd

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func updateInfo()

    [/autoit] [autoit][/autoit] [autoit]

    If $width>0 And $height>0 Then
    ;quadrant 4
    $s="left:"&$left&" top:"&$top&" width:"&$width&" height:"&$height
    ElseIf $width>0 And $height<0 Then
    ;quadrant 1
    $mheight=-$height
    $mtop=$my
    $s="left:"&$left&" top:"&$mtop&" width:"&$width&" height:"&$mheight
    ElseIf $width<0 And $height>0 Then
    ;quadrant 3
    $mwidth=-$width
    $mleft=$mx
    $s="left:"&$mleft&" top:"&$top&" width:"&$mwidth&" height:"&$height
    ElseIf $width<0 And $height<0 Then
    ;quadrant 2
    $mwidth=-$width
    $mleft=$mx
    $mheight=-$height
    $mtop=$my
    $s="left:"&$mleft&" top:"&$mtop&" width:"&$mwidth&" height:"&$mheight
    Else
    $s="left:"&$left&" top:"&$top&" width:"&Abs($width)&" height:"&Abs($height)
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    If GUICtrlRead($LabelInfo) <> $s Then
    GUICtrlSetData($LabelInfo,$s)
    $newc=getNextColor()
    GUICtrlSetBkColor($LabelBox,$newc)
    GUICtrlSetBkColor($LabelInfo,$newc)
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func primup()
    $mousepressed=0

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    If $width>0 And $height>0 Then
    ;quadrant 4
    ElseIf $width>0 And $height<0 Then
    ;quadrant 1
    $top=$top+$height
    $height=Abs($height)
    ElseIf $width<0 And $height>0 Then
    ;quadrant 3
    $left=$left+$width
    $width=Abs($width)
    ElseIf $width<0 And $height<0 Then
    ;quadrant 2
    $top=$top+$height
    $height=Abs($height)
    $left=$left+$width
    $width=Abs($width)

    [/autoit] [autoit][/autoit] [autoit]

    Else

    [/autoit] [autoit][/autoit] [autoit]

    EndIf

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func primmove()
    If $mousepressed=1 Then
    $pos=MouseGetPos()
    If Not IsArray($pos) Then MsgBox(16,"ERROR","MOUSE POSITION ERROR. - pos primmove")
    $mx=$pos[0]
    $my=$pos[1]
    $width=$mx-$left
    $height=$my-$top
    GUICtrlSetPos($LabelBox,$left,$top,$width,$height)
    EndIf
    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _GDIPlus_BitmapGetPixel($hBitmap, $iX, $iY)
    ;ich weiß nicht mehr wo ich diese funktion her hab...wisst ihr das? -.-
    Local $tArgb, $pArgb, $aRet
    $tArgb = DllStructCreate("dword Argb")
    $pArgb = DllStructGetPtr($tArgb)
    $aRet = DllCall($ghGDIPDll, "int", "GdipBitmapGetPixel", "hwnd", $hBitmap, "int", $iX, "int", $iY, "ptr", $pArgb)
    Return "0x" & Hex(DllStructGetData($tArgb, "Argb"), 6)
    EndFunc

    [/autoit]

    Inhalt der .zip:
    * JPG-Farbspektrum
    * Icon-Datei [GPL]
    * resources.au3 [ von http://www.autoitscript.com/forum/topic/51103-resources-udf/]


    bitte helft mir mit weiteren Ideen und Anregungen ;)

    viele Grüße,
    r4lf

    //Edit: @DesktopWidth und @DesktopHeight benutzt, Danke an Mattthias!

  • Hallo r4lf, ansich eine schöne Sache, setze die Fenstergröße doch bitte auf @DesktopWidth & @DesktopHeight sodass es bei jedem kompatibel ist.
    €: Zudem bietet sich der Backbuffer an, dann "flackert" es nicht so, MfG

    Es gibt sehr viele Leute, die glauben. Aber aus Aberglauben.
    - Blaise Pascal

  • ach verdammt, sry, das hab ich übersehen.... -> das edite ich gleich mal

    und das mit dem backbuffer... oO ...das geht doch nur bei GDI+, oder?
    grüße,
    r4lf

  • Ich habe leider nicht gesehen was du verwendet hast, dachte es wöre bereits GDI+ 0.ô
    €: Danke für das Update ABER du musst die Leiste natürlich auch nach unten rechts bewegen ^^

    Es gibt sehr viele Leute, die glauben. Aber aus Aberglauben.
    - Blaise Pascal

  • -.- verdammt, was kann ich eigentlich....danke ;)
    der code ist jetzt im post, dann müsst ihr nicht immer die zip runterladen, in der zip sind jetzt nur spektrum, icon und resources.au3....

    NOCH hab ich nicht viel Ahnung von GDI+, kommt aber noch ;)

    grüße