forked from wtnbgo/layerEx
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
LayerExBase.cpp
129 lines (119 loc) · 4.01 KB
/
LayerExBase.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include "LayerExBase.h"
int NI_LayerExBase::classId;
iTJSDispatch2 * NI_LayerExBase::_leftProp = NULL;
iTJSDispatch2 * NI_LayerExBase::_topProp = NULL;
iTJSDispatch2 * NI_LayerExBase::_widthProp = NULL;
iTJSDispatch2 * NI_LayerExBase::_heightProp = NULL;
iTJSDispatch2 * NI_LayerExBase::_pitchProp = NULL;
iTJSDispatch2 * NI_LayerExBase::_bufferProp = NULL;
iTJSDispatch2 * NI_LayerExBase::_updateProp = NULL;
void
NI_LayerExBase::init(iTJSDispatch2 *layerobj)
{
// プロパティ取得
tTJSVariant var;
if (TJS_FAILED(layerobj->PropGet(TJS_IGNOREPROP, TJS_W("imageLeft"), NULL, &var, layerobj))) {
TVPThrowExceptionMessage(TJS_W("invoking of Layer.imageLeft failed."));
} else {
_leftProp = var;
}
if (TJS_FAILED(layerobj->PropGet(TJS_IGNOREPROP, TJS_W("imageTop"), NULL, &var, layerobj))) {
TVPThrowExceptionMessage(TJS_W("invoking of Layer.imageTop failed."));
} else {
_topProp = var;
}
if (TJS_FAILED(layerobj->PropGet(TJS_IGNOREPROP, TJS_W("imageWidth"), NULL, &var, layerobj))) {
TVPThrowExceptionMessage(TJS_W("invoking of Layer.imageWidth failed."));
} else {
_widthProp = var;
}
if (TJS_FAILED(layerobj->PropGet(TJS_IGNOREPROP, TJS_W("imageHeight"), NULL, &var, layerobj))) {
TVPThrowExceptionMessage(TJS_W("invoking of Layer.imageHeight failed."));
} else {
_heightProp = var;
}
if (TJS_FAILED(layerobj->PropGet(TJS_IGNOREPROP, TJS_W("mainImageBufferForWrite"), NULL, &var, layerobj))) {
TVPThrowExceptionMessage(TJS_W("invoking of Layer.mainImageBufferForWrite failed."));
} else {
_bufferProp = var;
}
if (TJS_FAILED(layerobj->PropGet(TJS_IGNOREPROP, TJS_W("mainImageBufferPitch"), NULL, &var, layerobj))) {
TVPThrowExceptionMessage(TJS_W("invoking of Layer.mainImageBufferPitch failed."));
} else {
_pitchProp = var;
}
if (TJS_FAILED(layerobj->PropGet(TJS_IGNOREPROP, TJS_W("update"), NULL, &var, layerobj))) {
TVPThrowExceptionMessage(TJS_W("invoking of Layer.update failed."));
} else {
_updateProp = var;
}
}
void
NI_LayerExBase::unInit()
{
if (_leftProp) _leftProp->Release();
if (_topProp) _topProp->Release();
if (_widthProp) _widthProp->Release();
if (_heightProp) _heightProp->Release();
if (_bufferProp) _bufferProp->Release();
if (_pitchProp) _pitchProp->Release();
if (_updateProp) _updateProp->Release();
}
/// プロパティから int 値を取得する
static tjs_int64 getPropValue(iTJSDispatch2 *dispatch, iTJSDispatch2 *layerobj)
{
tTJSVariant var;
if(TJS_FAILED(dispatch->PropGet(0, NULL, NULL, &var, layerobj))) {
TVPThrowExceptionMessage(TJS_W("can't get int value from property."));
}
return var;
}
void
NI_LayerExBase::reset(iTJSDispatch2 *layerobj)
{
_width = (int)getPropValue(_widthProp, layerobj);
_height = (int)getPropValue(_heightProp, layerobj);
_buffer = (unsigned char *)getPropValue(_bufferProp, layerobj);
_pitch = (int)getPropValue(_pitchProp, layerobj);
}
/**
* 更新処理呼び出し
* layer.update(x,y,w,h) を呼び出す
* 画像領域全体を更新とする
*/
void
NI_LayerExBase::redraw(iTJSDispatch2 *layerobj)
{
tTJSVariant vars[4];
_leftProp->PropGet(0,NULL,NULL,&vars[0], layerobj);
_topProp->PropGet(0,NULL,NULL,&vars[1], layerobj);
_widthProp->PropGet(0,NULL,NULL,&vars[2], layerobj);
_heightProp->PropGet(0,NULL,NULL,&vars[3], layerobj);
tTJSVariant *varsp[4] = {vars, vars+1, vars+2, vars+3};
_updateProp->FuncCall(0, NULL, NULL, NULL, 4, varsp, layerobj);
}
NI_LayerExBase *
NI_LayerExBase::getNative(iTJSDispatch2 *objthis, bool create)
{
NI_LayerExBase *_this = NULL;
if (TJS_FAILED(objthis->NativeInstanceSupport(TJS_NIS_GETINSTANCE,
classId, (iTJSNativeInstance**)&_this)) && create) {
_this = new NI_LayerExBase();
if (TJS_FAILED(objthis->NativeInstanceSupport(TJS_NIS_REGISTER,
classId, (iTJSNativeInstance **)&_this))) {
delete _this;
_this = NULL;
}
}
return _this;
}
/**
* コンストラクタ
*/
NI_LayerExBase::NI_LayerExBase()
{
_width = 0;
_height = 0;
_pitch = 0;
_buffer = NULL;
}