mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-30 16:58:40 -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
|
||||
// Access: Public
|
||||
// Description:
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
Rocket::Core::FileHandle RocketFileInterface::
|
||||
Open(const Rocket::Core::String& path) {
|
||||
rocket_cat.debug() << "Opening " << path.CString() << "\n";
|
||||
|
||||
Filename fn = Filename::from_os_specific(path.CString());
|
||||
void *ptr = (void*) _vfs->open_read_file(fn, true);
|
||||
|
||||
if (ptr == NULL) {
|
||||
rocket_cat.error() << "Failed to open " << fn << "\n";
|
||||
PT(VirtualFile) file = _vfs->get_file(fn);
|
||||
if (file == NULL) {
|
||||
rocket_cat.error() << "Failed to find " << fn << "\n";
|
||||
return (Rocket::Core::FileHandle) NULL;
|
||||
}
|
||||
|
||||
// A FileHandle is actually just a void pointer
|
||||
return (Rocket::Core::FileHandle) ptr;
|
||||
istream *str = file->open_read_file(true);
|
||||
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
|
||||
// Access: Public
|
||||
// Description:
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void RocketFileInterface::
|
||||
Close(Rocket::Core::FileHandle file) {
|
||||
if ((istream*) file != (istream*) NULL) {
|
||||
_vfs->close_read_file((istream*) file);
|
||||
VirtualFileHandle *handle = (VirtualFileHandle*) file;
|
||||
if (handle == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
_vfs->close_read_file(handle->_stream);
|
||||
delete handle;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: RocketFileInterface::Read
|
||||
// Access: Public
|
||||
// Description:
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
size_t RocketFileInterface::
|
||||
Read(void* buffer, size_t size, Rocket::Core::FileHandle file) {
|
||||
istream* const stream = (istream*) file;
|
||||
if (stream == (istream*) NULL) {
|
||||
VirtualFileHandle *handle = (VirtualFileHandle*) file;
|
||||
if (handle == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
stream->read((char*) buffer, size);
|
||||
return stream->gcount();
|
||||
handle->_stream->read((char*) buffer, size);
|
||||
return handle->_stream->gcount();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: RocketFileInterface::Seek
|
||||
// Access: Public
|
||||
// Description:
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool RocketFileInterface::
|
||||
Seek(Rocket::Core::FileHandle file, long offset, int origin) {
|
||||
istream* stream = (istream*) file;
|
||||
if (stream == (istream*) NULL) {
|
||||
VirtualFileHandle *handle = (VirtualFileHandle*) file;
|
||||
if (handle == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch(origin) {
|
||||
case SEEK_SET:
|
||||
stream->seekg(offset, ios::beg);
|
||||
handle->_stream->seekg(offset, ios::beg);
|
||||
break;
|
||||
case SEEK_CUR:
|
||||
stream->seekg(offset, ios::cur);
|
||||
handle->_stream->seekg(offset, ios::cur);
|
||||
break;
|
||||
case SEEK_END:
|
||||
stream->seekg(offset, ios::end);
|
||||
handle->_stream->seekg(offset, ios::end);
|
||||
};
|
||||
|
||||
return !stream->fail();
|
||||
return !handle->_stream->fail();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: RocketFileInterface::Tell
|
||||
// Access: Public
|
||||
// Description:
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
size_t RocketFileInterface::
|
||||
Tell(Rocket::Core::FileHandle file) {
|
||||
if ((istream*) file == (istream*) NULL) {
|
||||
return -1;
|
||||
VirtualFileHandle *handle = (VirtualFileHandle*) file;
|
||||
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
|
||||
|
||||
#include "config_rocket.h"
|
||||
|
||||
#include "virtualFile.h"
|
||||
#include <Rocket/Core/FileInterface.h>
|
||||
|
||||
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 {
|
||||
public:
|
||||
RocketFileInterface(VirtualFileSystem *vfs = NULL);
|
||||
@ -33,7 +38,14 @@ public:
|
||||
bool Seek(Rocket::Core::FileHandle file, long offset, int origin);
|
||||
size_t Tell(Rocket::Core::FileHandle file);
|
||||
|
||||
size_t Length(Rocket::Core::FileHandle file);
|
||||
|
||||
protected:
|
||||
struct VirtualFileHandle {
|
||||
PT(VirtualFile) _file;
|
||||
istream *_stream;
|
||||
};
|
||||
|
||||
VirtualFileSystem* _vfs;
|
||||
};
|
||||
|
||||
|
@ -156,7 +156,7 @@ RenderGeometry(Rocket::Core::Vertex* vertices, int num_vertices, int* indices, i
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: RocketRenderInterface::CompileGeometry
|
||||
// Access: Protected
|
||||
// Access: Protected
|
||||
// Description: Called by Rocket when it wants to compile geometry
|
||||
// it believes will be static for the forseeable future.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
@ -20,6 +20,12 @@
|
||||
#include <Rocket/Core/SystemInterface.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 {
|
||||
public:
|
||||
float GetElapsedTime();
|
||||
|
Loading…
x
Reference in New Issue
Block a user