RetroArch/menu/drivers/xui.cpp

727 lines
19 KiB
C++
Raw Normal View History

2012-04-21 21:13:50 +00:00
/* RetroArch - A frontend for libretro.
2014-01-01 00:50:59 +00:00
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
2016-01-10 03:06:50 +00:00
* Copyright (C) 2011-2016 - Daniel De Matteis
2015-01-07 17:24:13 +00:00
* Copyright (C) 2015- - Swizzy
*
2012-04-21 21:13:50 +00:00
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
2012-04-21 21:13:50 +00:00
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
2012-04-21 21:31:57 +00:00
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
2012-01-23 21:22:54 +00:00
#include <stdint.h>
2015-01-26 09:54:13 +00:00
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <xtl.h>
#include <xui.h>
#include <xuiapp.h>
#include <file/file_path.h>
2015-06-17 17:48:55 +00:00
#include <string/string_list.h>
2015-11-17 10:22:00 +00:00
#include <queues/message_queue.h>
2015-10-03 01:15:47 +00:00
#include "menu_generic.h"
#include "../menu_driver.h"
2015-11-17 10:23:42 +00:00
#include "../menu_animation.h"
#include "../menu_entry.h"
2015-10-17 17:38:33 +00:00
#include "../menu_entries.h"
2015-01-26 09:54:13 +00:00
#include "../menu_input.h"
2015-12-09 08:53:43 +00:00
#include "../menu_navigation.h"
2015-06-02 19:41:09 +00:00
#include "../menu_setting.h"
2015-10-18 05:15:54 +00:00
#include "../menu_display.h"
#include "../../gfx/video_context_driver.h"
2014-10-28 18:54:23 +00:00
#include "../../general.h"
2015-01-07 21:23:45 +00:00
#include "../../gfx/d3d/d3d.h"
#define XUI_CONTROL_NAVIGATE_OK (XUI_CONTROL_NAVIGATE_RIGHT + 1)
2014-02-28 20:24:39 +00:00
#define FONT_WIDTH 5
#define FONT_HEIGHT 10
#define FONT_WIDTH_STRIDE (FONT_WIDTH + 1)
#define FONT_HEIGHT_STRIDE (FONT_HEIGHT + 1)
2014-02-28 20:15:16 +00:00
#define RXUI_TERM_START_X 15
#define RXUI_TERM_START_Y 27
#define RXUI_TERM_WIDTH(width) (((width - RXUI_TERM_START_X - 15) / (FONT_WIDTH_STRIDE)))
#define RXUI_TERM_HEIGHT(height) (((height - RXUI_TERM_START_Y - 15) / (FONT_HEIGHT_STRIDE)) - 1)
2013-03-30 07:16:58 +00:00
HXUIOBJ m_menulist;
HXUIOBJ m_menutitle;
HXUIOBJ m_menutitlebottom;
2015-01-12 23:48:26 +00:00
HXUIOBJ m_background;
2013-05-06 01:05:21 +00:00
HXUIOBJ m_back;
HXUIOBJ root_menu;
HXUIOBJ current_menu;
static msg_queue_t *xui_msg_queue;
class CRetroArch : public CXuiModule
{
protected:
virtual HRESULT RegisterXuiClasses();
virtual HRESULT UnregisterXuiClasses();
};
#define CREATE_CLASS(class_type, class_name) \
class class_type: public CXuiSceneImpl \
{ \
public: \
HRESULT OnInit( XUIMessageInit* pInitData, int & bHandled ); \
HRESULT DispatchMessageMap(XUIMessage *pMessage) \
{ \
if (pMessage->dwMessage == XM_INIT) \
{ \
XUIMessageInit *pData = (XUIMessageInit *) pMessage->pvData; \
return OnInit(pData, pMessage->bHandled); \
} \
return __super::DispatchMessageMap(pMessage); \
} \
\
static HRESULT Register() \
{ \
HXUICLASS hClass; \
XUIClass cls; \
memset(&cls, 0x00, sizeof(cls)); \
cls.szClassName = class_name; \
cls.szBaseClassName = XUI_CLASS_SCENE; \
cls.Methods.CreateInstance = (PFN_CREATEINST) (CreateInstance); \
cls.Methods.DestroyInstance = (PFN_DESTROYINST) DestroyInstance; \
cls.Methods.ObjectProc = (PFN_OBJECT_PROC) _ObjectProc; \
cls.pPropDefs = _GetPropDef(&cls.dwPropDefCount); \
HRESULT hr = XuiRegisterClass(&cls, &hClass); \
if (FAILED(hr)) \
return hr; \
return S_OK; \
} \
\
static HRESULT APIENTRY CreateInstance(HXUIOBJ hObj, void **ppvObj) \
{ \
*ppvObj = NULL; \
class_type *pThis = new class_type(); \
if (!pThis) \
return E_OUTOFMEMORY; \
pThis->m_hObj = hObj; \
HRESULT hr = pThis->OnCreate(); \
if (FAILED(hr)) \
{ \
DestroyInstance(pThis); \
return hr; \
} \
*ppvObj = pThis; \
return S_OK; \
} \
\
static HRESULT APIENTRY DestroyInstance(void *pvObj) \
{ \
class_type *pThis = (class_type *) pvObj; \
delete pThis; \
return S_OK; \
} \
}
2013-05-09 16:44:35 +00:00
CREATE_CLASS(CRetroArchMain, L"RetroArchMain");
2012-05-29 13:25:39 +00:00
CRetroArch app;
wchar_t strw_buffer[PATH_MAX_LENGTH];
2012-01-22 20:47:34 +00:00
/* Register custom classes */
2012-04-21 21:48:05 +00:00
HRESULT CRetroArch::RegisterXuiClasses (void)
{
2012-04-21 22:11:48 +00:00
CRetroArchMain::Register();
2012-05-29 02:39:54 +00:00
return 0;
}
/* Unregister custom classes */
2012-04-21 21:48:05 +00:00
HRESULT CRetroArch::UnregisterXuiClasses (void)
{
2013-05-08 00:11:06 +00:00
XuiUnregisterClass(L"RetroArchMain");
2012-05-29 02:39:54 +00:00
return 0;
}
HRESULT CRetroArchMain::OnInit(XUIMessageInit * pInitData, BOOL& bHandled)
{
GetChildById(L"XuiMenuList", &m_menulist);
GetChildById(L"XuiTxtTitle", &m_menutitle);
GetChildById(L"XuiTxtBottom", &m_menutitlebottom);
2015-01-12 23:48:26 +00:00
GetChildById(L"XuiBackground", &m_background);
2015-01-10 12:00:47 +00:00
if (XuiHandleIsValid(m_menutitlebottom))
{
2015-06-12 22:09:09 +00:00
char str[PATH_MAX_LENGTH] = {0};
2015-08-17 16:14:51 +00:00
if (menu_entries_get_core_title(str, sizeof(str)) == 0)
{
mbstowcs(strw_buffer, str, sizeof(strw_buffer) / sizeof(wchar_t));
XuiTextElementSetText(m_menutitlebottom, strw_buffer);
}
2015-01-10 12:00:47 +00:00
}
2012-05-29 02:39:54 +00:00
return 0;
}
2015-02-01 07:13:09 +00:00
HRESULT XuiTextureLoader(IXuiDevice *pDevice, LPCWSTR szFileName,
XUIImageInfo *pImageInfo, IDirect3DTexture9 **ppTex)
2015-01-12 23:48:26 +00:00
{
2015-02-01 07:13:09 +00:00
D3DXIMAGE_INFO pSrc;
2015-06-12 14:17:19 +00:00
CONST BYTE *pbTextureData = 0;
UINT cbTextureData = 0;
HXUIRESOURCE hResource = 0;
BOOL bIsMemoryResource = FALSE;
IDirect3DDevice9 * d3dDevice = NULL;
HRESULT hr =
XuiResourceOpenNoLoc(szFileName, &hResource, &bIsMemoryResource);
2015-02-01 07:13:09 +00:00
if (FAILED(hr))
return hr;
if (bIsMemoryResource)
{
hr = XuiResourceGetBuffer(hResource, &pbTextureData);
if (FAILED(hr))
goto cleanup;
cbTextureData = XuiResourceGetTotalSize(hResource);
}
else
{
hr = XuiResourceRead(hResource, NULL, 0, &cbTextureData);
if (FAILED(hr))
goto cleanup;
pbTextureData = (BYTE *)XuiAlloc(cbTextureData);
if (pbTextureData == 0)
{
hr = E_OUTOFMEMORY;
goto cleanup;
}
2015-06-12 14:17:19 +00:00
hr = XuiResourceRead(hResource,
(BYTE*)pbTextureData, cbTextureData, &cbTextureData);
2015-02-01 07:13:09 +00:00
if (FAILED(hr))
goto cleanup;
XuiResourceClose(hResource);
hResource = 0;
}
/* Cast our d3d device into our IDirect3DDevice9* interface */
d3dDevice = (IDirect3DDevice9*)pDevice->GetD3DDevice();
if(!d3dDevice)
goto cleanup;
/* Create our texture based on our conditions */
hr = D3DXCreateTextureFromFileInMemoryEx(
d3dDevice,
pbTextureData,
cbTextureData,
D3DX_DEFAULT_NONPOW2,
D3DX_DEFAULT_NONPOW2,
1,
D3DUSAGE_CPU_CACHED_MEMORY,
D3DFMT_LIN_A8R8G8B8,
D3DPOOL_DEFAULT,
D3DX_FILTER_NONE,
D3DX_FILTER_NONE,
0,
&pSrc,
NULL,
ppTex
);
if(hr != D3DXERR_INVALIDDATA )
{
2016-02-21 08:54:53 +00:00
pImageInfo->Depth = pSrc.Depth;
pImageInfo->Format = pSrc.Format;
pImageInfo->Height = pSrc.Height;
2015-02-01 07:13:09 +00:00
pImageInfo->ImageFileFormat = pSrc.ImageFileFormat;
2016-02-21 08:54:53 +00:00
pImageInfo->MipLevels = pSrc.MipLevels;
pImageInfo->ResourceType = pSrc.ResourceType;
pImageInfo->Width = pSrc.Width;
2015-02-01 07:13:09 +00:00
}
else
RARCH_ERR("D3DXERR_INVALIDDATA Encountered\n");
2015-01-12 23:48:26 +00:00
cleanup:
2015-02-01 07:13:09 +00:00
if (bIsMemoryResource && hResource != 0)
XuiResourceReleaseBuffer(hResource, pbTextureData);
else
XuiFree((LPVOID)pbTextureData);
if (hResource != 0)
XuiResourceClose(hResource);
return hr;
2015-01-12 23:48:26 +00:00
}
2016-01-12 08:23:17 +00:00
static void* xui_init(void **userdata)
2012-01-22 20:47:34 +00:00
{
HRESULT hr;
2015-06-12 14:17:19 +00:00
d3d_video_t *d3d = NULL;
D3DPRESENT_PARAMETERS d3dpp = {0};
video_info_t video_info = {0};
2014-05-30 20:37:23 +00:00
TypefaceDescriptor typeface = {0};
2015-06-12 14:17:19 +00:00
settings_t *settings = config_get_ptr();
2015-12-05 11:50:56 +00:00
menu_handle_t *menu = (menu_handle_t*)calloc(1, sizeof(*menu));
if (!menu)
return NULL;
2013-04-18 13:04:09 +00:00
d3d = (d3d_video_t*)video_driver_get_ptr(false);
if (d3d->resolution_hd_enable)
RARCH_LOG("HD menus enabled.\n");
2015-03-20 21:22:06 +00:00
video_info.vsync = settings->video.vsync;
2012-11-20 01:51:00 +00:00
video_info.force_aspect = false;
2015-03-20 21:22:06 +00:00
video_info.smooth = settings->video.smooth;
video_info.input_scale = 2;
video_info.fullscreen = true;
video_info.rgb32 = false;
2012-11-20 01:51:00 +00:00
2014-03-05 21:10:36 +00:00
d3d_make_d3dpp(d3d, &video_info, &d3dpp);
2015-01-12 23:48:26 +00:00
2016-02-21 08:54:53 +00:00
hr = app.InitShared(d3d->dev, &d3dpp,
(PFN_XUITEXTURELOADER)XuiTextureLoader);
if (FAILED(hr))
{
2012-04-21 21:25:32 +00:00
RARCH_ERR("Failed initializing XUI application.\n");
goto error;
}
/* Register font */
2015-03-21 21:48:27 +00:00
typeface.szTypeface = L"Arial Unicode MS";
typeface.szLocator = L"file://game:/media/rarch.ttf";
typeface.szReserved1 = NULL;
2013-05-09 16:44:35 +00:00
hr = XuiRegisterTypeface( &typeface, TRUE );
if (FAILED(hr))
{
2012-04-21 21:25:32 +00:00
RARCH_ERR("Failed to register default typeface.\n");
goto error;
}
hr = XuiLoadVisualFromBinary(
L"file://game:/media/rarch_scene_skin.xur", NULL);
if (FAILED(hr))
{
2012-04-21 21:25:32 +00:00
RARCH_ERR("Failed to load skin.\n");
goto error;
}
hr = XuiSceneCreate(d3d->resolution_hd_enable ?
L"file://game:/media/hd/" : L"file://game:/media/sd/",
L"rarch_main.xur", NULL, &root_menu);
if (FAILED(hr))
{
2012-04-21 21:25:32 +00:00
RARCH_ERR("Failed to create scene 'rarch_main.xur'.\n");
goto error;
}
current_menu = root_menu;
hr = XuiSceneNavigateFirst(app.GetRootObj(),
current_menu, XUSER_INDEX_FOCUS);
if (FAILED(hr))
{
RARCH_ERR("XuiSceneNavigateFirst failed.\n");
goto error;
}
2015-03-22 18:15:34 +00:00
video_driver_set_texture_frame(NULL,
true, 0, 0, 1.0f);
2013-04-18 13:04:09 +00:00
xui_msg_queue = msg_queue_new(16);
return menu;
error:
free(menu);
return NULL;
}
2016-01-12 08:23:17 +00:00
static void xui_free(void *data)
{
(void)data;
2012-05-29 13:25:39 +00:00
app.Uninit();
if (xui_msg_queue)
msg_queue_free(xui_msg_queue);
}
static void xui_render_message(const char *msg)
{
2015-06-12 14:17:19 +00:00
struct font_params font_parms = {0};
size_t i = 0;
size_t j = 0;
struct string_list *list = NULL;
2015-12-05 11:50:56 +00:00
d3d_video_t *d3d = (d3d_video_t*)video_driver_get_ptr(false);
2015-01-27 14:35:31 +00:00
2015-02-11 05:59:19 +00:00
if (!d3d)
2014-12-03 21:26:35 +00:00
return;
2015-02-11 05:59:19 +00:00
list = string_split(msg, "\n");
2014-12-03 21:26:35 +00:00
2015-02-11 05:59:19 +00:00
if (!list)
2014-12-03 21:26:35 +00:00
return;
2015-02-11 05:59:19 +00:00
if (list->elems == 0)
goto end;
2014-12-03 21:26:35 +00:00
for (i = 0; i < list->size; i++, j++)
{
2015-06-12 22:09:09 +00:00
char *msg = (char*)list->elems[i].data;
unsigned msglen = strlen(msg);
float msg_width = d3d->resolution_hd_enable ? 160 : 100;
2014-12-03 21:26:35 +00:00
float msg_height = 120;
float msg_offset = 32;
2016-02-21 08:54:53 +00:00
font_parms.x = msg_width;
font_parms.y = msg_height + (msg_offset * j);
2014-12-03 21:26:35 +00:00
font_parms.scale = 21;
2015-03-22 17:48:24 +00:00
video_driver_set_osd_msg(msg, &font_parms, NULL);
2014-12-03 21:26:35 +00:00
}
2015-02-11 05:59:19 +00:00
end:
string_list_free(list);
}
2016-01-12 08:23:17 +00:00
static void xui_frame(void *data)
{
2015-02-01 07:13:09 +00:00
XUIMessage msg;
XUIMessageRender msgRender;
D3DXMATRIX matOrigView;
LPDIRECT3DDEVICE d3dr;
2016-02-21 08:54:53 +00:00
const char *message = NULL;
2015-12-05 11:50:56 +00:00
D3DVIEWPORT vp_full = {0};
2015-12-10 14:45:05 +00:00
d3d_video_t *d3d = (d3d_video_t*)video_driver_get_ptr(false);
if (!d3d)
return;
d3dr = (LPDIRECT3DDEVICE)d3d->dev;
if (!d3dr)
return;
2015-11-17 10:22:00 +00:00
menu_display_ctl(MENU_DISPLAY_CTL_SET_VIEWPORT, NULL);
2014-03-05 02:55:16 +00:00
app.RunFrame();
XuiTimersRun();
2013-05-09 16:44:35 +00:00
XuiRenderBegin( app.GetDC(), D3DCOLOR_ARGB( 255, 0, 0, 0 ) );
2013-04-19 19:04:08 +00:00
2013-05-09 16:44:35 +00:00
XuiRenderGetViewTransform( app.GetDC(), &matOrigView );
2013-04-19 19:04:08 +00:00
2016-02-21 08:54:53 +00:00
XuiMessageRender( &msg, &msgRender,
app.GetDC(), 0xffffffff, XUI_BLEND_NORMAL );
2013-05-09 16:44:35 +00:00
XuiSendMessage( app.GetRootObj(), &msg );
2013-04-19 19:04:08 +00:00
2013-05-09 16:44:35 +00:00
XuiRenderSetViewTransform( app.GetDC(), &matOrigView );
2013-04-19 19:04:08 +00:00
2016-02-13 04:17:36 +00:00
runloop_ctl(RUNLOOP_CTL_MSG_QUEUE_PULL, &message);
if (message)
xui_render_message(message);
else
{
2016-02-13 04:17:36 +00:00
runloop_ctl(RUNLOOP_CTL_MSG_QUEUE_PULL, &message);
if (message)
xui_render_message(message);
}
2013-05-09 16:44:35 +00:00
XuiRenderEnd( app.GetDC() );
2015-11-17 10:22:00 +00:00
menu_display_ctl(MENU_DISPLAY_CTL_UNSET_VIEWPORT, NULL);
}
static void blit_line(int x, int y, const char *message, bool green)
2014-02-28 16:50:55 +00:00
{
}
2016-01-12 08:23:17 +00:00
static void xui_render_background(void)
2014-02-28 16:50:55 +00:00
{
2016-02-21 08:54:53 +00:00
if (menu_display_ctl(MENU_DISPLAY_CTL_LIBRETRO_RUNNING, NULL))
2015-01-12 23:48:26 +00:00
XuiElementSetShow(m_background, FALSE);
else
XuiElementSetShow(m_background, TRUE);
2014-02-28 16:50:55 +00:00
}
2016-01-12 08:23:17 +00:00
static void xui_render_messagebox(void *data, const char *message)
2014-02-28 16:50:55 +00:00
{
msg_queue_clear(xui_msg_queue);
msg_queue_push(xui_msg_queue, message, 2, 1);
2014-02-28 16:50:55 +00:00
}
2016-01-12 08:23:17 +00:00
static void xui_set_list_text(int index, const wchar_t* leftText,
2015-02-01 07:13:09 +00:00
const wchar_t* rightText)
2014-02-28 16:50:55 +00:00
{
2015-02-01 07:13:09 +00:00
LPCWSTR currText;
float width, height;
XUIRect pRect;
D3DXVECTOR3 textPos, rightEdgePos;
HXUIOBJ hVisual = NULL, hControl = NULL, hTextLeft = NULL,
hTextRight = NULL, hRightEdge = NULL;
hControl = XuiListGetItemControl(m_menulist, index);
if (XuiHandleIsValid(hControl))
XuiControlGetVisual(hControl, &hVisual);
if(!XuiHandleIsValid(hVisual))
return;
XuiElementGetChildById(hVisual, L"LeftText", &hTextLeft);
if (!XuiHandleIsValid(hTextLeft))
return;
currText = XuiTextElementGetText(hTextLeft);
XuiElementGetBounds(hTextLeft, &width, &height);
if (!currText || wcscmp(currText, leftText) || width <= 5)
{
XuiTextElementMeasureText(hTextLeft, leftText, &pRect);
XuiElementSetBounds(hTextLeft, pRect.GetWidth(), height);
}
XuiTextElementSetText(hTextLeft, leftText);
XuiElementGetChildById(hVisual, L"RightText", &hTextRight);
if(XuiHandleIsValid(hTextRight))
{
currText = XuiTextElementGetText(hTextRight);
XuiElementGetBounds(hTextRight, &width, &height);
if (!currText || wcscmp(currText, rightText) || width <= 5)
{
XuiTextElementMeasureText(hTextRight, rightText, &pRect);
XuiElementSetBounds(hTextRight, pRect.GetWidth(), height);
XuiElementGetPosition(hTextLeft, &textPos);
XuiElementGetChildById(hVisual, L"graphic_CapRight", &hRightEdge);
XuiElementGetPosition(hRightEdge, &rightEdgePos);
textPos.x = rightEdgePos.x - (pRect.GetWidth() + textPos.x);
XuiElementSetPosition(hTextRight, &textPos);
}
XuiTextElementSetText(hTextRight, rightText);
}
2015-01-10 12:00:47 +00:00
}
2014-02-28 16:50:55 +00:00
2016-01-12 08:23:17 +00:00
static void xui_render(void *data)
2015-01-10 12:00:47 +00:00
{
uint64_t *frame_count;
bool display_kb, msg_force;
unsigned fb_width;
2015-09-25 13:00:13 +00:00
size_t end, i, selection;
2015-06-12 22:09:09 +00:00
char title[PATH_MAX_LENGTH] = {0};
2015-06-13 14:22:05 +00:00
const char *dir = NULL;
const char *label = NULL;
unsigned menu_type = 0;
video_driver_ctl(RARCH_DISPLAY_CTL_GET_FRAME_COUNT, &frame_count);
2015-01-10 12:00:47 +00:00
menu_display_ctl(MENU_DISPLAY_CTL_WIDTH, &fb_width);
menu_display_ctl(MENU_DISPLAY_CTL_MSG_FORCE, &msg_force);
2015-06-15 00:37:32 +00:00
if (
2015-12-11 20:41:59 +00:00
menu_entries_ctl(MENU_ENTRIES_CTL_NEEDS_REFRESH, NULL)
2015-12-05 12:49:22 +00:00
&& menu_driver_ctl(RARCH_MENU_CTL_IS_ALIVE, NULL)
&& !msg_force
2015-06-15 00:37:32 +00:00
)
2015-01-10 12:00:47 +00:00
return;
2015-11-17 10:22:00 +00:00
menu_display_ctl(MENU_DISPLAY_CTL_UNSET_FRAMEBUFFER_DIRTY_FLAG, NULL);
menu_animation_ctl(MENU_ANIMATION_CTL_CLEAR_ACTIVE, NULL);
2015-03-08 18:51:25 +00:00
2016-01-12 08:23:17 +00:00
xui_render_background();
2015-01-10 12:00:47 +00:00
if (XuiHandleIsValid(m_menutitle))
{
2015-05-14 22:07:07 +00:00
menu_entries_get_title(title, sizeof(title));
2015-01-10 12:00:47 +00:00
mbstowcs(strw_buffer, title, sizeof(strw_buffer) / sizeof(wchar_t));
XuiTextElementSetText(m_menutitle, strw_buffer);
2015-11-17 10:23:42 +00:00
menu_animation_ticker_str(title, RXUI_TERM_WIDTH(fb_width) - 3,
(unsigned int)*frame_count / 15, title, true);
2015-01-10 12:00:47 +00:00
}
if (XuiHandleIsValid(m_menutitle))
{
2015-08-17 16:14:51 +00:00
if (menu_entries_get_core_title(title, sizeof(title)) == 0)
{
mbstowcs(strw_buffer, title, sizeof(strw_buffer) / sizeof(wchar_t));
XuiTextElementSetText(m_menutitlebottom, strw_buffer);
}
2015-01-10 12:00:47 +00:00
}
2015-05-14 22:03:06 +00:00
end = menu_entries_get_end();
2015-01-10 12:00:47 +00:00
for (i = 0; i < end; i++)
{
2015-11-17 10:26:29 +00:00
char entry_path[PATH_MAX_LENGTH] = {0};
char entry_value[PATH_MAX_LENGTH] = {0};
wchar_t msg_right[PATH_MAX_LENGTH] = {0};
wchar_t msg_left[PATH_MAX_LENGTH] = {0};
2015-06-01 12:59:15 +00:00
menu_entry_get_value(i, entry_value, sizeof(entry_value));
menu_entry_get_path(i, entry_path, sizeof(entry_path));
mbstowcs(msg_left, entry_path, sizeof(msg_left) / sizeof(wchar_t));
2015-06-01 12:59:15 +00:00
mbstowcs(msg_right, entry_value, sizeof(msg_right) / sizeof(wchar_t));
2016-01-12 08:23:17 +00:00
xui_set_list_text(i, msg_left, msg_right);
}
2015-09-25 13:00:13 +00:00
if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection))
return;
XuiListSetCurSelVisible(m_menulist, selection);
2015-01-10 12:00:47 +00:00
2015-09-26 00:52:05 +00:00
menu_input_ctl(MENU_INPUT_CTL_KEYBOARD_DISPLAY, &display_kb);
2015-09-25 20:50:43 +00:00
if (display_kb)
2015-01-10 12:00:47 +00:00
{
2015-06-12 22:09:09 +00:00
char msg[1024] = {0};
2015-09-25 20:50:43 +00:00
const char *str = NULL, *label = NULL;
2015-09-26 00:52:05 +00:00
menu_input_ctl(MENU_INPUT_CTL_KEYBOARD_BUFF_PTR, &str);
menu_input_ctl(MENU_INPUT_CTL_KEYBOARD_LABEL, &label);
2015-06-12 22:09:09 +00:00
2015-01-10 12:00:47 +00:00
if (!str)
str = "";
2015-11-17 10:26:29 +00:00
snprintf(msg, sizeof(msg), "%s\n%s", label, str);
2016-01-12 08:23:17 +00:00
xui_render_messagebox(msg);
2015-01-10 12:00:47 +00:00
}
2014-02-28 16:50:55 +00:00
}
2016-01-12 08:23:17 +00:00
static void xui_populate_entries(const char *path,
const char *label, unsigned i)
2014-03-08 05:15:52 +00:00
{
2015-09-25 13:00:13 +00:00
size_t selection;
if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection))
return;
2014-08-31 17:29:42 +00:00
(void)label;
(void)path;
2014-08-31 17:29:42 +00:00
2015-09-25 13:00:13 +00:00
XuiListSetCurSelVisible(m_menulist, selection);
2014-03-08 05:15:52 +00:00
}
2014-02-28 16:50:55 +00:00
2016-01-12 08:23:17 +00:00
static void xui_navigation_clear(void *data, bool pending_push)
2014-04-13 21:41:47 +00:00
{
2015-09-25 13:00:13 +00:00
size_t selection;
if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection))
return;
2015-09-25 13:00:13 +00:00
XuiListSetCurSelVisible(m_menulist, selection);
2014-04-13 21:41:47 +00:00
}
2016-01-12 08:23:17 +00:00
static void xui_navigation_set_visible(void *data)
2014-04-13 21:41:47 +00:00
{
2015-09-25 13:00:13 +00:00
size_t selection;
if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection))
return;
2015-09-25 13:00:13 +00:00
XuiListSetCurSelVisible(m_menulist, selection);
2014-04-13 21:41:47 +00:00
}
2016-01-12 08:23:17 +00:00
static void xui_navigation_alphabet(void *data, size_t *ptr_out)
2014-04-13 21:41:47 +00:00
{
XuiListSetCurSelVisible(m_menulist, *ptr_out);
}
2016-01-12 08:23:17 +00:00
static void xui_list_insert(void *data,
file_list_t *list,
2014-09-09 04:25:52 +00:00
const char *path, const char *, size_t list_size)
2014-04-13 22:09:52 +00:00
{
2015-06-12 22:09:09 +00:00
wchar_t buf[PATH_MAX_LENGTH] = {0};
2014-04-13 22:09:52 +00:00
XuiListInsertItems(m_menulist, list_size, 1);
mbstowcs(buf, path, sizeof(buf) / sizeof(wchar_t));
XuiListSetText(m_menulist, list_size, buf);
}
2016-01-12 08:23:17 +00:00
static void xui_list_free(file_list_t *list, size_t idx,
size_t list_size)
2014-04-13 22:09:52 +00:00
{
2015-02-01 07:13:09 +00:00
int x = XuiListGetItemCount( m_menulist );
(void)idx;
2015-02-01 07:13:09 +00:00
2015-04-03 00:41:37 +00:00
if( list_size > x)
2015-02-01 07:13:09 +00:00
list_size = x;
2015-04-03 00:41:37 +00:00
if( list_size > 0)
2015-02-01 07:13:09 +00:00
XuiListDeleteItems(m_menulist, 0, list_size);
2014-04-13 22:09:52 +00:00
}
2016-01-12 08:23:17 +00:00
static void xui_list_clear(file_list_t *list)
2014-04-13 22:09:52 +00:00
{
2016-02-21 08:54:53 +00:00
XuiListDeleteItems(m_menulist,
0, XuiListGetItemCount(m_menulist));
2014-04-13 22:09:52 +00:00
}
2016-01-12 08:23:17 +00:00
static void xui_list_set_selection(void *data, file_list_t *list)
2014-04-13 22:09:52 +00:00
{
if (list)
2016-02-21 08:54:53 +00:00
XuiListSetCurSel(m_menulist,
file_list_get_directory_ptr(list));
2014-04-13 22:09:52 +00:00
}
static int xui_environ(enum menu_environ_cb type, void *data)
2015-07-07 22:37:44 +00:00
{
switch (type)
{
2015-11-17 10:28:08 +00:00
case 0:
2015-07-07 22:37:44 +00:00
default:
return -1;
}
return 0;
}
2016-01-12 08:23:17 +00:00
menu_ctx_driver_t menu_ctx_xui = {
NULL,
2016-01-12 08:23:17 +00:00
xui_render_messagebox,
generic_menu_iterate,
2016-01-12 08:23:17 +00:00
xui_render,
xui_frame,
xui_init,
xui_free,
NULL,
NULL,
2016-01-12 08:23:17 +00:00
xui_populate_entries,
2015-02-11 20:06:50 +00:00
NULL,
2016-01-12 08:23:17 +00:00
xui_navigation_clear,
xui_navigation_set_visible,
xui_navigation_set_visible,
xui_navigation_clear,
xui_navigation_set_visible,
xui_navigation_alphabet,
xui_navigation_alphabet,
2015-10-03 02:32:38 +00:00
generic_menu_init_list,
2016-01-12 08:23:17 +00:00
xui_list_insert,
xui_list_free,
xui_list_clear,
2014-12-23 20:25:02 +00:00
NULL,
2015-06-07 13:43:03 +00:00
NULL,
2015-06-08 14:01:57 +00:00
NULL,
NULL,
2015-06-15 17:00:52 +00:00
NULL,
2016-01-12 08:23:17 +00:00
xui_list_set_selection,
NULL,
2015-11-17 10:28:08 +00:00
NULL,
2016-01-12 08:23:17 +00:00
"xui",
xui_environ,
NULL,
2014-02-28 18:22:32 +00:00
};