mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-30 16:58:40 -04:00
support p3d specifying preferred window size to desktop app
This commit is contained in:
parent
2af9dcb6eb
commit
d3dc3621ac
@ -112,8 +112,10 @@ run_embedded(streampos read_offset, int argc, char *argv[]) {
|
|||||||
// Read out the tokens that may interest us
|
// Read out the tokens that may interest us
|
||||||
if (keyword == "width") {
|
if (keyword == "width") {
|
||||||
_win_width = atoi(value.c_str());
|
_win_width = atoi(value.c_str());
|
||||||
|
_got_win_size = true;
|
||||||
} else if (keyword == "height") {
|
} else if (keyword == "height") {
|
||||||
_win_height = atoi(value.c_str());
|
_win_height = atoi(value.c_str());
|
||||||
|
_got_win_size = true;
|
||||||
} else if (keyword == "log_basename") {
|
} else if (keyword == "log_basename") {
|
||||||
_log_basename = value;
|
_log_basename = value;
|
||||||
} else if (keyword == "root_dir") {
|
} else if (keyword == "root_dir") {
|
||||||
@ -233,9 +235,7 @@ run_embedded(streampos read_offset, int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create a plugin instance and run the program
|
// Create a plugin instance and run the program
|
||||||
P3D_instance *inst = create_instance
|
P3D_instance *inst = create_instance(f, true, argv, argc, read_offset);
|
||||||
(f, true, _win_x, _win_y, _win_width, _win_height,
|
|
||||||
argv, argc, read_offset);
|
|
||||||
_instances.insert(inst);
|
_instances.insert(inst);
|
||||||
|
|
||||||
run_main_loop();
|
run_main_loop();
|
||||||
|
@ -120,6 +120,7 @@ run_command_line(int argc, char *argv[]) {
|
|||||||
cerr << "Invalid value for -s: " << optarg << "\n";
|
cerr << "Invalid value for -s: " << optarg << "\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
_got_win_size = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'o':
|
case 'o':
|
||||||
@ -248,8 +249,11 @@ run_command_line(int argc, char *argv[]) {
|
|||||||
int num_y_spans = int(sqrt((double)num_instance_filenames));
|
int num_y_spans = int(sqrt((double)num_instance_filenames));
|
||||||
int num_x_spans = (num_instance_filenames + num_y_spans - 1) / num_y_spans;
|
int num_x_spans = (num_instance_filenames + num_y_spans - 1) / num_y_spans;
|
||||||
|
|
||||||
int inst_width = _win_width / num_x_spans;
|
int origin_x = _win_x;
|
||||||
int inst_height = _win_height / num_y_spans;
|
int origin_y = _win_y;
|
||||||
|
_win_width = _win_width / num_x_spans;
|
||||||
|
_win_height = _win_height / num_y_spans;
|
||||||
|
_got_win_size = true;
|
||||||
|
|
||||||
for (int yi = 0; yi < num_y_spans; ++yi) {
|
for (int yi = 0; yi < num_y_spans; ++yi) {
|
||||||
for (int xi = 0; xi < num_x_spans; ++xi) {
|
for (int xi = 0; xi < num_x_spans; ++xi) {
|
||||||
@ -259,12 +263,11 @@ run_command_line(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create instance i at window slot (xi, yi).
|
// Create instance i at window slot (xi, yi).
|
||||||
int inst_x = _win_x + xi * inst_width;
|
_win_x = origin_x + xi * _win_width;
|
||||||
int inst_y = _win_y + yi * inst_height;
|
_win_y = origin_y + yi * _win_height;
|
||||||
|
|
||||||
P3D_instance *inst = create_instance
|
P3D_instance *inst = create_instance
|
||||||
(instance_filenames[i], true,
|
(instance_filenames[i], true,
|
||||||
inst_x, inst_y, inst_width, inst_height,
|
|
||||||
instance_args, num_instance_args);
|
instance_args, num_instance_args);
|
||||||
_instances.insert(inst);
|
_instances.insert(inst);
|
||||||
}
|
}
|
||||||
@ -275,7 +278,6 @@ run_command_line(int argc, char *argv[]) {
|
|||||||
for (int i = 0; i < num_instance_filenames; ++i) {
|
for (int i = 0; i < num_instance_filenames; ++i) {
|
||||||
P3D_instance *inst = create_instance
|
P3D_instance *inst = create_instance
|
||||||
(instance_filenames[i], true,
|
(instance_filenames[i], true,
|
||||||
_win_x, _win_y, _win_width, _win_height,
|
|
||||||
instance_args, num_instance_args);
|
instance_args, num_instance_args);
|
||||||
_instances.insert(inst);
|
_instances.insert(inst);
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,8 @@
|
|||||||
#include "find_root_dir.h"
|
#include "find_root_dir.h"
|
||||||
#include "load_plugin.h"
|
#include "load_plugin.h"
|
||||||
#include "executionEnvironment.h"
|
#include "executionEnvironment.h"
|
||||||
|
#include "multifile.h"
|
||||||
|
#include "tinyxml.h"
|
||||||
|
|
||||||
// We can include this header file to get the DTOOL_PLATFORM
|
// We can include this header file to get the DTOOL_PLATFORM
|
||||||
// definition, even though we don't link with dtool.
|
// definition, even though we don't link with dtool.
|
||||||
@ -62,6 +64,7 @@ Panda3DBase(bool console_environment) {
|
|||||||
_win_y = -1;
|
_win_y = -1;
|
||||||
_win_width = 640;
|
_win_width = 640;
|
||||||
_win_height = 480;
|
_win_height = 480;
|
||||||
|
_got_win_size = false;
|
||||||
|
|
||||||
_exit_with_last_instance = true;
|
_exit_with_last_instance = true;
|
||||||
_host_url = PANDA_PACKAGE_HOST_URL;
|
_host_url = PANDA_PACKAGE_HOST_URL;
|
||||||
@ -330,7 +333,6 @@ make_parent_window() {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
P3D_instance *Panda3DBase::
|
P3D_instance *Panda3DBase::
|
||||||
create_instance(const string &p3d, bool start_instance,
|
create_instance(const string &p3d, bool start_instance,
|
||||||
int win_x, int win_y, int win_width, int win_height,
|
|
||||||
char **args, int num_args, const int &p3d_offset) {
|
char **args, int num_args, const int &p3d_offset) {
|
||||||
// Check to see if the p3d filename we were given is a URL, or a
|
// Check to see if the p3d filename we were given is a URL, or a
|
||||||
// local file.
|
// local file.
|
||||||
@ -346,6 +348,9 @@ create_instance(const string &p3d, bool start_instance,
|
|||||||
p3d_filename.make_absolute();
|
p3d_filename.make_absolute();
|
||||||
os_p3d_filename = p3d_filename.to_os_specific();
|
os_p3d_filename = p3d_filename.to_os_specific();
|
||||||
}
|
}
|
||||||
|
if (is_local) {
|
||||||
|
read_p3d_info(p3d_filename);
|
||||||
|
}
|
||||||
|
|
||||||
// Build up the token list.
|
// Build up the token list.
|
||||||
Tokens tokens = _tokens;
|
Tokens tokens = _tokens;
|
||||||
@ -373,7 +378,7 @@ create_instance(const string &p3d, bool start_instance,
|
|||||||
token._value = "1";
|
token._value = "1";
|
||||||
tokens.push_back(token);
|
tokens.push_back(token);
|
||||||
|
|
||||||
P3D_token *tokens_p;
|
P3D_token *tokens_p = NULL;
|
||||||
size_t num_tokens = tokens.size();
|
size_t num_tokens = tokens.size();
|
||||||
if (!tokens.empty()) {
|
if (!tokens.empty()) {
|
||||||
tokens_p = &tokens[0];
|
tokens_p = &tokens[0];
|
||||||
@ -400,7 +405,7 @@ create_instance(const string &p3d, bool start_instance,
|
|||||||
}
|
}
|
||||||
|
|
||||||
P3D_instance_setup_window_ptr
|
P3D_instance_setup_window_ptr
|
||||||
(inst, _window_type, win_x, win_y, win_width, win_height, &_parent_window);
|
(inst, _window_type, _win_x, _win_y, _win_width, _win_height, &_parent_window);
|
||||||
}
|
}
|
||||||
|
|
||||||
return inst;
|
return inst;
|
||||||
@ -432,6 +437,56 @@ delete_instance(P3D_instance *inst) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: Panda3DBase::read_p3d_info
|
||||||
|
// Access: Protected
|
||||||
|
// Description: Opens the p3d file to read the p3d_info.xml file
|
||||||
|
// within it, looking for any locally-relevant
|
||||||
|
// parameters (like win-size).
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
bool Panda3DBase::
|
||||||
|
read_p3d_info(const Filename &p3d_filename) {
|
||||||
|
PT(Multifile) mf = new Multifile;
|
||||||
|
if (!mf->open_read(p3d_filename)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
int si = mf->find_subfile("p3d_info.xml");
|
||||||
|
if (si == -1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
string p3d_info;
|
||||||
|
mf->read_subfile(si, p3d_info);
|
||||||
|
istringstream strm(p3d_info);
|
||||||
|
TiXmlDocument doc;
|
||||||
|
strm >> doc;
|
||||||
|
if (strm.fail() && !strm.eof()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
TiXmlElement *xpackage = doc.FirstChildElement("package");
|
||||||
|
if (xpackage == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
TiXmlElement *xconfig = xpackage->FirstChildElement("config");
|
||||||
|
if (xconfig == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Successfully read the p3d_info.xml file.
|
||||||
|
if (!_got_win_size) {
|
||||||
|
// If the user didn't override the size on the command line, allow
|
||||||
|
// the p3d file to request a preferred size.
|
||||||
|
if (xconfig->Attribute("width", &_win_width)) {
|
||||||
|
_got_win_size = true;
|
||||||
|
}
|
||||||
|
if (xconfig->Attribute("height", &_win_height)) {
|
||||||
|
_got_win_size = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: Panda3DBase::parse_token
|
// Function: Panda3DBase::parse_token
|
||||||
// Access: Protected
|
// Access: Protected
|
||||||
|
@ -49,10 +49,10 @@ protected:
|
|||||||
|
|
||||||
P3D_instance *
|
P3D_instance *
|
||||||
create_instance(const string &p3d, bool start_instance,
|
create_instance(const string &p3d, bool start_instance,
|
||||||
int win_x, int win_y, int win_width, int win_height,
|
|
||||||
char **args, int num_args, const int &p3d_offset = 0);
|
char **args, int num_args, const int &p3d_offset = 0);
|
||||||
void delete_instance(P3D_instance *instance);
|
void delete_instance(P3D_instance *instance);
|
||||||
|
|
||||||
|
bool read_p3d_info(const Filename &p3d_filename);
|
||||||
bool parse_token(const char *arg);
|
bool parse_token(const char *arg);
|
||||||
bool parse_int_pair(const char *arg, int &x, int &y);
|
bool parse_int_pair(const char *arg, int &x, int &y);
|
||||||
string lookup_token(const string &keyword) const;
|
string lookup_token(const string &keyword) const;
|
||||||
@ -84,6 +84,7 @@ protected:
|
|||||||
P3D_window_handle _parent_window;
|
P3D_window_handle _parent_window;
|
||||||
int _win_x, _win_y;
|
int _win_x, _win_y;
|
||||||
int _win_width, _win_height;
|
int _win_width, _win_height;
|
||||||
|
bool _got_win_size;
|
||||||
bool _exit_with_last_instance;
|
bool _exit_with_last_instance;
|
||||||
|
|
||||||
bool _reporting_download;
|
bool _reporting_download;
|
||||||
|
@ -58,10 +58,7 @@ open_p3d_file(FSRef *ref) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create an instance.
|
// Create an instance.
|
||||||
P3D_instance *inst = create_instance
|
create_instance((char *)filename, true, NULL, 0);
|
||||||
((char *)filename, true,
|
|
||||||
_win_x, _win_y, _win_width, _win_height,
|
|
||||||
NULL, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static pascal OSErr
|
static pascal OSErr
|
||||||
|
Loading…
x
Reference in New Issue
Block a user