Previous Thread
Next Thread
Print Thread
lua draw_text right and center justify #114592 01/25/19 05:58 PM
Joined: Feb 2014
Posts: 282
G
Golden Child Offline OP
Senior Member
OP Offline
Senior Member
G
Joined: Feb 2014
Posts: 282
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
Joined: Jan 2012
Posts: 800
C
crazyc Offline
Senior Member
Offline
Senior Member
C
Joined: Jan 2012
Posts: 800
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
3 registered members (skylinekiller, nerd4gw, Jim Miller), 138 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
ShoutChat Box
Comment Guidelines: Do post respectful and insightful comments. Don't flame, hate, spam.
Forum Statistics
Forums9
Topics8,675
Posts113,813
Members4,859
Most Online418
Aug 14th, 2019
Powered by UBB.threads™ PHP Forum Software 7.7.3