Previous Thread
Next Thread
Print Thread
lua draw_text right and center justify #114592
01/25/19 05:58 PM
01/25/19 05:58 PM
Joined: Feb 2014
Posts: 173
G
Golden Child Online content OP
Senior Member
Golden Child  Online Content OP
Senior Member
G
Joined: Feb 2014
Posts: 173
I was fiddling around with the lua draw_text routine and saw that there's an option to call draw_text with a justification parameter like "right" or "center".

But there was no text displayed... because it doesn't have the y coordinate set properly.

Running with the apple2p driver,

emu:pause() manager:machine().screens[":screen"]:draw_text("right",25,"Hello",0xffffffff,0xffff0000)

should display some text on the screen, but it doesn't because of a missing line:

In src/mame/frontend/luaengine.cpp:

Code
                        "draw_text", [this](screen_device &sdev, sol::object xobj, float y, const char *msg, sol::object color, sol::object bcolor) {
                                        int sc_width = sdev.visible_area().width();
                                        int sc_height = sdev.visible_area().height();
                                        auto justify = ui::text_layout::LEFT;
                                        float x = 0;
                                        if(xobj.is<float>())
                                        {
                                                x = std::min(std::max(0.0f, xobj.as<float>()), float(sc_width-1)) / float(sc_width);
                                                y = std::min(std::max(0.0f, y), float(sc_height-1)) / float(sc_height);
                                        }
                                        else if(xobj.is<const char *>())
                                        {
                                                std::string just_str = xobj.as<const char *>();
                                                if(just_str == "right")
                                                        justify = ui::text_layout::RIGHT;
                                                else if(just_str == "center")
                                                        justify = ui::text_layout::CENTER;
// need to set the y coordinate properly
                                                y = std::min(std::max(0.0f, y), float(sc_height-1)) / float(sc_height);

                                        }
                                        else
                                        {
                                                luaL_error(m_lua_state, "Error in param 1 to draw_text");
                                                return;
                                        }




I'm not sure anybody uses this, it's super obscure.

Re: lua draw_text right and center justify [Re: Golden Child] #114593
01/25/19 07:19 PM
01/25/19 07:19 PM
Joined: Jan 2012
Posts: 798
C
crazyc Offline
Senior Member
crazyc  Offline
Senior Member
C
Joined: Jan 2012
Posts: 798
y means pixel row if you use justification for compatibility with xml cheats. Multiply y by mame_manager:ui():get_line_height() to put the text on nonoverlapping rows. It also can't work while paused. Use emu.register_frame_done(function) to make sure it gets displayed.


Who's Online Now
1 registered members (Duke), 150 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Shout Box
Forum Statistics
Forums9
Topics8,625
Posts112,775
Members4,839
Most Online324
Dec 20th, 2018
Powered by UBB.threads™ PHP Forum Software 7.6.1.1
(Release build 20180111)
Page Time: 0.065s Queries: 14 (0.032s) Memory: 5.5856 MB (Peak: 5.7412 MB) Zlib enabled. Server Time: 2019-02-17 11:30:05 UTC