From 966fe28c59f59fc8be795c8215b9352435982445 Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 30 Sep 2021 16:46:36 +0200 Subject: Merged nGenEx and Parser into Stars45 --- nGenEx/Layout.cpp | 275 ------------------------------------------------------ 1 file changed, 275 deletions(-) delete mode 100644 nGenEx/Layout.cpp (limited to 'nGenEx/Layout.cpp') diff --git a/nGenEx/Layout.cpp b/nGenEx/Layout.cpp deleted file mode 100644 index 05c1eb2..0000000 --- a/nGenEx/Layout.cpp +++ /dev/null @@ -1,275 +0,0 @@ -/* Starshatter OpenSource Distribution - Copyright (c) 1997-2004, Destroyer Studios LLC. - All Rights Reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - * Neither the name "Destroyer Studios" nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. - - SUBSYSTEM: nGenEx.lib - FILE: Layout.cpp - AUTHOR: John DiCamillo - - - OVERVIEW - ======== - Layout Resource class implementation -*/ - -#include "MemDebug.h" -#include "Layout.h" - -// +--------------------------------------------------------------------+ - -Layout::Layout() -{ } - -Layout::~Layout() -{ } - -// +--------------------------------------------------------------------+ - -bool -Layout::DoLayout(ActiveWindow* panel) -{ - if (!panel || panel->GetChildren().size() < 1) - return false; - - if (cols.size() < 1 || rows.size() < 1) - return false; - - std::vector cell_x; - std::vector cell_y; - - ScaleWeights(); - CalcCells(panel->Width(), panel->Height(), cell_x, cell_y); - - ListIter iter = panel->GetChildren(); - while (++iter) { - ActiveWindow* w = iter.value(); - Rect c = w->GetCells(); - Rect r; - Rect rp = panel->GetRect(); - - if (c.x < 0) c.x = 0; - else if (c.x >= (int)cell_x.size()) c.x = cell_x.size() - 1; - if (c.y < 0) c.y = 0; - else if (c.y >= (int)cell_y.size()) c.y = cell_y.size() - 1; - if (c.x+c.w >= (int)cell_x.size()) c.w = cell_x.size() - c.x - 1; - if (c.y+c.h >= (int)cell_y.size()) c.h = cell_y.size() - c.y - 1; - - r.x = cell_x[c.x] + w->GetCellInsets().left; - r.y = cell_y[c.y] + w->GetCellInsets().top; - r.w = cell_x[c.x+c.w] - w->GetCellInsets().right - r.x; - r.h = cell_y[c.y+c.h] - w->GetCellInsets().bottom - r.y; - - r.x += panel->X(); - r.y += panel->Y(); - - if (w->GetFixedWidth() && w->GetFixedWidth() < r.w) - r.w = w->GetFixedWidth(); - - if (w->GetFixedHeight() && w->GetFixedHeight() < r.h) - r.h = w->GetFixedHeight(); - - if (w->GetID() == 330 || w->GetID() == 125) { - int y1 = r.y + r.h; - int y2 = rp.y + rp.h; - } - - if (w->GetHidePartial() && (r.x + r.w > rp.x + rp.w)) { - w->MoveTo(Rect(0,0,0,0)); - } - - else if (w->GetHidePartial() && (r.y + r.h > rp.y + rp.h)) { - w->MoveTo(Rect(0,0,0,0)); - } - - else { - w->MoveTo(r); - } - } - - return true; -} - -// +--------------------------------------------------------------------+ - -void -Layout::ScaleWeights() -{ - float total = 0; - - for (auto cwi = col_weights.begin(); cwi != col_weights.end(); ++cwi) - total += *cwi; - - if (total > 0) { - for (auto cwi = col_weights.begin(); cwi != col_weights.end(); ++cwi) - *cwi = *cwi / total; - } - - total = 0; - for (auto rwi = row_weights.begin(); rwi != row_weights.end(); ++rwi) - total += *rwi; - - if (total > 0) { - for (auto rwi = row_weights.begin(); rwi != row_weights.end(); ++rwi) - *rwi = *rwi / total; - } -} - -// +--------------------------------------------------------------------+ - -void - Layout::CalcCells(DWORD w, DWORD h, std::vector& cell_x, std::vector& cell_y) -{ - DWORD x = 0; - DWORD y = 0; - DWORD min_x = 0; - DWORD min_y = 0; - DWORD ext_x = 0; - DWORD ext_y = 0; - - for (auto cit = cols.begin(); cit != cols.end(); ++cit) - min_x += *cit; - - for (auto rit = rows.begin(); rit != rows.end(); ++rit) - min_y += *rit; - - if (min_x < w) - ext_x = w - min_x; - - if (min_y < h) - ext_y = h - min_y; - - cell_x.push_back(x); - for (auto cit = cols.begin(); cit != cols.end(); ++cit) { - x += *cit + (DWORD) (ext_x * col_weights[cit - cols.begin()]); - cell_x.push_back(x); - } - - cell_y.push_back(y); - for (auto rit = rows.begin(); rit != rows.end(); ++rit) { - y += *rit + (DWORD) (ext_y * row_weights[rit - rows.begin()]); - cell_y.push_back(y); - } -} - -// +--------------------------------------------------------------------+ - -void -Layout::Clear() -{ - cols.clear(); - rows.clear(); - - col_weights.clear(); - row_weights.clear(); -} - -void -Layout::AddCol(DWORD min_width, float col_factor) -{ - cols.push_back(min_width); - col_weights.push_back(col_factor); -} - -void -Layout::AddRow(DWORD min_height, float row_factor) -{ - rows.push_back(min_height); - row_weights.push_back(row_factor); -} - -void -Layout::SetConstraints(const std::vector& min_x, -const std::vector& min_y, -const std::vector& weight_x, -const std::vector& weight_y) -{ - Clear(); - - if (min_x.size() == weight_x.size() && min_y.size() == weight_y.size()) { - for (auto iter = min_x.begin(); iter != min_x.end(); ++iter) - cols.push_back(*iter); - - for (auto iter = min_y.begin(); iter != min_y.end(); ++iter) - rows.push_back(*iter); - - for (auto iter = weight_x.begin(); iter != weight_x.end(); ++iter) - col_weights.push_back(*iter); - - for (auto iter = weight_y.begin(); iter != weight_y.end(); ++iter) - row_weights.push_back(*iter); - } -} - -void -Layout::SetConstraints(const std::vector& min_x, -const std::vector& min_y, -const std::vector& weight_x, -const std::vector& weight_y) -{ - Clear(); - - if (min_x.size() == weight_x.size() && - min_y.size() == weight_y.size()) { - - for (auto iter = min_x.begin(); iter != min_x.end(); ++iter) - cols.push_back((DWORD) *iter); - - for (auto iter = min_y.begin(); iter != min_y.end(); ++iter) - rows.push_back((DWORD) *iter); - - for (auto iter = weight_x.begin(); iter != weight_x.end(); ++iter) - col_weights.push_back(*iter); - - for (auto iter = weight_y.begin(); iter != weight_y.end(); ++iter) - row_weights.push_back(*iter); - } -} - -void -Layout::SetConstraints(int ncols, -int nrows, -const int* min_x, -const int* min_y, -const float* weight_x, -const float* weight_y) -{ - Clear(); - - if (nrows > 0 && ncols > 0) { - int i = 0; - - for (i = 0; i < ncols; i++) { - cols.push_back(min_x[i]); - col_weights.push_back(weight_x[i]); - } - - for (i = 0; i < nrows; i++) { - rows.push_back(min_y[i]); - row_weights.push_back(weight_y[i]); - } - } -} -- cgit v1.1