Skip to content

Commit

Permalink
Merge pull request #20 from Nigh/backgroud-mode
Browse files Browse the repository at this point in the history
add Backgroud mode
  • Loading branch information
Nigh authored Sep 12, 2023
2 parents 4f753ba + d16152f commit 91e088a
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 72 deletions.
183 changes: 113 additions & 70 deletions app.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,16 @@ MonitorGet(1, &Left, &Top, &Right, &Bottom)
DPIScale := A_ScreenDPI / 96
Screen_Height := Bottom - Top
Screen_Width := Right - Left
picture_array := [{ name: '', pBitmap: -1, exif: '' }, { name: '', pBitmap: -1, exif: '' }]
hBitmap_cache := []
picture_array := []
loop 2
picture_array.Push({
name: '',
pBitmap: -1,
exif: '',
pBitmapShow: 0,
G: 0,
hBitmapShow: 0
})

if (IniRead("setting.ini", "setup", "autocenter", "1") == "1") {
setting_autoCenter := "center"
Expand All @@ -38,6 +46,14 @@ if (IniRead("setting.ini", "setup", "autocenter", "1") == "1") {
autoCenter_default_check := "Checked0"
}

if (IniRead("setting.ini", "setup", "runbackgroud", "0") == "1") {
setting_runbackgroud := 1
runbackgroud_default_check := "Checked1"
} else {
setting_runbackgroud := 0
runbackgroud_default_check := "Checked0"
}

#include Gdip_All.ahk
pGDI := Gdip_Startup()

Expand All @@ -59,6 +75,8 @@ swapbtn.OnEvent("Click", swap)

autoCenterSwitch := mygui.Add("Checkbox", "x+10 yp hp " autoCenter_default_check, 'Auto Center')
autoCenterSwitch.OnEvent("Click", autoPosSwitch_cb)
backgroundSwitch := mygui.Add("Checkbox", "x+10 yp hp " runbackgroud_default_check, 'Runs in background')
backgroundSwitch.OnEvent("Click", backgroundSwitch_cb)

mygui.SetFont("s10 Q5 norm", "Comic Sans MS")
mygui.Add("Text", "xs y+0 h12", 'Current:')
Expand All @@ -69,6 +87,7 @@ mygui.Add("Text", "xs y+0 h12", 'EXIF:')
txt_exif := mygui.Add("Text", "x+10 yp hp w360", 'NULL')
txt_exif.SetFont("cNavy bold")

picCurrentShow := 1
pic := mygui.Add("Picture", "x10 y+0 w500 h400 0xE 0x200 0x800000 -0x40")
pic.OnEvent("Click", pic_on_click)
pic.OnEvent("DoubleClick", pic_on_click)
Expand All @@ -79,7 +98,11 @@ info.Push(mygui.Add("Text", "x420 y12 h0", "v" . version))
info.Push(mygui.Add("Link", "xp y+0 hp", 'bilibili: <a href="https://space.bilibili.com/895523">TecNico</a>'))
info.Push(mygui.Add("Link", "xp y+0 hp", 'GitHub: <a href="https://github.com/Nigh">xianii</a>'))

mygui.Show("AutoSize")
if (setting_runbackgroud) {
mygui.Show("AutoSize Hide")
} else {
mygui.Show("AutoSize")
}

if (A_Args.Length > 0) {
para_pic := Array()
Expand All @@ -92,13 +115,36 @@ if (A_Args.Length > 0) {
}
}
HotIfWinActive "ahk_id" mygui.Hwnd
Hotkey "^w", myGui_Close
Hotkey "Esc", myGui_Close
if (setting_runbackgroud) {
Hotkey "^w", myGui_Hide
Hotkey "Esc", myGui_Hide
} else {
Hotkey "^w", myGui_Close
Hotkey "Esc", myGui_Close
}
Hotkey "Space", pic_on_click
Hotkey "s", swap
HotIf
if (setting_runbackgroud) {
Hotkey "^q", copyCompare
TrayTip("Runs in Background.`nSelect pictures and press Ctrl+Q to compare.", "PicQuickCompare", 1)
}
Return

copyCompare(GuiCtrlObj, info*) {
global mygui
A_Clipboard := ""
Send("^c")
if (!ClipWait(1)) {
return
}
FileArray := []
loop parse A_Clipboard, "`n", "`r" {
FileArray.Push(A_LoopField)
}
mygui_DropFiles(mygui, 0, FileArray, 0, 0)
}

#include Filexpro.ahk
autoPosSwitch_cb(GuiCtrlObj, Info*) {
global setting_autoCenter
Expand All @@ -113,65 +159,68 @@ autoPosSwitch_cb(GuiCtrlObj, Info*) {
SetTimer(() => GuiCtrlObj.Opt("-Disabled"), -600)
}
backgroundSwitch_cb(GuiCtrlObj, Info*) {
GuiCtrlObj.Opt("+Disabled")
SetTimer(() => GuiCtrlObj.Opt("-Disabled"), -600)
global setting_autoCenter
if (GuiCtrlObj.Value > 0) {
IniWrite("1", "setting.ini", "setup", "runbackgroud")
} else {
IniWrite("0", "setting.ini", "setup", "runbackgroud")
}
Reload
; GuiCtrlObj.Opt("+Disabled")
; SetTimer(() => GuiCtrlObj.Opt("-Disabled"), -600)
}
isSwapable() {
global
return picture_array[picCurrentShow ^ 0x3].pBitmap > 0
}
swap(GuiCtrlObj, Info*) {
global picture_array
if (picture_array[2].pBitmap > 0) {
tmp := picture_array[2]
picture_array[2] := picture_array[1]
picture_array[1] := tmp
mygui_ctrl_show_pic(pic, picture_array[1])
global picture_array, picCurrentShow
if (isSwapable()) {
picCurrentShow := picCurrentShow ^ 0x3
mygui_ctrl_show_pic(picture_array[picCurrentShow])
}
}

on_space(a) {
global picture_array, pic
if (picture_array[2].pBitmap > 0) {
mygui_ctrl_show_pic(pic, picture_array[2])
if (isSwapable()) {
swap("")
KeyWait "Space"
mygui_ctrl_show_pic(pic, picture_array[1])
swap("")
}
}
pic_on_click(thisGui, GuiCtrlObj*) {
global picture_array, pic
if (picture_array[2].pBitmap > 0) {
mygui_ctrl_show_pic(pic, picture_array[2])
if (isSwapable()) {
swap("")
if (thisGui == "Space") {
KeyWait "Space"
} else {
KeyWait "LButton"
}
mygui_ctrl_show_pic(pic, picture_array[1])
swap("")
}
}

create_pic_bitmap_cache() {
create_pic_bitmap_cache(index) {
global picture_array, pic, DPIScale

if (picture_array[index].pBitmap < 0) {
return
}
pic.GetPos(, , , &ctrlH)
loop 2 {
if (picture_array[A_Index].pBitmap < 0) {
break
}
hBitmap_cache.Push({ pBitmap: 0, pBitmapShow: 0, G: 0, hBitmapShow: 0 })
hBitmap_cache[hBitmap_cache.Length].pBitmap := picture_array[A_Index].pBitmap
Gdip_GetImageDimensions(hBitmap_cache[hBitmap_cache.Length].pBitmap, &W, &H)
percent := ctrlH / H * DPIScale
picW := W * percent
picH := H * percent
hBitmap_cache[hBitmap_cache.Length].pBitmapShow := Gdip_CreateBitmap(picW, picH)
hBitmap_cache[hBitmap_cache.Length].G := Gdip_GraphicsFromImage(hBitmap_cache[hBitmap_cache.Length].pBitmapShow)
Gdip_SetSmoothingMode(hBitmap_cache[hBitmap_cache.Length].G, 4)
Gdip_SetInterpolationMode(hBitmap_cache[hBitmap_cache.Length].G, 7)
Gdip_DrawImage(hBitmap_cache[hBitmap_cache.Length].G, hBitmap_cache[hBitmap_cache.Length].pBitmap, 0, 0, picW, picH)
hBitmap_cache[hBitmap_cache.Length].hBitmapShow := Gdip_CreateHBITMAPFromBitmap(hBitmap_cache[hBitmap_cache.Length].pBitmapShow)
if (picture_array[index].G) {
Gdip_DeleteGraphics(picture_array[index].G), Gdip_DisposeImage(picture_array[index].pBitmapShow), DeleteObject(picture_array[index].hBitmapShow)
}

while (hBitmap_cache.Length > 2) {
Gdip_DeleteGraphics(hBitmap_cache[1].G), Gdip_DisposeImage(hBitmap_cache[1].pBitmapShow), DeleteObject(hBitmap_cache[1].hBitmapShow)
hBitmap_cache.RemoveAt(1)
}
Gdip_GetImageDimensions(picture_array[index].pBitmap, &W, &H)
percent := ctrlH / H * DPIScale
picW := W * percent
picH := H * percent
picture_array[index].pBitmapShow := Gdip_CreateBitmap(picW, picH)
picture_array[index].G := Gdip_GraphicsFromImage(picture_array[index].pBitmapShow)
Gdip_SetSmoothingMode(picture_array[index].G, 4)
Gdip_SetInterpolationMode(picture_array[index].G, 7)
Gdip_DrawImage(picture_array[index].G, picture_array[index].pBitmap, 0, 0, picW, picH)
picture_array[index].hBitmapShow := Gdip_CreateHBITMAPFromBitmap(picture_array[index].pBitmapShow)
}

pic_ctrl_set_size() {
Expand Down Expand Up @@ -217,37 +266,23 @@ pic_ctrl_set_size() {
inf.Move(Max(ctrlW - 90, 410))
}
pic.gui.Show("AutoSize " setting_autoCenter)
pic.gui.GetPos(&X, &Y, &Width, &Height)
if (Y + Height >= 0.95 * Screen_Height / DPIScale) {
pic.gui.Show("yCenter")
}
pic.Redraw()
}

mygui_ctrl_show_pic(GuiCtrlObj, image)
mygui_ctrl_show_pic(picture)
{
global hBitmap_cache, txt_indicator
loop 2 {
if (hBitmap_cache[A_Index].pBitmap == image.pBitmap) {
SetImage(GuiCtrlObj.hwnd, hBitmap_cache[A_Index].hBitmapShow)
txt_indicator.Text := image.name
txt_exif.Text := image.exif
return
}
}
GuiCtrlObj.GetPos(, , , &ctrlH)
Gdip_GetImageDimensions(image.pBitmap, &W, &H)
percent := ctrlH / H
picW := W * percent
picH := H * percent
pBitmapShow := Gdip_CreateBitmap(picW, picH)
G := Gdip_GraphicsFromImage(pBitmapShow)
Gdip_SetSmoothingMode(G, 4)
Gdip_SetInterpolationMode(G, 7)
Gdip_DrawImage(G, image.pBitmap, 0, 0, picW, picH)
hBitmapShow := Gdip_CreateHBITMAPFromBitmap(pBitmapShow)
SetImage(GuiCtrlObj.hwnd, hBitmapShow)
Gdip_DeleteGraphics(G), Gdip_DisposeImage(pBitmapShow), DeleteObject(hBitmapShow)
global txt_indicator, pic, mygui
txt_indicator.Text := picture.name
txt_exif.Text := picture.exif
SetImage(pic.hwnd, picture.hBitmapShow)
}

mygui_DropFiles(GuiObj, GuiCtrlObj, FileArray, X, Y) {
global picture_array, pic
global picture_array, pic, picCurrentShow
local valid := 0
local bitmap
GuiObj.Opt("+OwnDialogs")
Expand All @@ -258,7 +293,7 @@ mygui_DropFiles(GuiObj, GuiCtrlObj, FileArray, X, Y) {
if (bitmap > 0) {
valid += 1
Loop Files, fullpath, "F" {
picture_array[2] := picture_array[1]
picCurrentShow := picCurrentShow ^ 0x3
exinfo := Filexpro(A_LoopFileFullPath, "", "System.Photo.Orientation", "System.Photo.FNumber", "System.Photo.ISOSpeed", "System.Photo.FocalLength", "System.Photo.ExposureTime", "System.Photo.ExposureTimeNumerator", "System.Photo.ExposureTimeDenominator", "xInfo")
if (StrLen(exinfo["System.Photo.FocalLength"]) > 0) {
ex_focal := exinfo["System.Photo.FocalLength"] "mm"
Expand All @@ -281,20 +316,28 @@ mygui_DropFiles(GuiObj, GuiCtrlObj, FileArray, X, Y) {
if (exinfo["System.Photo.Orientation"] == "6") {
Gdip_ImageRotateFlip(bitmap, 1)
}
picture_array[1] := { name: A_LoopFileName, pBitmap: bitmap, exif: exif }
picture_array[picCurrentShow].name := A_LoopFileName
picture_array[picCurrentShow].pBitmap := bitmap
picture_array[picCurrentShow].exif := exif
}
}
}
}
if (valid) {
pic_ctrl_set_size()
create_pic_bitmap_cache()
mygui_ctrl_show_pic(pic, picture_array[1])
loop 2
create_pic_bitmap_cache(A_Index)
mygui_ctrl_show_pic(picture_array[picCurrentShow])
}
if (!valid) {
MsgBox "Invalid Files"
}
}

myGui_Hide(thisGui) {
global mygui
mygui.Show("Hide")
}
mygui_Close(thisGui) {
trueExit(0, 0)
}
Expand Down
5 changes: 3 additions & 2 deletions meta.ahk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FileEncoding("UTF-8")
appName := "PicQuickCompare"
version := "0.2.2"
version := "0.2.3"
versionFilename := "version.txt"
ahkFilename := "app.ahk"
binaryFilename := "PicQuickCompare.exe"
Expand All @@ -11,5 +11,6 @@ update_log := "
1. 增加Exif信息显示
2. 根据Exif信息自动旋转图片
3. 修复v0.2.0版本Exif只能获取英文系统的问题
3. 修复v0.2.1版本读取不含Exif文件报错的问题
4. 修复v0.2.1版本读取不含Exif文件报错的问题
5. 增加后台运行模式,选中图片按Ctrl+Q即可直接比较
)"

0 comments on commit 91e088a

Please sign in to comment.