<commit_before>#include "Scale9.h"
#include "S2_Sprite.h"
#include "S2_Symbol.h"
#include "DrawNode.h"
#include "ImageSymbol.h"
#include "Texture.h"

#include <SM_Calc.h>

#include <string.h>
#include <assert.h>

namespace s2
{

Scale9::Scale9()
	: m_type(S9_NULL)
	, m_width(0)
	, m_height(0)
{
	memset(m_grids, 0, sizeof(m_grids));
}

Scale9::Scale9(const Scale9& s9)
{
	this->operator = (s9);
}

Scale9& Scale9::operator = (const Scale9& s9)
{
	m_type = s9.m_type;
	m_width = s9.m_width;
	m_height = s9.m_height;
	for (int i = 0; i < 9; ++i) {
		Sprite* spr = s9.m_grids[i];
		if (spr) {
			m_grids[i] = VI_CLONE(Sprite, spr);
		} else {
			m_grids[i] = NULL;
		}
	}
	return *this;
}

Scale9::~Scale9()
{
	for (int i = 0; i < 9; ++i) {
		if (m_grids[i]) {
			m_grids[i]->RemoveReference();
		}
	}
}

void Scale9::Draw(const RenderParams& params) const
{
	for (int i = 0; i < 9; ++i) {
		if (m_grids[i]) {
			DrawNode::Draw(m_grids[i], params);
		}
	}
}

void Scale9::SetSize(float width, float height)
{
	if (m_width == width && m_height == height) {
		return;
	}

	m_width = width;
	m_height = height;

	switch (m_type)
	{
	case S9_9GRID:
		{
			float w0 = m_grids[S9_DOWN_LEFT]->GetSymbol()->GetBounding().Size().x,
				  w2 = m_grids[S9_DOWN_RIGHT]->GetSymbol()->GetBounding().Size().x,
				  w1 = width - w0 - w2;
			float h0 = m_grids[S9_DOWN_LEFT]->GetSymbol()->GetBounding().Size().y,
				  h2 = m_grids[S9_DOWN_RIGHT]->GetSymbol()->GetBounding().Size().y,
				  h1 = height - h0 - h2;

			ResizeSprite(m_grids[S9_DOWN_LEFT], sm::vec2(-w0*0.5f-w1*0.5f, -h0*0.5f-h1*0.5f), w0, h0);
			ResizeSprite(m_grids[S9_DOWN_CENTER], sm::vec2(0.0f, -h0*0.5f-h1*0.5f), w1, h0);
			ResizeSprite(m_grids[S9_DOWN_RIGHT], sm::vec2(w1*0.5f+w2*0.5f, -h0*0.5f-h1*0.5f), w2, h0);

			ResizeSprite(m_grids[S9_MID_LEFT], sm::vec2(-w0*0.5f-w1*0.5f, 0.0f), w0, h1);
			ResizeSprite(m_grids[S9_MID_CENTER], sm::vec2(0.0f, 0.0f), w1, h1);
			ResizeSprite(m_grids[S9_MID_RIGHT], sm::vec2(w1*0.5f+w2*0.5f, 0.0f), w2, h1);

			ResizeSprite(m_grids[S9_TOP_LEFT], sm::vec2(-w0*0.5f-w1*0.5f, h1*0.5f+h2*0.5f), w0, h2);
			ResizeSprite(m_grids[S9_TOP_CENTER], sm::vec2(0.0f, h1*0.5f+h2*0.5f), w1, h2);
			ResizeSprite(m_grids[S9_TOP_RIGHT], sm::vec2(w1*0.5f+w2*0.5f, h1*0.5f+h2*0.5f), w2, h2);		
		}
		break;
	case S9_9GRID_HOLLOW:
		{
			float w0 = m_grids[S9_DOWN_LEFT]->GetSymbol()->GetBounding().Size().x,
				  w2 = m_grids[S9_DOWN_RIGHT]->GetSymbol()->GetBounding().Size().x,
				  w1 = width - w0 - w2;
			float h0 = m_grids[S9_DOWN_LEFT]->GetSymbol()->GetBounding().Size().y,
				  h2 = m_grids[S9_DOWN_RIGHT]->GetSymbol()->GetBounding().Size().y,
				  h1 = height - h0 - h2;

			ResizeSprite(m_grids[S9_DOWN_LEFT], sm::vec2(-w0*0.5f-w1*0.5f, -h0*0.5f-h1*0.5f), w0, h0);
			ResizeSprite(m_grids[S9_DOWN_CENTER], sm::vec2(0.0f, -h0*0.5f-h1*0.5f), w1, h0);
			ResizeSprite(m_grids[S9_DOWN_RIGHT], sm::vec2(w1*0.5f+w2*0.5f, -h0*0.5f-h1*0.5f), w2, h0);

			ResizeSprite(m_grids[S9_MID_LEFT], sm::vec2(-w0*0.5f-w1*0.5f, 0.0f), w0, h1);
			ResizeSprite(m_grids[S9_MID_RIGHT], sm::vec2(w1*0.5f+w2*0.5f, 0.0f), w2, h1);

			ResizeSprite(m_grids[S9_TOP_LEFT], sm::vec2(-w0*0.5f-w1*0.5f, h1*0.5f+h2*0.5f), w0, h2);
			ResizeSprite(m_grids[S9_TOP_CENTER], sm::vec2(0.0f, h1*0.5f+h2*0.5f), w1, h2);<commit_msg>[FXIED] scale9 layout<commit_after>#include "Scale9.h"
#include "S2_Sprite.h"
#include "S2_Symbol.h"
#include "DrawNode.h"
#include "ImageSymbol.h"
#include "Texture.h"

#include <SM_Calc.h>

#include <string.h>
#include <assert.h>

namespace s2
{

Scale9::Scale9()
	: m_type(S9_NULL)
	, m_width(0)
	, m_height(0)
{
	memset(m_grids, 0, sizeof(m_grids));
}

Scale9::Scale9(const Scale9& s9)
{
	this->operator = (s9);
}

Scale9& Scale9::operator = (const Scale9& s9)
{
	m_type = s9.m_type;
	m_width = s9.m_width;
	m_height = s9.m_height;
	for (int i = 0; i < 9; ++i) {
		Sprite* spr = s9.m_grids[i];
		if (spr) {
			m_grids[i] = VI_CLONE(Sprite, spr);
		} else {
			m_grids[i] = NULL;
		}
	}
	return *this;
}

Scale9::~Scale9()
{
	for (int i = 0; i < 9; ++i) {
		if (m_grids[i]) {
			m_grids[i]->RemoveReference();
		}
	}
}

void Scale9::Draw(const RenderParams& params) const
{
	for (int i = 0; i < 9; ++i) {
		if (m_grids[i]) {
			DrawNode::Draw(m_grids[i], params);
		}
	}
}

void Scale9::SetSize(float width, float height)
{
	if (m_width == width && m_height == height) {
		return;
	}

	m_width = width;
	m_height = height;

	switch (m_type)
	{
	case S9_9GRID:
		{
			float w0 = m_grids[S9_DOWN_LEFT]->GetSymbol()->GetBounding().Size().x,
				  w2 = m_grids[S9_DOWN_RIGHT]->GetSymbol()->GetBounding().Size().x,
				  w1 = width - w0 - w2;
			float h0 = m_grids[S9_DOWN_LEFT]->GetSymbol()->GetBounding().Size().y,
				  h2 = m_grids[S9_TOP_LEFT]->GetSymbol()->GetBounding().Size().y,
				  h1 = height - h0 - h2;

			ResizeSprite(m_grids[S9_DOWN_LEFT], sm::vec2(-w0*0.5f-w1*0.5f, -h0*0.5f-h1*0.5f), w0, h0);
			ResizeSprite(m_grids[S9_DOWN_CENTER], sm::vec2(0.0f, -h0*0.5f-h1*0.5f), w1, h0);
			ResizeSprite(m_grids[S9_DOWN_RIGHT], sm::vec2(w1*0.5f+w2*0.5f, -h0*0.5f-h1*0.5f), w2, h0);

			ResizeSprite(m_grids[S9_MID_LEFT], sm::vec2(-w0*0.5f-w1*0.5f, 0.0f), w0, h1);
			ResizeSprite(m_grids[S9_MID_CENTER], sm::vec2(0.0f, 0.0f), w1, h1);
			ResizeSprite(m_grids[S9_MID_RIGHT], sm::vec2(w1*0.5f+w2*0.5f, 0.0f), w2, h1);

			ResizeSprite(m_grids[S9_TOP_LEFT], sm::vec2(-w0*0.5f-w1*0.5f, h1*0.5f+h2*0.5f), w0, h2);
			ResizeSprite(m_grids[S9_TOP_CENTER], sm::vec2(0.0f, h1*0.5f+h2*0.5f), w1, h2);
			ResizeSprite(m_grids[S9_TOP_RIGHT], sm::vec2(w1*0.5f+w2*0.5f, h1*0.5f+h2*0.5f), w2, h2);		
		}
		break;
	case S9_9GRID_HOLLOW:
		{
			float w0 = m_grids[S9_DOWN_LEFT]->GetSymbol()->GetBounding().Size().x,
				  w2 = m_grids[S9_DOWN_RIGHT]->GetSymbol()->GetBounding().Size().x,
				  w1 = width - w0 - w2;
			float h0 = m_grids[S9_DOWN_LEFT]->GetSymbol()->GetBounding().Size().y,
				  h2 = m_grids[S9_TOP_LEFT]->GetSymbol()->GetBounding().Size().y,
				  h1 = height - h0 - h2;

			ResizeSprite(m_grids[S9_DOWN_LEFT], sm::vec2(-w0*0.5f-w1*0.5f, -h0*0.5f-h1*0.5f), w0, h0);
			ResizeSprite(m_grids[S9_DOWN_CENTER], sm::vec2(0.0f, -h0*0.5f-h1*0.5f), w1, h0);
			ResizeSprite(m_grids[S9_DOWN_RIGHT], sm::vec2(w1*0.5f+w2*0.5f, -h0*0.5f-h1*0.5f), w2, h0);

			ResizeSprite(m_grids[S9_MID_LEFT], sm::vec2(-w0*0.5f-w1*0.5f, 0.0f), w0, h1);
			ResizeSprite(m_grids[S9_MID_RIGHT], sm::vec2(w1*0.5f+w2*0.5f, 0.0f), w2, h1);

			ResizeSprite(m_grids[S9_TOP_LEFT], sm::vec2(-w0*0.5f-w1*0.5f, h1*0.5f+h2*0.5f), w0, h2);
			ResizeSprite(m_grids[S9_TOP_CENTER], sm::vec2(0.0f, h1*0.5f+h2*0.5f), w1, h2);
{'fraction_non_alphanumeric': 0.2143074581430746, 'fraction_numerical': 0.08569254185692542, 'mean_word_length': 4.269446672012831, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1666142', 'n_tokens_mistral': 3684, 'n_tokens_neox': 3517, 'n_words': 457}