Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;****************************************************************************************************************************************************************************
- #Include c:\pradeep\gdip.autohotkey ;<My Altered GDIP lib> ;<<<<<<<<<<<<<<<<<<--------------------------- gdip.ahk
- ;~ #Include <PopUpWindow_V2> ; At the bottom of the script
- ;****************************************************************************************************************************************************************************
- #SingleInstance, Force
- SetBatchLines, -1
- Gdip_Startup()
- return
- *ESC::ExitApp
- ;~ RALT::PopUpWindow.Helper()
- ;*******************________________************************__________________*****************_______________*************
- ; Create a New InstaNote
- ~m & n::
- CoordMode, Mouse, Screen
- MouseGetPos, x , y
- obj := { X: x , Y: y , FontSize: 20 }
- New InstaNote( obj )
- return
- ;*******************________________************************__________________*****************_______________*************
- ; Create a New InstaNote from your Clipboard ( text )
- ;!c::
- CoordMode, Mouse, Screen
- MouseGetPos, x , y
- obj := { X: x
- , Y: y
- , FontSize: 16
- , Color: "0xFFCDCDCD"
- , BorderColor: "0xFF000000"
- , FontColor: "0xFF000000"
- , Font: "Comic Sans MS" }
- New InstaNote( obj , Option := 1 )
- return
- ;*******************________________************************__________________*****************_______________*************
- ; Copy the InstaNote into your Clipboard ( text )
- ;!v::
- InstaNote.SetClipboard()
- return
- ;*******************________________************************__________________*****************_______________*************
- ; Create a New Google Search InstaNote
- #s::
- CoordMode, Mouse, Screen
- MouseGetPos, x , y
- obj := { Type: "GoogleSearch" ;<<<<----------- run Google Search by closing the InstaNote or pressing enter while it is active
- , X: x
- , Y: y
- , FontSize: 32
- , Color: "0xFFFF0000"
- , BorderColor: "0xFF99FF00"
- , FontColor: "0xFFFFFF00"
- , Font: "Comic Sans MS" }
- New InstaNote( obj )
- return
- ;*******************________________************************__________________*****************_______________*************
- ; InstaNote Class
- ;####################################################################################################################################################################################
- ;####################################################################################################################################################################################
- ;####################################################################################################################################################################################
- ;####################################################################################################################################################################################
- class InstaNote {
- ;Written By: Hellbent
- ;Date Started: Mar 29th, 2022
- ;Date of last edit: Mar 29th, 2022
- ;Current Version: v1.1
- ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- ;Prototype:
- ; obj := { X: x , Y: y , FontSize: 32 , Color: "0x01999900" , BorderColor: "0xFFFF0000" , FontColor: "0xFFFFff00" , Font: "Comic Sans MS" }
- ; New InstaNote( obj , Option := 0 ) ; 0 = default , 1 = create from clipboard ( text )
- ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- static Index := 0 , Windows := [] , Handles := [] , Active := 1 , FontSize := 12 , Font := "Segoe UI"
- __New( obj := "" , Option := 0 ){
- if( !InstaNote.Index ){
- InstaNote.Bind := ObjBindMethod( InstaNote , "_LButtonHK" )
- OnMessage( 0x100 , InstaNote[ "_CaptureKeys" ].Bind( InstaNote ) )
- OnMessage( 0x205 , InstaNote[ "_CloseWindow" ].Bind( InstaNote ) )
- OnMessage( 0x201 , InstaNote[ "_MoveWindow" ].Bind( InstaNote ) )
- OnMessage( 0x020A , InstaNote[ "_WheelChange" ].Bind( InstaNote ) )
- }
- if( InstaNote.Windows[ InstaNote.Index ].Output[ 1 ] = "" ){
- InstaNote.Handles[ InstaNote.Windows[ InstaNote.Index ].Gui1.Hwnd ] := ""
- InstaNote.Windows[ InstaNote.Index ].Gui1.DeleteWindow()
- InstaNote.Windows[ InstaNote.Index ] := ""
- }
- This._SetDefaults()
- This._UpdateDefaults( obj , Option )
- This._CreateWindow()
- This._AddControls()
- This._Draw()
- This.Index := ++InstaNote.Index
- InstaNote.Windows[ InstaNote.Index ] := This
- InstaNote.Handles[ This.Gui1.Hwnd ] := This
- InstaNote.Active := This.Gui1.Hwnd
- return InstaNote.Handles[ This.Gui1.Hwnd ] , This := ""
- }
- _SetDefaults(){
- This.X := 10 , This.Y := 10
- This.W := 30 , This.H := 10
- This.LastH := 10 , This.RoundNess := 15
- This.Color := "0xFFFFFFFF" , This.BorderColor := "0xff000000"
- This.Font := InstaNote.Font , This.FontSize := InstaNote.FontSize
- This.FontOptions := " " , This.FontColor := "0xFF000000"
- This.FontColorBottom := "0x00FFFFFF" , This.MarginX := 3
- This.MarginY := 3 , This.PaddingX := 15
- This.PaddingY := 5 , This.Output := []
- This.String := [] , This.CurrentPosition := 1
- This.CurrentLine := 1 , This.LineCount := 1
- This.WindowOptions := " -DPIScale +AlwaysOnTop +ToolWindow "
- }
- _UpdateDefaults( obj := "" , option := 0 ){
- local k , v , bd
- if( IsObject( obj ) )
- for k, v in obj
- This[ k ] := obj[ k ]
- if( option = 1 )
- This._GetClipboard()
- This.TextLineHeight := This._GetTextSize( 2 )
- This.TextLineHeight += 2 * This.PaddingY
- This._GetString()
- bd := InstaNote.Bind
- Hotkey, ~LButton , % bd , On
- ;**********************
- ;~ This.RoundNess := This.TextLineHeight / 9
- This.RoundNess := This.TextLineHeight / 8
- ;**********************
- ;~ if( !obj.FontSize )
- ;~ This.FontSize := InstaNote.FontSize
- ;~ ToolTip, % obj.Type "`" This.Type
- }
- _CreateWindow(){
- This.Gui1 := New PopUpWindow( { AutoShow: 1 , X: This.X - This.W / 2 , Y: This.Y - This.H / 2 , W: This.W , H: This.H , Options: This.WindowOptions } )
- This.Active := This.Gui1.Hwnd
- Gui, % This.Gui1.Hwnd ":Show"
- }
- SetClipboard(){
- if( InstaNote.Handles[ win := InstaNote._GetWindow() ].Output )
- Clipboard := InstaNote.Handles[ win := InstaNote._GetWindow() ]._GetString()
- }
- _GetClipboard(){
- This.Output := StrSplit( clipboard , "" )
- }
- _WheelChange( input ){
- local ctrl , Dir , win
- if( This.WheelActive )
- return
- if( This.ft := !This.ft )
- return
- This.WheelActive := 1
- if( InstaNote.Handles[ win := InstaNote._GetWindow() ].FontSize ){
- Dir := ( ( input >> 16 ) > 0x7FFF ) || ( ( input < 0 ) ? ( 1 ) : ( 0 ) )
- if( Dir )
- ( GetKeyState( "Shift" ) ) ? ( InstaNote.Handles[ win ].FontSize += 10 , change := 1 ) : ( ++InstaNote.Handles[ win ].FontSize , change := 1 )
- else
- ( ( GetKeyState( "Shift" ) ? ( InstaNote.Handles[ win ].FontSize -= 10 ) : ( --InstaNote.Handles[ win ].FontSize ) ) < 1 ) ? ( InstaNote.Handles[ win ].FontSize := 1 , change := 0 ) : ( change := 1 )
- if( change ){
- InstaNote.Handles[ win ]._UpdateDefaults()
- InstaNote.Handles[ win ]._GetString()
- InstaNote.Handles[ win ]._Draw()
- }
- }
- This.WheelActive := 0
- }
- _LButtonHK(){
- bd := InstaNote.Bind
- if( ( win := InstaNote._GetWindow() ) != InstaNote.Active ){
- Hotkey, ~LButton , % bd , Off
- ;******************************************
- ;~ InstaNote.Handles[ InstaNote.Active ].BorderColor := "0xFFFF0000"
- ;******************************************
- InstaNote.Handles[ InstaNote.Active ]._Draw()
- InstaNote.Active := ""
- }
- }
- _GetWindow(){
- local win
- MouseGetPos,,, win
- return win
- }
- _Resize(){
- This.Gui1.UpdateSettings( { W: This.W , H: This.H } , UpdateGraphics := 1 )
- }
- _MoveWindow(){
- local win , x , y
- PostMessage, 0xA1 , 2
- While( GetKeyState( "LButton" ) )
- Sleep, 30
- WinGetPos, x , y ,,, % "ahk_Id " win := InstaNote._GetWindow()
- InstaNote.Handles[ win ].Gui1.UpdateSettings( { X: x , Y: y } )
- }
- _CloseWindow(){
- local out
- if( !IsObject( InstaNote.Handles[ win := InstaNote._GetWindow() ] ) )
- return 0
- if( InstaNote.Active = win ){
- InstaNote.Active := ""
- bd := InstaNote.Bind
- Hotkey, ~LButton , % bd , Off
- }
- if( InstaNote.Handles[ win ].Type = "Google Search" || InstaNote.Handles[ win ].Type = "GoogleSearch" ){
- out := InstaNote.Handles[ win ]._GetString()
- Try
- run, % "http://www.google.com/search?hl=en&q=" out
- catch
- msgbox, unknown error
- }else if( GetKeyState( "Shift" ) )
- Clipboard := InstaNote.Handles[ win ]._GetString()
- InstaNote.Windows[ InstaNote.Handles[ win ].Index ] := ""
- InstaNote.Handles[ win ].Gui1.DeleteWindow()
- InstaNote.Handles[ win ] := ""
- }
- _CaptureKeys( key ){
- if( key = 16 )
- return 1
- else if( key = 17 )
- return 1
- else if( key = 32 )
- InstaNote.Handles[ InstaNote.Active ].Output.Push( " " )
- else if( key = 13 ){
- if( InstaNote.Handles[ InstaNote.Active ].Type = "GoogleSearch" || InstaNote.Handles[ InstaNote.Active ].Type = "Google Search" )
- InstaNote.Handles[ InstaNote.Active ]._CloseWindow()
- else
- InstaNote.Handles[ InstaNote.Active ].Output.Push( "`n" )
- }
- else if( key = 8 )
- InstaNote.Handles[ InstaNote.Active ].Output.Pop()
- else if( key = 189 )
- InstaNote.Handles[ InstaNote.Active ].Output.Push( ( GetKeyState( "Shift" ) ) ? ( "_" ) : ( "-" ) )
- else if( key = 187 )
- InstaNote.Handles[ InstaNote.Active ].Output.Push( ( GetKeyState( "Shift" ) ) ? ( "+" ) : ( "=" ) )
- else if( key = 50 )
- InstaNote.Handles[ InstaNote.Active ].Output.Push( ( GetKeyState( "Shift" ) ) ? ( "@" ) : ( "2" ) )
- else if( key = 54 )
- InstaNote.Handles[ InstaNote.Active ].Output.Push( ( GetKeyState( "Shift" ) ) ? ( "^" ) : ( "6" ) )
- else if( key = 55 )
- InstaNote.Handles[ InstaNote.Active ].Output.Push( ( GetKeyState( "Shift" ) ) ? ( "&" ) : ( "7" ) )
- else if( key = 56 )
- InstaNote.Handles[ InstaNote.Active ].Output.Push( ( GetKeyState( "Shift" ) ) ? ( "*" ) : ( "8" ) )
- else if( key = 57 )
- InstaNote.Handles[ InstaNote.Active ].Output.Push( ( GetKeyState( "Shift" ) ) ? ( "(" ) : ( "9" ) )
- else if( key = 48 )
- InstaNote.Handles[ InstaNote.Active ].Output.Push( ( GetKeyState( "Shift" ) ) ? ( ")" ) : ( "0" ) )
- else if( key = 222 )
- InstaNote.Handles[ InstaNote.Active ].Output.Push( ( GetKeyState( "Shift" ) ) ? ( """" ) : ( "'" ) )
- else if( key = 191 )
- InstaNote.Handles[ InstaNote.Active ].Output.Push( ( GetKeyState( "Shift" ) ) ? ( "?" ) : ( "/" ) )
- else if( key = 188 )
- InstaNote.Handles[ InstaNote.Active ].Output.Push( ( GetKeyState( "Shift" ) ) ? ( "<" ) : ( "," ) )
- else if( key = 190 )
- InstaNote.Handles[ InstaNote.Active ].Output.Push( ( GetKeyState( "Shift" ) ) ? ( ">" ) : ( "." ) )
- else if( key = 220 )
- InstaNote.Handles[ InstaNote.Active ].Output.Push( ( GetKeyState( "Shift" ) ) ? ( "|" ) : ( "\" ) )
- else if( key = 192 )
- InstaNote.Handles[ InstaNote.Active ].Output.Push( ( GetKeyState( "Shift" ) ) ? ( "~" ) : ( "``" ) )
- else if( key = 186 )
- InstaNote.Handles[ InstaNote.Active ].Output.Push( ( GetKeyState( "Shift" ) ) ? ( ":" ) : ( ";" ) )
- else if( key = 219 )
- InstaNote.Handles[ InstaNote.Active ].Output.Push( ( GetKeyState( "Shift" ) ) ? ( "{" ) : ( "[" ) )
- else if( key = 221 )
- InstaNote.Handles[ InstaNote.Active ].Output.Push( ( GetKeyState( "Shift" ) ) ? ( "}" ) : ( "]" ) )
- else if( key >= 48 && key <= 53 ){
- InstaNote.Handles[ InstaNote.Active ].Output.Push( ( !GetKeyState( "Shift" ) ) ? chr( key ) : chr( key - 16 ) )
- }else{
- InstaNote.Handles[ InstaNote.Active ].Output.Push( ( GetKeyState( "Shift" ) ) ? chr( key ) : chr( key + 32 ) )
- }
- InstaNote.Handles[ InstaNote.Active ]._Draw()
- return 1
- }
- _DrawClipboard(){
- ;&&&&%%%%%%%$$$$$$$$$$$
- }
- _Draw(){
- local string := This._GetString()
- This.Gui1.ClearWindow( AutoUpdate := 0 )
- This.Gui1.PaintBackground( { Color: This.BorderColor , X: 2 , Y: 2 , W: This.Gui1.W - 4 , H: This.Gui1.H - 4 , Round: This.RoundNess } )
- Brush := Gdip_BrushCreateSolid( This.Color ) , Gdip_FillRoundedRectangle( This.Gui1.G, Brush , This.Bubble.X - This.PaddingX , This.Bubble.Y - This.PaddingY, This.Bubble.W , This.Bubble.H , This.RoundNess ) , Gdip_DeleteBrush( Brush )
- Brush := Gdip_BrushCreateSolid( This.FontColor ) , Gdip_TextToGraphics( This.Gui1.G , string , " s" This.Fontsize " c" Brush " vCenter " This.FontOptions " x" This.Bubble.X " y" This.Bubble.Y - This.PaddingY + 1 , This.Font , This.Bubble.W, This.Bubble.H )
- This.Gui1.UpdateWindow()
- }
- _GetTextSize( outputType := 0 , String := "" ){ ; 0 = all , 1 = width , 2 = height
- local pBitmap, G, Brush, temparr
- pBitmap := Gdip_CreateBitmap( 10,10), G := Gdip_GraphicsFromImage( pBitmap ), Gdip_SetSmoothingMode( G , 2 )
- Brush := Gdip_BrushCreateSolid( "0xFF000000")
- temparr := StrSplit( Gdip_TextToGraphics( G , ( String != "" ) ? ( String ) : ( "T" ) , " s" This.Fontsize " c" Brush " " This.FontOptions " x" 0 " y" 0 , This.Font , 10000, 10000 ),"|","|" )
- Gdip_DeleteBrush( Brush ), Gdip_DeleteGraphics( G ), Gdip_DisposeImage( pBitmap )
- if( outputType = 0 )
- return temparr
- else if( outputType = 1 )
- return temparr[ 3 ]
- else if( outputType = 2 )
- return temparr[ 4 ]
- }
- _GetString(){
- static lw := ""
- local text := "" , cc := This.Output , h
- This.LineCount := 1
- Loop, % cc.Length() {
- if( cc[ A_Index ] = "`n" )
- ++This.LineCount
- text .= cc[ A_Index ]
- }
- h := This.TextLineHeight * This.LineCount
- w := This._GetTextSize( 1 , text ) + 2 * This.PaddingX
- This.Bubble := { X: This.MarginX + This.PaddingX ,Y: This.MarginY + This.PaddingY , W: w , H: h }
- This.H := h + 2 * This.MarginY
- This.W := w + 2 * This.MarginX
- if( This.LastH != This.H && This.LastH := This.H )
- This._Resize()
- if( lw != This.W )
- This._Resize()
- ;*****************************************
- ;~ This.RoundNess := h / 9
- ;*****************************************
- return text
- }
- }
- ;*******************________________************************__________________*****************_______________*************
- ; Layered Window Class
- ;####################################################################################################################################################################################
- ;####################################################################################################################################################################################
- ;####################################################################################################################################################################################
- ;####################################################################################################################################################################################
- class PopUpWindow {
- ;PopUpWindow v2.2
- ;Date Written: Oct 28th, 2021
- ;Last Edit: Feb 7th, 2022 :Changed the trigger method.
- ;Written By: Hellbent aka CivReborn
- ;SpcThanks: teadrinker , malcev
- static Index := 0 , Windows := [] , Handles := [] , EditHwnd , HelperHwnd
- __New( obj := "" ){
- This._SetDefaults()
- This.UpdateSettings( obj )
- This._CreateWindow()
- This._CreateWindowGraphics()
- if( This.AutoShow )
- This.ShowWindow( This.Title )
- }
- _SetDefaults(){
- This.X := 10
- This.Y := 10
- This.W := 10
- This.H := 10
- This.Smoothing := 2
- This.Options := " -DPIScale +AlwaysOnTop "
- This.AutoShow := 0
- This.GdipStartUp := 0
- This.Title := ""
- This.Controls := []
- This.Handles := []
- This.Index := 0
- }
- UpdateSettings( obj := "" , UpdateGraphics := 0 ){
- local k , v
- if( IsObject( obj ) )
- for k, v in obj
- This[ k ] := obj[ k ]
- ( This.X = "Center" ) ? ( This.X := ( A_ScreenWidth - This.W ) / 2 )
- ( This.Y = "Center" ) ? ( This.Y := ( A_ScreenHeight - This.H ) / 2 )
- if( UpdateGraphics ){
- This._DestroyWindowsGraphics()
- This._CreateWindowGraphics()
- }
- }
- _CreateWindow(){
- local hwnd
- Gui , New, % " +LastFound +E0x80000 hwndhwnd -Caption " This.Options
- PopUpWindow.Index++
- This.Index := PopUpWindow.Index
- PopUpWindow.Windows[ PopUpWindow.Index ] := This
- This.Hwnd := hwnd
- PopUpWindow.Handles[ hwnd ] := PopUpWindow.Index
- if( This.GdipStartUp && !PopUpWindow.pToken )
- PopUpWindow.pToken := GDIP_STARTUP()
- }
- _DestroyWindowsGraphics(){
- Gdip_DeleteGraphics( This.G )
- SelectObject( This.hdc , This.obm )
- DeleteObject( This.hbm )
- DeleteDC( This.hdc )
- }
- _CreateWindowGraphics(){
- This.hbm := CreateDIBSection( This.W , This.H )
- This.hdc := CreateCompatibleDC()
- This.obm := SelectObject( This.hdc , This.hbm )
- This.G := Gdip_GraphicsFromHDC( This.hdc )
- Gdip_SetSmoothingMode( This.G , This.Smoothing )
- }
- ShowWindow( Title := "" ){
- Gui , % This.Hwnd ":Show", % "x" This.X " y" This.Y " w" This.W " h" This.H " NA", % Title
- }
- HideWindow(){
- Gui , % This.Hwnd ":Hide",
- }
- UpdateWindow(){
- UpdateLayeredWindow( This.hwnd , This.hdc , This.X , This.Y , This.W , This.H )
- }
- ClearWindow( AutoUpdate := 0 ){
- Gdip_GraphicsClear( This.G )
- if( Autoupdate )
- This.UpdateWindow()
- }
- DrawBitmap( pBitmap , obj , dispose := 1 , AutoUpdate := 0 ){
- Gdip_DrawImage( This.G , pBitmap , obj.X , obj.Y , obj.W , obj.H )
- if( dispose )
- Gdip_DisposeImage( pBitmap )
- if( Autoupdate )
- This.UpdateWindow()
- }
- PaintBackground( color := "0xFF000000" , AutoUpdate := 0 ){
- if( isObject( color ) ){
- Brush := Gdip_BrushCreateSolid( ( color.HasKey( "Color" ) ) ? ( color.Color ) : ( "0xFF000000" ) )
- if( color.Haskey( "Round" ) )
- Gdip_FillRoundedRectangle( This.G , Brush , color.X , color.Y , color.W , color.H , color.Round )
- else
- Gdip_FillRectangle( This.G , Brush , color.X , color.Y , color.W , color.H )
- }else{
- Brush := Gdip_BrushCreateSolid( color )
- Gdip_FillRectangle( This.G , Brush , -1 , -1 , This.W + 2 , This.H + 2 )
- }
- Gdip_DeleteBrush( Brush )
- if( AutoUpdate )
- This.UpdateWindow()
- }
- DeleteWindow( GDIPShutdown := 0 ){
- Gui, % This.Hwnd ":Destroy"
- SelectObject( This.hdc , This.obm )
- DeleteObject( This.hbm )
- DeleteDC( This.hdc )
- Gdip_DeleteGraphics( This.G )
- hwnd := This.Hwnd
- for k, v in PopUpWindow.Windows[ Hwnd ]
- This[k] := ""
- PopUpWindow.Windows[ Hwnd ] := ""
- if( GDIPShutdown ){
- Gdip_Shutdown( PopUpWindow.pToken )
- PopUpWindow.pToken := ""
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement