forked from pkulchenko/ZeroBranePackage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopenimagefile.lua
71 lines (60 loc) · 1.88 KB
/
openimagefile.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
local function fileLoad(file)
local f = FileRead(file)
if not f then return end
local fstream = wx.wxMemoryInputStream.new(f, #f)
local log = wx.wxLogNull()
local image = wx.wxImage()
local loaded = image:LoadFile(fstream)
return loaded and image or nil
end
local function fileMeta(name)
local image = fileLoad(name)
if not image then return end
return image:GetWidth(), image:GetHeight()
end
local function fileShow(name)
local image = fileLoad(name)
if not image then return end
local width, height = image:GetWidth(), image:GetHeight()
local screenSizeX, screenSizeY = wx.wxDisplaySize()
local frame = wx.wxFrame(
wx.NULL,
wx.wxID_ANY,
('(%d x %d) %s'):format(width, height, name),
wx.wxDefaultPosition,
wx.wxSize(width, height),
wx.wxDEFAULT_FRAME_STYLE + wx.wxSTAY_ON_TOP
- wx.wxRESIZE_BORDER - wx.wxMAXIMIZE_BOX)
frame:SetClientSize(width, height)
frame:Centre()
local function OnPaint()
local dc = wx.wxPaintDC(frame)
dc:DrawBitmap(wx.wxBitmap(image), 0, 0, true)
dc:delete()
end
frame:Connect(wx.wxEVT_PAINT, OnPaint)
frame:Show(true)
return false
end
return {
name = "Open image file",
description = "Opens image file from the file tree.",
author = "Paul Kulchenko",
version = 0.1,
dependencies = 0.51,
onFiletreeActivate = function(self, tree, event, item)
if not item then return end
return fileShow(tree:GetItemFullName(item))
end,
onMenuFiletree = function(self, menu, tree, event)
local item_id = event:GetItem()
local name = tree:GetItemFullName(item_id)
local width, height = fileMeta(name)
if not width or not height then return end
local id = ID(self.fname .. ".openimage")
menu:AppendSeparator()
menu:Append(id, ("Open Image (%d x %d)"):format(width, height))
tree:Connect(id, wx.wxEVT_COMMAND_MENU_SELECTED,
function() fileShow(name) end)
end,
}