parent
690e7ba9a3
commit
e19d17385e
14 changed files with 240 additions and 124 deletions
@ -0,0 +1,115 @@ |
||||
#include "LineStyle.h" |
||||
|
||||
#include <serializing/ObjectOutputStream.h> |
||||
#include <serializing/ObjectInputStream.h> |
||||
|
||||
|
||||
LineStyle::LineStyle() |
||||
{ |
||||
XOJ_INIT_TYPE(LineStyle); |
||||
} |
||||
|
||||
LineStyle::LineStyle(const LineStyle& other) |
||||
{ |
||||
XOJ_INIT_TYPE(LineStyle); |
||||
*this = other; |
||||
} |
||||
|
||||
LineStyle::~LineStyle() |
||||
{ |
||||
XOJ_CHECK_TYPE(LineStyle); |
||||
|
||||
g_free(this->dashes); |
||||
this->dashes = NULL; |
||||
this->dashCount = 0; |
||||
|
||||
XOJ_RELEASE_TYPE(LineStyle); |
||||
} |
||||
|
||||
void LineStyle::operator=(const LineStyle& other) |
||||
{ |
||||
XOJ_CHECK_TYPE(LineStyle); |
||||
|
||||
const double* dashes = NULL; |
||||
int dashCount = 0; |
||||
|
||||
other.getDashes(dashes, dashCount); |
||||
setDashes(dashes, dashCount); |
||||
} |
||||
|
||||
|
||||
void LineStyle::serialize(ObjectOutputStream& out) |
||||
{ |
||||
XOJ_CHECK_TYPE(LineStyle); |
||||
|
||||
out.writeObject("LineStyle"); |
||||
|
||||
out.writeData(this->dashes, this->dashCount, sizeof(double)); |
||||
|
||||
out.endObject(); |
||||
} |
||||
|
||||
void LineStyle::readSerialized(ObjectInputStream& in) |
||||
{ |
||||
XOJ_CHECK_TYPE(LineStyle); |
||||
|
||||
in.readObject("LineStyle"); |
||||
|
||||
g_free(this->dashes); |
||||
this->dashes = NULL; |
||||
this->dashCount = 0; |
||||
in.readData((void**) &this->dashes, &this->dashCount); |
||||
|
||||
in.endObject(); |
||||
} |
||||
|
||||
/**
|
||||
* Get dash array and count |
||||
* |
||||
* @return true if dashed |
||||
*/ |
||||
bool LineStyle::getDashes(const double*& dashes, int& dashCount) const |
||||
{ |
||||
XOJ_CHECK_TYPE(LineStyle); |
||||
|
||||
dashes = this->dashes; |
||||
dashCount = this->dashCount; |
||||
|
||||
return this->dashCount > 0; |
||||
} |
||||
|
||||
/**
|
||||
* Set the dash array and count |
||||
* |
||||
* @param dashes Dash data, will be copied |
||||
* @param dashCount Count of entries |
||||
*/ |
||||
void LineStyle::setDashes(const double* dashes, int dashCount) |
||||
{ |
||||
XOJ_CHECK_TYPE(LineStyle); |
||||
|
||||
g_free(this->dashes); |
||||
if (dashCount == 0 || dashes == NULL) |
||||
{ |
||||
this->dashCount = 0; |
||||
this->dashes = NULL; |
||||
return; |
||||
} |
||||
|
||||
this->dashes = (double*)g_malloc(dashCount * sizeof(double)); |
||||
this->dashCount = dashCount; |
||||
|
||||
memcpy(this->dashes, dashes, this->dashCount * sizeof(double)); |
||||
} |
||||
|
||||
/**
|
||||
* Get dash array and count |
||||
* |
||||
* @return true if dashed |
||||
*/ |
||||
bool LineStyle::hasDashes() const |
||||
{ |
||||
XOJ_CHECK_TYPE(LineStyle); |
||||
|
||||
return this->dashCount > 0; |
||||
} |
||||
@ -0,0 +1,66 @@ |
||||
/*
|
||||
* Xournal++ |
||||
* |
||||
* Dash definition of a stroke |
||||
* |
||||
* @author Xournal++ Team |
||||
* https://github.com/xournalpp/xournalpp
|
||||
* |
||||
* @license GNU GPLv2 or later |
||||
*/ |
||||
|
||||
#pragma once |
||||
|
||||
#include <serializing/Serializeable.h> |
||||
|
||||
#include <XournalType.h> |
||||
|
||||
|
||||
class LineStyle : public Serializeable |
||||
{ |
||||
public: |
||||
LineStyle(); |
||||
LineStyle(const LineStyle& other); |
||||
virtual ~LineStyle(); |
||||
|
||||
void operator=(const LineStyle& other); |
||||
|
||||
public: |
||||
// Serialize interface
|
||||
void serialize(ObjectOutputStream& out); |
||||
void readSerialized(ObjectInputStream& in); |
||||
|
||||
public: |
||||
/**
|
||||
* Get dash array and count |
||||
* |
||||
* @return true if dashed |
||||
*/ |
||||
bool getDashes(const double*& dashes, int& dashCount) const; |
||||
|
||||
/**
|
||||
* @return true if dashed |
||||
*/ |
||||
bool hasDashes() const; |
||||
|
||||
/**
|
||||
* Set the dash array and count |
||||
* |
||||
* @param dashes Dash data, will be copied |
||||
* @param dashCount Count of entries |
||||
*/ |
||||
void setDashes(const double* dashes, int dashCount); |
||||
|
||||
private: |
||||
XOJ_TYPE_ATTRIB; |
||||
|
||||
/**
|
||||
* Dash definition (NULL for no Dash) |
||||
*/ |
||||
double* dashes = NULL; |
||||
|
||||
/**
|
||||
* Dash count (0 for no dash) |
||||
*/ |
||||
int dashCount = 0; |
||||
}; |
||||
Loading…
Reference in new issue