Use std::tr1::array for AssStyle::Margin

This eliminates the need for an explicit operator= on AssStyle.
This commit is contained in:
Thomas Goyne 2012-10-26 07:29:52 -07:00
parent e0705f1c84
commit ce05857bfa
5 changed files with 12 additions and 64 deletions

View file

@ -50,11 +50,15 @@
#include "../libaegisub/lagi_pre.h"
/////////
// Setup
#define AGI_PRE
// General headers
#ifdef _WIN32
#include <array>
#else
#include <tr1/array>
#endif
#include <clocale>
#include <cstdlib>
#include <cctype>

View file

@ -78,7 +78,7 @@ class AssEntry {
public:
/// Group it belongs to, e.g. "[Events]"
const wxString group;
wxString group;
AssEntry(wxString const& data, wxString const& group) : data(data), group(group) { }
virtual ~AssEntry() { }

View file

@ -62,8 +62,6 @@ AssColor::AssColor(const wxColour &color)
SetWXColor(color);
}
/// @brief Parse from SSA/ASS
/// @param value
void AssColor::Parse(wxString const& value) {
if (value.size() > 0 && value[0] == '#') {
// HTML colour
@ -96,26 +94,16 @@ void AssColor::Parse(wxString const& value) {
a = (outval>>24) & 0xFF;
}
/// @brief Gets a wxColour
/// @return
wxColour AssColor::GetWXColor() const {
return wxColour(r,g,b,255-a);
}
/// @brief Sets color from wx
/// @param color
void AssColor::SetWXColor(const wxColor &color) {
r = color.Red();
g = color.Green();
b = color.Blue();
//a = color.Alpha();
}
/// @brief Get formatted in ASS format
/// @param alpha
/// @param stripped
/// @param isStyle
/// @return
wxString AssColor::GetAssFormatted(bool alpha,bool stripped,bool isStyle) const {
wxString work;
if (!stripped) work += "&H";
@ -125,8 +113,6 @@ wxString AssColor::GetAssFormatted(bool alpha,bool stripped,bool isStyle) const
return work;
}
/// @brief Get decimal formatted
/// @return
wxString AssColor::GetSSAFormatted() const {
long color = (a<<24)+(b<<16)+(g<<8)+r;
wxString output=wxString::Format("%li",(long)color);
@ -164,8 +150,7 @@ AssStyle::AssStyle()
, alignment(2)
, encoding(1)
{
for (int i = 0; i < 3; i++)
Margin[i] = 10;
std::fill(Margin.begin(), Margin.end(), 10);
UpdateData();
}
@ -269,38 +254,6 @@ AssStyle::AssStyle(wxString rawData, int version)
UpdateData();
}
AssStyle& AssStyle::operator=(AssStyle const& rgt) {
name = rgt.name;
font = rgt.font;
fontsize = rgt.fontsize;
primary = rgt.primary;
secondary = rgt.secondary;
outline = rgt.outline;
shadow = rgt.shadow;
bold = rgt.bold;
italic = rgt.italic;
underline = rgt.underline;
strikeout = rgt.strikeout;
scalex = rgt.scalex;
scaley = rgt.scaley;
spacing = rgt.spacing;
angle = rgt.angle;
borderstyle = rgt.borderstyle;
outline_w = rgt.outline_w;
shadow_w = rgt.shadow_w;
alignment = rgt.alignment;
encoding = rgt.encoding;
memcpy(Margin, rgt.Margin, sizeof(Margin));
SetEntryData(rgt.GetEntryData());
return *this;
}
void AssStyle::UpdateData() {
wxString final;

View file

@ -33,16 +33,13 @@
///
#ifndef AGI_PRE
#include <tr1/array>
#include <wx/colour.h>
#endif
#include "ass_entry.h"
/// DOCME
/// @class AssColor
/// @brief DOCME
///
/// DOCME
struct AssColor {
int r; ///< Red component
int g; ///< Green component
@ -63,11 +60,6 @@ struct AssColor {
wxString GetSSAFormatted() const;
};
/// DOCME
/// @class AssStyle
/// @brief DOCME
///
/// DOCME
class AssStyle : public AssEntry {
public:
wxString name; ///< Name of the style; must be case-insensitively unique within a file despite being case-sensitive
@ -92,7 +84,7 @@ public:
double outline_w; ///< Outline width in pixels
double shadow_w; ///< Shadow distance in pixels
int alignment; ///< \an-style line alignment
int Margin[3]; ///< Left/Right/Vertical
std::tr1::array<int, 3> Margin; ///< Left/Right/Vertical
int encoding; ///< ASS font encoding needed for some non-unicode fonts
/// Update the raw line data after one or more of the public members have been changed
@ -103,7 +95,6 @@ public:
AssStyle();
AssStyle(wxString data, int version=1);
AssStyle& operator=(AssStyle const&);
wxString GetSSAText() const;
AssEntryType GetType() const { return ENTRY_STYLE; }

View file

@ -79,7 +79,7 @@ void SubtitlesPreview::SetStyle(AssStyle const& newStyle) {
*style = newStyle;
style->name = "Default";
style->alignment = 5;
memset(style->Margin, 0, sizeof style->Margin);
std::fill(style->Margin.begin(), style->Margin.end(), 0);
style->UpdateData();
UpdateBitmap();
}