-- NFO Window Class NFOWindowClass = { windowCaption = 'NFOWindow by mgr.inz.Player', fontSize = 12, scrollLines = 9, nfoTEXT = nil, lineWidth, lineHeight, totalHeight, scrollDistance, CW, CH, Form, Button, PaintBox, Bitmap, DestY, currentY, objects = {} } function NFOWindowClass.Destroy() --destroy hotkeys and timers for i,v in pairs(NFOWindowClass.objects) do object_destroy(v) NFOWindowClass.objects[i] = nil end if NFOWindowClass.Form~=nil then NFOWindowClass.Form.hide() object_destroy(NFOWindowClass.Form) NFOWindowClass.Form = nil end end function NFOWindowClass.Init(arg) if arg.nfo==nil then arg.nfo = NFOWindowClass.authorNFO end -- set variables NFOWindowClass.windowCaption = arg.windowCaption or NFOWindowClass.windowCaption NFOWindowClass.fontSize = arg.fontSize or NFOWindowClass.fontSize NFOWindowClass.scrollLines = arg.scrollLines or NFOWindowClass.scrollLines -- PREPARE nfoTEXT table NFOWindowClass.nfoTEXT = {} table.insert(NFOWindowClass.nfoTEXT,ansiToUtf8(' ')) local longestLine = '' for w in string.gfind (arg.nfo,"[^\n]+") do table.insert(NFOWindowClass.nfoTEXT,ansiToUtf8(w)) if #longestLine < #NFOWindowClass.nfoTEXT[#NFOWindowClass.nfoTEXT] then longestLine = NFOWindowClass.nfoTEXT[#NFOWindowClass.nfoTEXT] end end table.insert(NFOWindowClass.nfoTEXT,ansiToUtf8(' ')) table.insert(NFOWindowClass.nfoTEXT,ansiToUtf8(' ')) -- DETERMINE line width, line height, total height local tmpImage = createImage(UDF1) tmpImage.Canvas.Font.Name = 'Terminal' tmpImage.Canvas.Font.Size = NFOWindowClass.fontSize setProperty(tmpImage.Canvas.Font,'CharSet','OEM_CHARSET') NFOWindowClass.lineWidth = tmpImage.Canvas.getTextWidth (longestLine..' ') NFOWindowClass.lineHeight = tmpImage.Canvas.getTextHeight(longestLine..' ') NFOWindowClass.totalHeight = NFOWindowClass.lineHeight * (#NFOWindowClass.nfoTEXT) NFOWindowClass.scrollDistance = NFOWindowClass.lineHeight * NFOWindowClass.scrollLines object_destroy(tmpImage);tmpImage=nil -- DETERMINE window size local windowMaximumHeight = arg.windowMaximumHeight or 600 NFOWindowClass.CW = NFOWindowClass.lineWidth + 10 NFOWindowClass.CH = (NFOWindowClass.totalHeight > windowMaximumHeight) and windowMaximumHeight or NFOWindowClass.totalHeight if NFOWindowClass.CW < 200 then NFOWindowClass.CW=200 end --assign event to given button if arg.Button then arg.Button.Enabled = true arg.Button.OnClick = NFOWindowClass.ShowWindow NFOWindowClass.Button = arg.Button end end function NFOWindowClass.ButtonSetEnabled(enabled) if NFOWindowClass.Button~=nil then NFOWindowClass.Button.Enabled = enabled end end function NFOWindowClass.ShowWindow(senderButton) NFOWindowClass.ButtonSetEnabled(false) NFOWindowClass.Destroy() -- destroy if any left -- MAIN WINDOW ATTRIBUTES, CAPTION and EVENTS local NFOFORM = createForm(false) NFOFORM.setSize(NFOWindowClass.CW, NFOWindowClass.CH) NFOFORM.Caption = NFOWindowClass.windowCaption NFOFORM.Borderstyle = 'bsToolWindow' NFOFORM.Position = 'poScreenCenter' NFOFORM.DoubleBuffered = true NFOFORM.OnClose = function (sender) NFOWindowClass.ButtonSetEnabled(true) -- enable button NFOWindowClass.Destroy() end -- ESC key to exit setMethodProperty(NFOFORM,'OnKeyPress', function (sender, key) if string.byte(key) == 27 then NFOWindowClass.ButtonSetEnabled(true) -- enable button NFOWindowClass.Destroy() end end) local rainbowColors = { 0x00000000,0x00000000,0x00000006,0x0000000E,0x00000016,0x00000020,0x0000002A,0x00000035, 0x00000040,0x0000004D,0x0000005B,0x00000068,0x00000076,0x00000083,0x00000091,0x0000009D, 0x000000AB,0x000000B7,0x000000C3,0x000000CF,0x000000DA,0x000000E5,0x000000ED,0x000000F5, 0x000000FC,0x000002FF,0x000006FF,0x00000CFF,0x000012FF,0x000019FF,0x000020FF,0x000028FF, 0x000030FF,0x000038FF,0x000042FF,0x00004AFF,0x000054FF,0x00005DFF,0x000068FF,0x000071FF, 0x00007CFF,0x000086FF,0x00008FFF,0x00009AFF,0x0000A3FF,0x0000ADFF,0x0000B6FF,0x0000C0FF, 0x0000C8FF,0x0000D1FF,0x0000D8FF,0x0000E0FF,0x0000E7FF,0x0000EDFF,0x0000F3FF,0x0000F8FF, 0x0000FCFF,0x0001FFFA,0x0003FFF5,0x0004FFF0,0x0005FFEA,0x0007FFE3,0x0008FFDC,0x000BFFD5, 0x000CFFCD,0x000EFFC5,0x0010FFBD,0x0012FFB4,0x0014FFAB,0x0016FFA2,0x0018FF98,0x001BFF8E, 0x001CFF85,0x001FFF7C,0x0022FF72,0x0024FF68,0x0026FF5F,0x0029FF57,0x002CFF4D,0x002FFF44, 0x0033FF3C,0x0035FF34,0x0038FF2C,0x003BFF24,0x003FFF1D,0x0042FF17,0x0046FF10,0x0049FF0B, 0x004DFF06,0x0050FF02,0x0054FE00,0x0058FE00,0x005DFF00,0x0061FE00,0x0065FE00,0x006AFE00, 0x006FFE00,0x0075FD00,0x007AFD00,0x007FFE00,0x0085FD00,0x008BFD00,0x0091FD00,0x0097FC00, 0x009CFD00,0x00A2FD00,0x00A9FD00,0x00AFFC00,0x00B7FB00,0x00BFFB00,0x00C8FA00,0x00D1F900, 0x00D9F800,0x00E0F600,0x00E6F500,0x00ECF200,0x00F3F000,0x00F8EE00,0x00FCEC00,0x00FFE901, 0x00FFE507,0x00FFE10D,0x00FFDD14,0x00FFD71C,0x00FFD224,0x00FFCD2C,0x00FFC737,0x00FFC240, 0x00FFBC4A,0x00FFB754,0x00FFB359,0x00FFB05F,0x00FFAC65,0x00FFA86A,0x00FFA66F,0x00FFA275, 0x00FF9F7B,0x00FF9B80,0x00FF9785,0x00FF948B,0x00FF918F,0x00FF8E94,0x00FF8A99,0x00FF879D, 0x00FF83A1,0x00FF80A6,0x00FF7DAA,0x00FF7AAD,0x00FF77B0,0x00FE73B5,0x00FD6FBA,0x00FC6ABE, 0x00FC67C3,0x00FA62C7,0x00FA5ECC,0x00F85AD0,0x00F755D4,0x00F751D9,0x00F64CDD,0x00F448E2, 0x00F443E7,0x00F23EEB,0x00F13AEE,0x00EF35F1,0x00ED30F7,0x00EA29FB,0x00E823FF,0x00E41DFF, 0x00E117FF,0x00DD12FF,0x00D80DFF,0x00D309FF,0x00CF05FF,0x00C902FF,0x00C300FD,0x00BD00F7, 0x00B600F0,0x00AE00E8,0x00A600DF,0x009C00D5,0x009400C9,0x008A00BD,0x008000B0,0x007700A4, 0x006C0096,0x00620088,0x0057007A,0x004D006C,0x0044005E,0x00390050,0x00310043,0x00280037, 0x001F002B,0x00180020,0x00100017,0x000B000D,0x00050006,0x00000000,0x00000000,0x00000000} -- CREATE NICE RAINBOW local rainbowImage = createImage(NFOFORM) rainbowImage.setSize(1,200) rainbowImage.align = 'alClient' rainbowImage.Stretch = true for i=1,200 do rainbowImage.Canvas.setPixel(0,i-1,rainbowColors[i]) end -- CREATE RENDER IMAGE FOR NFO TEXT local PaintBox = createPaintBox(NFOFORM) PaintBox.align = 'alClient' -- create bitmap local txtBmp = createBitmap(NFOWindowClass.CW, NFOWindowClass.totalHeight) txtBmp.TransparentColor = 0x800080 txtBmp.Transparent = true -- set canvas Font txtBmp.Canvas.Font.Name = 'Terminal' txtBmp.Canvas.Font.Size = NFOWindowClass.fontSize txtBmp.Canvas.Font.Color = 0x800080 setProperty(txtBmp.Canvas.Font,'CharSet','OEM_CHARSET') -- set canvas Brush color txtBmp.Canvas.Brush.Color = 0x000000 -- draw text for i=1,#NFOWindowClass.nfoTEXT do local Y = NFOWindowClass.lineHeight*(i-1) txtBmp.Canvas.textOut(5,Y,NFOWindowClass.nfoTEXT[i]) end PaintBox.OnPaint = NFOWindowClass.paintstate PaintBox.repaint() setMethodProperty(PaintBox,'OnMouseDown',function () form_dragNow(NFOFORM) end) -- drag form NFOFORM.show() local scrollTimer = createTimer(NFOFORM,false) scrollTimer.OnTimer = NFOWindowClass.scrollOnTimer scrollTimer.Interval = 10 NFOWindowClass.Form = NFOFORM NFOWindowClass.PaintBox = PaintBox NFOWindowClass.Bitmap = txtBmp NFOWindowClass.DestY = 0 NFOWindowClass.currentY = 0 NFOWindowClass.objects['hotkey1'] = createHotkey(NFOWindowClass.scrollUp ,VK_PRIOR) NFOWindowClass.objects['hotkey2'] = createHotkey(NFOWindowClass.scrollDown,VK_NEXT) NFOWindowClass.objects['timer'] = scrollTimer end function NFOWindowClass.paintstate(sender) sender.Canvas.draw(0,NFOWindowClass.currentY,NFOWindowClass.Bitmap) --local r=sender.Canvas.getClipRect() --sender.Canvas.copyRect(r.Left, r.Top, -- dest -- r.Right, r.Bottom, -- dest -- NFOWindowClass.Bitmap.Canvas, -- source -- r.Left, r.Top - NFOWindowClass.currentY, -- source -- r.Right, r.Bottom - NFOWindowClass.currentY) -- source end function NFOWindowClass.scrollUp() local y = NFOWindowClass.currentY if NFOWindowClass.objects['timer'].Enabled == true then y = NFOWindowClass.DestY + NFOWindowClass.scrollDistance end NFOWindowClass.DestY = (y + NFOWindowClass.scrollDistance < 0) and (y + NFOWindowClass.scrollDistance) or 0 NFOWindowClass.objects['timer'].Enabled = true end function NFOWindowClass.scrollDown() local y = NFOWindowClass.currentY if NFOWindowClass.objects['timer'].Enabled == true then y = NFOWindowClass.DestY - NFOWindowClass.scrollDistance end NFOWindowClass.DestY = (y - NFOWindowClass.scrollDistance < NFOWindowClass.CH-NFOWindowClass.totalHeight) and (NFOWindowClass.CH-NFOWindowClass.totalHeight) or (y - NFOWindowClass.scrollDistance) NFOWindowClass.objects['timer'].Enabled = true end function NFOWindowClass.scrollOnTimer(timer) local y = NFOWindowClass.currentY local step = (NFOWindowClass.DestY-y) * 0.05 if step < 1 and step > 0 then step = 1 end if step > -1 and step < 0 then step = -1 end y = y + step if step < 0 and y < NFOWindowClass.DestY then y=NFOWindowClass.DestY end if step > 0 and y > NFOWindowClass.DestY then y=NFOWindowClass.DestY end if math.abs(y) < 1 then y=0 end if NFOWindowClass.DestY==y then timer_setEnabled(timer,false) end NFOWindowClass.currentY = y -- you can remove this IF if NFOWindowClass.CH~=NFOWindowClass.totalHeight then NFOWindowClass.Form.Caption = NFOWindowClass.windowCaption.. ' position: '.. math.floor(y/(NFOWindowClass.CH-NFOWindowClass.totalHeight)*100).. '%' end NFOWindowClass.PaintBox.repaint() end NFOWindowClass.authorNFO = [[ _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ _/ _/ _/ This NFOWindow was made by _/ _/ mgr.inz.Player (aka YourEnemy) _/ _/ _/ _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ _/ _/ _/ You see this message, because you didn't set "nfo" _/ _/ _/ _/ Usage: _/ _/ _/ _/ NFOWindowClassOptions = _/ _/ { _/ _/ nfo='your text', -- mandatory _/ _/ windowCaption='NFOWindow by mgr.inz.Player', -- mandatory _/ _/ Button=UDF1_CEButton1, _/ _/ fontSize=12, -- (default 12) _/ _/ windowMaximumHeight=420, -- (default: 600, about 50 lines) _/ _/ scrollLines=5 -- (default: 9) _/ _/ } _/ _/ _/ _/ NFOWindowClass.Init(NFOWindowClassOptions) _/ _/ _/ _/ Example1 (show window after button onclick) : _/ _/ _/ _/ NFOWCO = { nfo='example 1\nline two', _/ _/ windowCaption='Example1 test', _/ _/ Button=UDF1_CEButton1 } _/ _/ _/ _/ NFOWindowClass.Init(NFOWCO) _/ _/ _/ _/ _/ _/ _/ _/ Example2 (ShowWindow used) : _/ _/ _/ _/ NFOWCO = { nfo='example 2\nline two', _/ _/ windowCaption='Example2 test' } _/ _/ _/ _/ NFOWindowClass.Init(NFOWCO) _/ _/ NFOWindowClass.ShowWindow() _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ ]] -- NFO Window Class END