mirror of
https://github.com/SourMesen/Mesen2.git
synced 2025-04-02 10:21:44 -04:00
Debugger: Lua - Added measureString, added support for text wrapping in drawString
This commit is contained in:
parent
6473c84829
commit
0e36b496b0
9 changed files with 37 additions and 30 deletions
|
@ -1,6 +1,4 @@
|
|||
#include "stdafx.h"
|
||||
|
||||
#ifndef LIBRETRO
|
||||
#include "LuaApi.h"
|
||||
#include "Lua/lua.hpp"
|
||||
#include "Debugger/LuaCallHelper.h"
|
||||
|
@ -17,6 +15,7 @@
|
|||
#include "Shared/Emulator.h"
|
||||
#include "Shared/Video/BaseVideoFilter.h"
|
||||
#include "Shared/Video/DrawScreenBufferCommand.h"
|
||||
#include "Shared/Video/DrawStringCommand.h"
|
||||
#include "Shared/KeyManager.h"
|
||||
#include "Shared/Interfaces/IConsole.h"
|
||||
#include "Shared/Interfaces/IKeyManager.h"
|
||||
|
@ -86,7 +85,9 @@ int LuaApi::GetLibrary(lua_State *lua)
|
|||
{ "addEventCallback", LuaApi::RegisterEventCallback },
|
||||
{ "removeEventCallback", LuaApi::UnregisterEventCallback },
|
||||
|
||||
{ "measureString", LuaApi::MeasureString },
|
||||
{ "drawString", LuaApi::DrawString },
|
||||
|
||||
{ "drawPixel", LuaApi::DrawPixel },
|
||||
{ "drawLine", LuaApi::DrawLine },
|
||||
{ "drawRectangle", LuaApi::DrawRectangle },
|
||||
|
@ -278,7 +279,7 @@ int LuaApi::ConvertAddress(lua_State *lua)
|
|||
checkEnum(MemoryType, memType, "invalid memory type");
|
||||
errorCond(address < 0 || address >= _memoryDumper->GetMemorySize(memType), "address is out of range");
|
||||
|
||||
AddressInfo src { address, memType };
|
||||
AddressInfo src { (int32_t)address, memType };
|
||||
AddressInfo result;
|
||||
if(DebugUtilities::IsRelativeMemory(memType)) {
|
||||
result = _debugger->GetAbsoluteAddress(src);
|
||||
|
@ -398,12 +399,28 @@ int LuaApi::UnregisterEventCallback(lua_State *lua)
|
|||
return l.ReturnCount();
|
||||
}
|
||||
|
||||
int LuaApi::MeasureString(lua_State* lua)
|
||||
{
|
||||
LuaCallHelper l(lua);
|
||||
l.ForceParamCount(2);
|
||||
int maxWidth = l.ReadInteger(0);
|
||||
string text = l.ReadString();
|
||||
checkminparams(1);
|
||||
|
||||
TextSize size = DrawStringCommand::MeasureString(text, maxWidth);
|
||||
lua_newtable(lua);
|
||||
lua_pushintvalue(width, size.X);
|
||||
lua_pushintvalue(height, size.Y);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int LuaApi::DrawString(lua_State *lua)
|
||||
{
|
||||
LuaCallHelper l(lua);
|
||||
l.ForceParamCount(7);
|
||||
l.ForceParamCount(8);
|
||||
int displayDelay = l.ReadInteger(0);
|
||||
int frameCount = l.ReadInteger(1);
|
||||
int maxWidth = l.ReadInteger(0);
|
||||
int backColor = l.ReadInteger(0);
|
||||
int color = l.ReadInteger(0xFFFFFF);
|
||||
string text = l.ReadString();
|
||||
|
@ -412,7 +429,7 @@ int LuaApi::DrawString(lua_State *lua)
|
|||
checkminparams(3);
|
||||
|
||||
int startFrame = _emu->GetFrameCount() + displayDelay;
|
||||
_emu->GetDebugHud()->DrawString(x, y, text, color, backColor, frameCount, startFrame);
|
||||
_emu->GetDebugHud()->DrawString(x, y, text, color, backColor, frameCount, startFrame, maxWidth);
|
||||
|
||||
return l.ReturnCount();
|
||||
}
|
||||
|
@ -934,6 +951,4 @@ int LuaApi::SetState(lua_State* lua)
|
|||
lua_settable(lua, -3);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
|
@ -30,8 +30,10 @@ public:
|
|||
static int UnregisterMemoryCallback(lua_State *lua);
|
||||
static int RegisterEventCallback(lua_State *lua);
|
||||
static int UnregisterEventCallback(lua_State *lua);
|
||||
|
||||
|
||||
static int MeasureString(lua_State* lua);
|
||||
static int DrawString(lua_State *lua);
|
||||
|
||||
static int DrawLine(lua_State *lua);
|
||||
static int DrawPixel(lua_State *lua);
|
||||
static int DrawRectangle(lua_State *lua);
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#include "stdafx.h"
|
||||
#ifndef LIBRETRO
|
||||
#include "LuaCallHelper.h"
|
||||
|
||||
LuaCallHelper::LuaCallHelper(lua_State *lua) : _lua(lua)
|
||||
|
@ -145,6 +144,4 @@ void LuaCallHelper::Return(string value)
|
|||
int LuaCallHelper::ReturnCount()
|
||||
{
|
||||
return _returnCount;
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
|
@ -280,7 +280,7 @@ uint16_t NesCpu::FetchOperand()
|
|||
default: break;
|
||||
}
|
||||
|
||||
#if !defined(LIBRETRO) && !defined(DUMMYCPU)
|
||||
#if !defined(DUMMYCPU)
|
||||
if(_lastCrashWarning == 0 || _state.CycleCount - _lastCrashWarning > 5000000) {
|
||||
MessageManager::DisplayMessage("Error", "GameCrash", "Invalid OP code - CPU crashed.");
|
||||
_lastCrashWarning = _state.CycleCount;
|
||||
|
|
|
@ -161,7 +161,6 @@ void MessageManager::DisplayMessage(string title, string message, string param1,
|
|||
|
||||
void MessageManager::Log(string message)
|
||||
{
|
||||
#ifndef LIBRETRO
|
||||
auto lock = _logLock.AcquireSafe();
|
||||
if(message.empty()) {
|
||||
message = "------------------------------------------------------";
|
||||
|
@ -170,11 +169,6 @@ void MessageManager::Log(string message)
|
|||
_log.pop_front();
|
||||
}
|
||||
_log.push_back(message);
|
||||
#else
|
||||
if(MessageManager::_messageManager) {
|
||||
MessageManager::_messageManager->DisplayMessage("", message + "\n");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void MessageManager::ClearLog()
|
||||
|
|
|
@ -226,14 +226,15 @@ public:
|
|||
_backColor = (~backColor & 0xFF000000) | (backColor & 0xFFFFFF);
|
||||
}
|
||||
|
||||
static TextSize MeasureString(string text, uint32_t maxWidth = 0)
|
||||
static TextSize MeasureString(string& text, uint32_t maxWidth = 0)
|
||||
{
|
||||
uint32_t maxX = 0;
|
||||
uint32_t x = 0;
|
||||
uint32_t y = 0;
|
||||
uint32_t lineHeight = 9;
|
||||
|
||||
auto newLine = [&x, &y, &lineHeight]() {
|
||||
auto newLine = [&]() {
|
||||
maxX = std::max(x, maxX);
|
||||
x = 0;
|
||||
y += lineHeight;
|
||||
lineHeight = 9;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "stdafx.h"
|
||||
#include "PlatformUtilities.h"
|
||||
|
||||
#if !defined(LIBRETRO) && defined(_WIN32)
|
||||
#ifdef _WIN32
|
||||
#include <Windows.h>
|
||||
#endif
|
||||
|
||||
|
@ -11,21 +11,21 @@ void PlatformUtilities::DisableScreensaver()
|
|||
{
|
||||
//Prevent screensaver/etc from starting while using the emulator
|
||||
//DirectInput devices apparently do not always count as user input
|
||||
#if !defined(LIBRETRO) && defined(_WIN32)
|
||||
#ifdef _WIN32
|
||||
SetThreadExecutionState(ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED | ES_CONTINUOUS);
|
||||
#endif
|
||||
}
|
||||
|
||||
void PlatformUtilities::EnableScreensaver()
|
||||
{
|
||||
#if !defined(LIBRETRO) && defined(_WIN32)
|
||||
#ifdef _WIN32
|
||||
SetThreadExecutionState(ES_CONTINUOUS);
|
||||
#endif
|
||||
}
|
||||
|
||||
void PlatformUtilities::EnableHighResolutionTimer()
|
||||
{
|
||||
#if !defined(LIBRETRO) && defined(_WIN32)
|
||||
#ifdef _WIN32
|
||||
//Request a 1ms timer resolution on Windows while a game is running
|
||||
if(!_highResTimerEnabled) {
|
||||
timeBeginPeriod(1);
|
||||
|
@ -36,7 +36,7 @@ void PlatformUtilities::EnableHighResolutionTimer()
|
|||
|
||||
void PlatformUtilities::RestoreTimerResolution()
|
||||
{
|
||||
#if !defined(LIBRETRO) && defined(_WIN32)
|
||||
#ifdef _WIN32
|
||||
if(_highResTimerEnabled) {
|
||||
timeEndPeriod(1);
|
||||
_highResTimerEnabled = false;
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
class Socket
|
||||
{
|
||||
private:
|
||||
#ifndef LIBRETRO
|
||||
#ifdef _WIN32
|
||||
bool _cleanupWSA = false;
|
||||
#endif
|
||||
|
@ -13,7 +12,6 @@ private:
|
|||
uintptr_t _socket = (uintptr_t)~0;
|
||||
bool _connectionError = false;
|
||||
int32_t _UPnPPort = -1;
|
||||
#endif
|
||||
|
||||
public:
|
||||
Socket();
|
||||
|
|
|
@ -11,7 +11,7 @@ namespace utf8 {
|
|||
static std::string encode(const std::u16string &wstr);
|
||||
};
|
||||
|
||||
#if defined(_WIN32) && !defined(LIBRETRO)
|
||||
#ifdef _WIN32
|
||||
class ifstream : public std::ifstream
|
||||
{
|
||||
public:
|
||||
|
|
Loading…
Add table
Reference in a new issue