Advertisement
tic

MyFeed

tic
Feb 28th, 2013
844
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #SingleInstance, Force
  2. CoordMode, Mouse, Screen
  3. pToken := Gdip_Startup()
  4. OnExit, Exit
  5.  
  6. Gui, 1: -Caption +E0x80000 +LastFound +AlwaysOnTop +ToolWindow +OwnDialogs
  7. Gui, 1: Show, NA
  8. hwnd1 := WinExist()
  9.  
  10. w := 200, h := 300
  11. bw := 2
  12. w += bw//2, h += bw//2
  13.  
  14. info := {title: "My Feed", item: ["Some information", "Click me!", "And me!", "Just another test", "Last piece of information"]}
  15. o := {x: Round(w*0.05), y: 0, w: Round(w*0.9), h: 35, hpos: "Centre", vpos: "vCentre", color: "bbffffff", size: "14", style: ["Normal"]}
  16. options := {}, optionsHover := {}
  17. Loop, % info.item.MaxIndex()        ;%
  18. {
  19.     oLocal := o.Clone()
  20.     oLocal.y := 60+(A_Index-1)*35
  21.     options[A_Index] := oLocal
  22.     oHover := oLocal.Clone(), oHover.style := ["Bold"]
  23.     optionsHover[A_Index] := oHover
  24. }
  25.  
  26. hbm := CreateDIBSection(w, h), hdc := CreateCompatibleDC(), obm := SelectObject(hdc, hbm)
  27. G := Gdip_GraphicsFromHDC(hdc), Gdip_SetSmoothingMode(G, 4)
  28.  
  29. pBrush := Gdip_BrushCreateSolid(Gdip_ToARGB(200, 70, 70, 70))
  30. Gdip_FillRoundedRectangle(G, pBrush, bw//2, bw//2, w-bw, h-bw, 5)
  31.  
  32. pPen := Gdip_CreatePen(Gdip_ToARGB(255, 200, 200, 200), bw)
  33. Gdip_DrawRoundedRectangle(G, pPen, bw//2, bw//2, w-bw, h-bw, 5)
  34.  
  35. titleOptions := o.Clone(), titleOptions.y := 20, titleOptions.size := 20, titleOptions.style := ["Bold", "Underline"]
  36. Gdip_TextToGraphics2(G, info.title, titleOptions, "Arial", w, h)
  37.  
  38. Loop, % info.item.MaxIndex()        ;%
  39.     Gdip_TextToGraphics2(G, info.item[A_Index], options[A_Index], "Arial", w, h)
  40.  
  41. UpdateLayeredWindow(hwnd1, hdc, (A_ScreenWidth-w)//2, (A_ScreenHeight-h)//2, w, h)
  42. OnMessage(0x201, "WM_LBUTTONDOWN")
  43. SetTimer, Update, 50
  44. return
  45.  
  46. ;#######################################################################
  47.  
  48. Gdip_TextToGraphics2(pGraphics, Text, Options, Font="Arial", Width="", Height="", Measure=0)
  49. {
  50.     static replace := {x: "x", y: "y", w: "w", h: "h", hpos: "", vpos: "", color: "c", size: "s"}
  51.     for k, v in Options
  52.     {
  53.         if (k = "style")
  54.         {
  55.             Loop, % v.MaxIndex()        ;%
  56.                 o .= " " v[A_Index]
  57.         }
  58.         else
  59.             o .= " " replace[k] Options[k]
  60.     }
  61.     return Gdip_TextToGraphics(pGraphics, Text, o, Font, Width, Height, Measure)
  62. }
  63.  
  64. ;#######################################################################
  65.  
  66. Update:
  67. MouseGetPos, x, y, window
  68. WinGetPos, wx, wy,,, ahk_id %hwnd1%
  69. x -= wx, y -= wy
  70.  
  71. match := 0
  72. Loop, % info.item.MaxIndex()        ;%
  73. {
  74.     tx := options[A_Index].x, ty := options[A_Index].y
  75.     tw := options[A_Index].w, th := options[A_Index].h
  76.  
  77.     if (x >= tx && y >= ty && x <= tx+tw && y <= ty+th)
  78.     {
  79.         match := A_Index
  80.         break
  81.     }
  82. }
  83. if (match = omatch)
  84.     return
  85.  
  86. Loop, 2
  87. {
  88.     i := (A_Index = 1) ? match : omatch
  89.     Gdip_SetClipRect(G, options[i].x, options[i].y, options[i].w, options[i].h)
  90.     Gdip_SetCompositingMode(G, 1)
  91.     Gdip_FillRectangle(G, pBrush, 0, 0, w, h)
  92.     Gdip_SetCompositingMode(G, 0)
  93.     Gdip_TextToGraphics2(G, info.item[i], (A_Index = 1) ? optionsHover[i] : options[i], "Arial", w, h)
  94.     Gdip_ResetClip(G)
  95. }
  96. omatch := match
  97. UpdateLayeredWindow(hwnd1, hdc)
  98. return
  99.  
  100. ;#######################################################################
  101.  
  102. CheckClick:
  103. if !match
  104.     SetTimer, CheckClick, Off
  105. else if !GetKeyState("LButton", "P")
  106. {
  107.     SetTimer, CheckClick, Off
  108.     MsgBox, % info.item[match]      ;%
  109. }
  110. return
  111.  
  112. ;#######################################################################
  113.  
  114. WM_LBUTTONDOWN()
  115. {
  116.     PostMessage, 0xA1, 2
  117.     SetTimer, CheckClick, 50
  118. }
  119.  
  120. ;#######################################################################
  121.  
  122. Exit:
  123. SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc), Gdip_DeleteGraphics(G)
  124. Gdip_DeleteBrush(pBrush), Gdip_DeletePen(pPen)
  125. Gdip_Shutdown(pToken)
  126. ExitApp
  127. return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement