-- NFO Window Class NFOWindowClass = { windowCaption = 'NFOWindow by mgr.inz.Player', fontSize = 10, scrollLines = 9, nfoTEXT = nil, lineWidth, lineHeight, totalHeight, scrollDistance, CW, CH, Form, Button, txtImage, DestY, 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 form_hide(NFOWindowClass.Form) 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 = 1 for w in string.gfind (arg.nfo,"[^\n]+") do table.insert(NFOWindowClass.nfoTEXT,ansiToUtf8(w)) if #NFOWindowClass.nfoTEXT[longestLine] < #NFOWindowClass.nfoTEXT[#NFOWindowClass.nfoTEXT] then longestLine = #NFOWindowClass.nfoTEXT end end table.insert(NFOWindowClass.nfoTEXT,ansiToUtf8(' ')) table.insert(NFOWindowClass.nfoTEXT,ansiToUtf8(' ')) -- DETERMINE line width, line height, total height local IMAGEforTestingOnly = createImage(nil) local canvas = image_getCanvas(IMAGEforTestingOnly) local font = canvas_getFont(canvas) font_setName(font,'Terminal') setProperty(font,'CharSet','OEM_CHARSET') setProperty(font,'Size',NFOWindowClass.fontSize) NFOWindowClass.lineWidth = canvas_getTextWidth( canvas, NFOWindowClass.nfoTEXT[longestLine]..' ') NFOWindowClass.lineHeight = canvas_getTextHeight(canvas, NFOWindowClass.nfoTEXT[longestLine]..' ') NFOWindowClass.totalHeight = NFOWindowClass.lineHeight * (#NFOWindowClass.nfoTEXT) NFOWindowClass.scrollDistance = NFOWindowClass.lineHeight * NFOWindowClass.scrollLines object_destroy(IMAGEforTestingOnly);IMAGEforTestingOnly=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 control_setEnabled(arg.Button,true) control_onClick(arg.Button, NFOWindowClass.ShowWindow) NFOWindowClass.Button = arg.Button end end function NFOWindowClass.ButtonSetEnabled(enabled) if NFOWindowClass.Button~=nil then control_setEnabled(NFOWindowClass.Button,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) control_setSize(NFOFORM, NFOWindowClass.CW, NFOWindowClass.CH) control_setCaption(NFOFORM,NFOWindowClass.windowCaption) setProperty(NFOFORM,'Borderstyle','bsToolWindow') setProperty(NFOFORM,'Position','poScreenCenter') form_onClose(NFOFORM, 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} local rainbowImage = createImage(NFOFORM) control_setSize(rainbowImage,1,200) local rainbowCanvas = image_getCanvas(rainbowImage) for i=1,200 do canvas_setPixel(rainbowCanvas,0,i-1,rainbowColors[i]) end setProperty(rainbowImage,'Align','alClient') setProperty(rainbowImage,'Stretch','true') -- CREATE RENDER IMAGE FOR NFO TEXT local txtImage = createImage(NFOFORM) control_setSize(txtImage, NFOWindowClass.CW, NFOWindowClass.totalHeight) control_setPosition(txtImage,0,0) image_transparent(txtImage, true) local txtPic = image_getPicture(txtImage) local txtBmp = picture_getBitmap(txtPic) local canvas = rasterimage_getCanvas(txtBmp) setProperty(canvas,'AntialiasingMode','amOn') local font = canvas_getFont(canvas) font_setColor(font,0x800080) font_setName(font,'Terminal') setProperty(font,'CharSet','OEM_CHARSET') setProperty(font,'Size',NFOWindowClass.fontSize) graphic_setWidth(txtBmp,NFOWindowClass.CW); graphic_setHeight(txtBmp, NFOWindowClass.totalHeight) rasterimage_setTransparentColor(txtBmp,0x800080) rasterimage_setTransparent(txtBmp,true) local brush = canvas_getBrush(canvas) brush_setColor(brush, 0x000000) -- draw text for i=1,#NFOWindowClass.nfoTEXT do local Y = NFOWindowClass.lineHeight*(i-1) canvas_textOut(canvas,5,Y,NFOWindowClass.nfoTEXT[i]) end setMethodProperty(txtImage,'OnMouseDown',function () form_dragNow(NFOFORM) end) -- drag form form_show(NFOFORM) local scrollTimer = createTimer(NFOFORM,false) timer_onTimer(scrollTimer,NFOWindowClass.scrollOnTimer) timer_setInterval(scrollTimer,10) NFOWindowClass.objects['hotkey1'] = createHotkey(NFOWindowClass.scrollUp,VK_PRIOR) NFOWindowClass.objects['hotkey2'] = createHotkey(NFOWindowClass.scrollDown,VK_NEXT) NFOWindowClass.objects['timer'] = scrollTimer NFOWindowClass.Form = NFOFORM NFOWindowClass.txtImage = txtImage end function NFOWindowClass.scrollUp() local x,y = control_getPosition(NFOWindowClass.txtImage) if timer_getEnabled(NFOWindowClass.objects['timer']) == true then y = NFOWindowClass.DestY + NFOWindowClass.scrollDistance end NFOWindowClass.DestY = (y + NFOWindowClass.scrollDistance < 0) and (y + NFOWindowClass.scrollDistance) or 0 timer_setEnabled(NFOWindowClass.objects['timer'],true) end function NFOWindowClass.scrollDown() local x,y = control_getPosition(NFOWindowClass.txtImage) if timer_getEnabled(NFOWindowClass.objects['timer']) == 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) timer_setEnabled(NFOWindowClass.objects['timer'],true) end function NFOWindowClass.scrollOnTimer(timer) local x,y = control_getPosition(NFOWindowClass.txtImage) 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 control_setPosition(NFOWindowClass.txtImage,x,y) -- you can remove this IF if NFOWindowClass.CH~=NFOWindowClass.totalHeight then control_setCaption(NFOWindowClass.Form, NFOWindowClass.windowCaption..' position: '.. math.floor(y/(NFOWindowClass.CH-NFOWindowClass.totalHeight)*100).. '%') end if NFOWindowClass.DestY==y then timer_setEnabled(timer,false) end 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=10, -- (default 10) _/ _/ windowMaximumHeight=420, -- 420 / 12 = about 35 lines (default: 600) _/ _/ 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