From 3c864d6a2a8c2bfc265c85953636b1313fd34c36 Mon Sep 17 00:00:00 2001 From: Zachary Pavlov Date: Thu, 16 Jul 2009 19:25:56 +0000 Subject: [PATCH] first stab at a group level margin override --- pandatool/src/palettizer/paletteGroup.cxx | 31 +++++++++++++++++++ pandatool/src/palettizer/paletteGroup.h | 6 ++++ pandatool/src/palettizer/texturePlacement.cxx | 6 +++- pandatool/src/palettizer/texturePlacement.h | 2 ++ pandatool/src/palettizer/txaFile.cxx | 13 ++++++++ 5 files changed, 57 insertions(+), 1 deletion(-) diff --git a/pandatool/src/palettizer/paletteGroup.cxx b/pandatool/src/palettizer/paletteGroup.cxx index 39653b9a26..870892a785 100644 --- a/pandatool/src/palettizer/paletteGroup.cxx +++ b/pandatool/src/palettizer/paletteGroup.cxx @@ -119,6 +119,37 @@ get_groups() const { return _dependent; } +//////////////////////////////////////////////////////////////////// +// Function: PaletteGroup::get_margin_override +// Access: Public +// Description: Returns the set of groups this group depends on. +//////////////////////////////////////////////////////////////////// +int PaletteGroup:: +get_margin_override() const { + return _margin_override; +} + +//////////////////////////////////////////////////////////////////// +// Function: PaletteGroup::get_margin_override +// Access: Public +// Description: Returns the set of groups this group depends on. +//////////////////////////////////////////////////////////////////// +void PaletteGroup:: +set_margin_override(const int override) { + _margin_override = override; + _has_margin_override = true; +} + +//////////////////////////////////////////////////////////////////// +// Function: PaletteGroup::has_margin_override +// Access: Public +// Description: Returns the set of groups this group depends on. +//////////////////////////////////////////////////////////////////// +bool PaletteGroup:: +has_margin_override() const { + return _has_margin_override; +} + //////////////////////////////////////////////////////////////////// // Function: PaletteGroup::get_placements // Access: Public diff --git a/pandatool/src/palettizer/paletteGroup.h b/pandatool/src/palettizer/paletteGroup.h index 313a2089ab..37e672bc5d 100644 --- a/pandatool/src/palettizer/paletteGroup.h +++ b/pandatool/src/palettizer/paletteGroup.h @@ -65,6 +65,10 @@ public: int get_dependency_order() const; int get_dirname_order() const; + void set_margin_override(const int override); + int get_margin_override() const; + bool has_margin_override() const; + bool is_preferred_over(const PaletteGroup &other) const; void increment_egg_count(); @@ -116,6 +120,8 @@ private: // don't use them otherwise. int _num_placements; int _num_pages; + bool _has_margin_override; + int _margin_override; pvector _load_pages; public: diff --git a/pandatool/src/palettizer/texturePlacement.cxx b/pandatool/src/palettizer/texturePlacement.cxx index a180358995..20feb92779 100644 --- a/pandatool/src/palettizer/texturePlacement.cxx +++ b/pandatool/src/palettizer/texturePlacement.cxx @@ -939,7 +939,11 @@ compute_size_from_uvs(const TexCoordd &min_uv, const TexCoordd &max_uv) { _position._x_size = max(_position._x_size, 4); _position._y_size = max(_position._y_size, 4); - _position._margin = _texture->get_margin(); + if(get_group()->has_margin_override()) { + _position._margin = get_group()->get_margin_override(); + } else { + _position._margin = _texture->get_margin(); + } //cout << "margin: " << _position._margin << endl; // Normally, we have interior margins, but if the image size is too diff --git a/pandatool/src/palettizer/texturePlacement.h b/pandatool/src/palettizer/texturePlacement.h index 6f90e78209..e3381644be 100644 --- a/pandatool/src/palettizer/texturePlacement.h +++ b/pandatool/src/palettizer/texturePlacement.h @@ -128,6 +128,8 @@ private: // don't use it otherwise. int _num_references; + int _margin_override; + public: static TypeHandle get_class_type() { return _type_handle; diff --git a/pandatool/src/palettizer/txaFile.cxx b/pandatool/src/palettizer/txaFile.cxx index 2c83c998f5..55c517fd65 100644 --- a/pandatool/src/palettizer/txaFile.cxx +++ b/pandatool/src/palettizer/txaFile.cxx @@ -228,6 +228,7 @@ parse_group_line(const vector_string &words) { S_on, S_includes, S_dir, + S_margin, }; State state = S_none; @@ -248,6 +249,9 @@ parse_group_line(const vector_string &words) { } else if (word == "dir") { state = S_dir; + } else if (word == "margin") { + state = S_margin; + } else { switch (state) { case S_none: @@ -275,7 +279,16 @@ parse_group_line(const vector_string &words) { group->set_dirname(word); state = S_none; break; + + case S_margin: + int margin_override; + if (!string_to_int(word, margin_override)) { + group->set_margin_override(margin_override); + } + state = S_none; + break; } + } ++wi;