Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Miniwindows ➜ vertical text

vertical text

It is now over 60 days since the last post. This thread is closed.     Refresh page


Pages: 1  2 

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #15 on Thu 13 Feb 2020 12:35 AM (UTC)
Message
What you could do for the speed issue is cache the rotated text. So, when you want to draw a weapon, see if you already have a miniwindow (not shown) which contains the weapon name rotated. If not, you could make one. From then on, just copy from this rotated window onto the main window.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Zimmy   (31 posts)  Bio
Date Reply #16 on Thu 13 Feb 2020 02:20 AM (UTC)
Message
Nick Gammon said:

What you could do for the speed issue is cache the rotated text. So, when you want to draw a weapon, see if you already have a miniwindow (not shown) which contains the weapon name rotated. If not, you could make one. From then on, just copy from this rotated window onto the main window.

Would there be a difference in performance between creating the cache from miniwindows containing rotated text vs images that are copies of a miniwindow containing the rotated text. Do I need a separate secret miniwindow for each new weapon or can I just have a new image for each weapon?
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #17 on Thu 13 Feb 2020 06:05 AM (UTC)
Message
I don't really understand the question. What is option A and what is option B?

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Zimmy   (31 posts)  Bio
Date Reply #18 on Thu 13 Feb 2020 06:20 AM (UTC)

Amended on Thu 13 Feb 2020 06:28 AM (UTC) by Zimmy

Message
Nick Gammon said:

I don't really understand the question. What is option A and what is option B?


Option A: (what I thought you were suggesting) separate miniwindows for each rotated string.

Option B: using a single miniwindow to generate and copy images of each rotated string (clearing the contents after each time)

Anyways, here's what I have so far. I haven't coded in the cache mechanism yet. The only problem I'm having is with transparency.
[EDIT]Figured out the transparency. Edited the code.


--------------------------------------------------------------------------------
--   VERTICAL FONT
--------------------------------------------------------------------------------
function load_vertical_font(font, size, colour)
    rotated = {}
    WindowCreate(win.."upright", 0, 0, 0, 0, miniwin.pos_center_all, 0, ColourNameToRGB("black"))
    WindowCreate(win.."rotated", 0, 0, 0, 0, miniwin.pos_center_all, 0, ColourNameToRGB("black"))
    WindowFont(win.."upright", "vf", font, size, false, false, false, false)
    local alphabet = "-!?.'abcdefghijklmnopqrstucwxyz "
    alphabet:gsub(".", function(l)
        local w, h = WindowTextWidth(win.."upright", "vf", l), WindowFontInfo(win.."upright", "vf", 1)
        WindowResize(win.."upright", w, h, ColourNameToRGB("purple"))
        WindowRectOp(win.."upright", 2, 0, 0, w, h, ColourNameToRGB("purple"))
        WindowResize(win.."rotated", h, w, ColourNameToRGB("purple"))
        WindowText(win.."upright", "vf", l, 0, 0, w, h, colour, false)
        for x = 1, w do
            for y = 1, h do
                local pixel = WindowGetPixel(win.."upright", x, h - y)
                WindowSetPixel(win.."rotated", y, x, pixel)
                WindowImageFromWindow(win.."main", l, win.."rotated")
                rotated[l] = {x = h, y = w}
            end
        end
    end)
end

function print_vertical_text(text, x1, y1)
    text = string.lower(text)
    text:gsub("[-!?.'a-z ]", function(l)
        WindowDrawImage(win.."main", l, x1, y1, 0, 0, miniwin.image_transparent_copy)
        y1 = y1 + rotated[l].y
    end)
    WindowShow(win.."main", true)
end
--------------------------------------------------------------------------------
--   START EXECUTION HERE
--------------------------------------------------------------------------------
win = "win_"
WIN_X, WIN_Y = 300, 300
WindowCreate(win.."main", 0, 0, WIN_X, WIN_Y, miniwin.pos_center_all, 0, ColourNameToRGB("black"))
load_vertical_font("Dina", 14, ColourNameToRGB("white"))
print_vertical_text("Hello World!", 0, 0)
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #19 on Fri 14 Feb 2020 09:04 PM (UTC)
Message
Your technique seems perfectly acceptable.

Time taken to draw: 0.5 ms.


start = utils.timer ()
print_vertical_text("Hello World!", 0, 0)
print (string.format ("Time taken = %0.4f", utils.timer () - start))

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


52,964 views.

This is page 2, subject is 2 pages long:  [Previous page]  1  2 

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.