mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-01 01:07:51 -04:00
update libRocket file interface
This commit is contained in:
parent
bf270fadc1
commit
d899d8e6ed
@ -31,86 +31,118 @@ RocketFileInterface(VirtualFileSystem *vfs) : _vfs(vfs) {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: RocketFileInterface::Open
|
// Function: RocketFileInterface::Open
|
||||||
// Access: Public
|
// Access: Public
|
||||||
// Description:
|
// Description:
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
Rocket::Core::FileHandle RocketFileInterface::
|
Rocket::Core::FileHandle RocketFileInterface::
|
||||||
Open(const Rocket::Core::String& path) {
|
Open(const Rocket::Core::String& path) {
|
||||||
rocket_cat.debug() << "Opening " << path.CString() << "\n";
|
rocket_cat.debug() << "Opening " << path.CString() << "\n";
|
||||||
|
|
||||||
Filename fn = Filename::from_os_specific(path.CString());
|
Filename fn = Filename::from_os_specific(path.CString());
|
||||||
void *ptr = (void*) _vfs->open_read_file(fn, true);
|
|
||||||
|
|
||||||
if (ptr == NULL) {
|
PT(VirtualFile) file = _vfs->get_file(fn);
|
||||||
rocket_cat.error() << "Failed to open " << fn << "\n";
|
if (file == NULL) {
|
||||||
|
rocket_cat.error() << "Failed to find " << fn << "\n";
|
||||||
|
return (Rocket::Core::FileHandle) NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// A FileHandle is actually just a void pointer
|
istream *str = file->open_read_file(true);
|
||||||
return (Rocket::Core::FileHandle) ptr;
|
if (str == NULL) {
|
||||||
|
rocket_cat.error() << "Failed to open " << fn << " for reading\n";
|
||||||
|
return (Rocket::Core::FileHandle) NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
VirtualFileHandle *handle = new VirtualFileHandle;
|
||||||
|
handle->_file = file;
|
||||||
|
handle->_stream = str;
|
||||||
|
|
||||||
|
// A FileHandle is actually just a void pointer.
|
||||||
|
return (Rocket::Core::FileHandle) handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: RocketFileInterface::Close
|
// Function: RocketFileInterface::Close
|
||||||
// Access: Public
|
// Access: Public
|
||||||
// Description:
|
// Description:
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void RocketFileInterface::
|
void RocketFileInterface::
|
||||||
Close(Rocket::Core::FileHandle file) {
|
Close(Rocket::Core::FileHandle file) {
|
||||||
if ((istream*) file != (istream*) NULL) {
|
VirtualFileHandle *handle = (VirtualFileHandle*) file;
|
||||||
_vfs->close_read_file((istream*) file);
|
if (handle == NULL) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_vfs->close_read_file(handle->_stream);
|
||||||
|
delete handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: RocketFileInterface::Read
|
// Function: RocketFileInterface::Read
|
||||||
// Access: Public
|
// Access: Public
|
||||||
// Description:
|
// Description:
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
size_t RocketFileInterface::
|
size_t RocketFileInterface::
|
||||||
Read(void* buffer, size_t size, Rocket::Core::FileHandle file) {
|
Read(void* buffer, size_t size, Rocket::Core::FileHandle file) {
|
||||||
istream* const stream = (istream*) file;
|
VirtualFileHandle *handle = (VirtualFileHandle*) file;
|
||||||
if (stream == (istream*) NULL) {
|
if (handle == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
stream->read((char*) buffer, size);
|
handle->_stream->read((char*) buffer, size);
|
||||||
return stream->gcount();
|
return handle->_stream->gcount();
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: RocketFileInterface::Seek
|
// Function: RocketFileInterface::Seek
|
||||||
// Access: Public
|
// Access: Public
|
||||||
// Description:
|
// Description:
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
bool RocketFileInterface::
|
bool RocketFileInterface::
|
||||||
Seek(Rocket::Core::FileHandle file, long offset, int origin) {
|
Seek(Rocket::Core::FileHandle file, long offset, int origin) {
|
||||||
istream* stream = (istream*) file;
|
VirtualFileHandle *handle = (VirtualFileHandle*) file;
|
||||||
if (stream == (istream*) NULL) {
|
if (handle == NULL) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(origin) {
|
switch(origin) {
|
||||||
case SEEK_SET:
|
case SEEK_SET:
|
||||||
stream->seekg(offset, ios::beg);
|
handle->_stream->seekg(offset, ios::beg);
|
||||||
break;
|
break;
|
||||||
case SEEK_CUR:
|
case SEEK_CUR:
|
||||||
stream->seekg(offset, ios::cur);
|
handle->_stream->seekg(offset, ios::cur);
|
||||||
break;
|
break;
|
||||||
case SEEK_END:
|
case SEEK_END:
|
||||||
stream->seekg(offset, ios::end);
|
handle->_stream->seekg(offset, ios::end);
|
||||||
};
|
};
|
||||||
|
|
||||||
return !stream->fail();
|
return !handle->_stream->fail();
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: RocketFileInterface::Tell
|
// Function: RocketFileInterface::Tell
|
||||||
// Access: Public
|
// Access: Public
|
||||||
// Description:
|
// Description:
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
size_t RocketFileInterface::
|
size_t RocketFileInterface::
|
||||||
Tell(Rocket::Core::FileHandle file) {
|
Tell(Rocket::Core::FileHandle file) {
|
||||||
if ((istream*) file == (istream*) NULL) {
|
VirtualFileHandle *handle = (VirtualFileHandle*) file;
|
||||||
return -1;
|
if (handle == NULL) {
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
return ((istream*) file)->tellg();
|
|
||||||
|
return handle->_stream->tellg();
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: RocketFileInterface::Length
|
||||||
|
// Access: Public
|
||||||
|
// Description:
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
size_t RocketFileInterface::
|
||||||
|
Length(Rocket::Core::FileHandle file) {
|
||||||
|
VirtualFileHandle *handle = (VirtualFileHandle*) file;
|
||||||
|
if (handle == NULL) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return handle->_file->get_file_size(handle->_stream);
|
||||||
}
|
}
|
||||||
|
@ -16,11 +16,16 @@
|
|||||||
#define ROCKET_FILE_INTERFACE_H
|
#define ROCKET_FILE_INTERFACE_H
|
||||||
|
|
||||||
#include "config_rocket.h"
|
#include "config_rocket.h"
|
||||||
|
#include "virtualFile.h"
|
||||||
#include <Rocket/Core/FileInterface.h>
|
#include <Rocket/Core/FileInterface.h>
|
||||||
|
|
||||||
class VirtualFileSystem;
|
class VirtualFileSystem;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Class : RocketFileInterface
|
||||||
|
// Description : Implementation of FileInterface to allow libRocket
|
||||||
|
// to read files from the virtual file system.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
class RocketFileInterface : public Rocket::Core::FileInterface {
|
class RocketFileInterface : public Rocket::Core::FileInterface {
|
||||||
public:
|
public:
|
||||||
RocketFileInterface(VirtualFileSystem *vfs = NULL);
|
RocketFileInterface(VirtualFileSystem *vfs = NULL);
|
||||||
@ -33,7 +38,14 @@ public:
|
|||||||
bool Seek(Rocket::Core::FileHandle file, long offset, int origin);
|
bool Seek(Rocket::Core::FileHandle file, long offset, int origin);
|
||||||
size_t Tell(Rocket::Core::FileHandle file);
|
size_t Tell(Rocket::Core::FileHandle file);
|
||||||
|
|
||||||
|
size_t Length(Rocket::Core::FileHandle file);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
struct VirtualFileHandle {
|
||||||
|
PT(VirtualFile) _file;
|
||||||
|
istream *_stream;
|
||||||
|
};
|
||||||
|
|
||||||
VirtualFileSystem* _vfs;
|
VirtualFileSystem* _vfs;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -156,7 +156,7 @@ RenderGeometry(Rocket::Core::Vertex* vertices, int num_vertices, int* indices, i
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: RocketRenderInterface::CompileGeometry
|
// Function: RocketRenderInterface::CompileGeometry
|
||||||
// Access: Protected
|
// Access: Protected
|
||||||
// Description: Called by Rocket when it wants to compile geometry
|
// Description: Called by Rocket when it wants to compile geometry
|
||||||
// it believes will be static for the forseeable future.
|
// it believes will be static for the forseeable future.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
|
@ -20,6 +20,12 @@
|
|||||||
#include <Rocket/Core/SystemInterface.h>
|
#include <Rocket/Core/SystemInterface.h>
|
||||||
#include <Rocket/Core/Log.h>
|
#include <Rocket/Core/Log.h>
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Class : RocketSystemInterface
|
||||||
|
// Description : This is an implementation of SystemInterface
|
||||||
|
// that redirects the log output to Panda's notify
|
||||||
|
// system.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
class RocketSystemInterface : public Rocket::Core::SystemInterface {
|
class RocketSystemInterface : public Rocket::Core::SystemInterface {
|
||||||
public:
|
public:
|
||||||
float GetElapsedTime();
|
float GetElapsedTime();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user