1 /*$
2  Copyright (C) 2016-2020 Azel.
3 
4  This file is part of AzPainterB.
5 
6  AzPainterB is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  AzPainterB is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 $*/
19 
20 /*****************************************
21  * DockLayer
22  *
23  * [dock] レイヤ
24  *****************************************/
25 
26 #include "mDef.h"
27 #include "mWindowDef.h"
28 #include "mWidget.h"
29 #include "mContainer.h"
30 #include "mDockWidget.h"
31 #include "mIconButtons.h"
32 #include "mImageList.h"
33 #include "mEvent.h"
34 #include "mTrans.h"
35 
36 #include "defWidgets.h"
37 #include "defDraw.h"
38 #include "defConfig.h"
39 
40 #include "DockObject.h"
41 #include "AppResource.h"
42 
43 #include "trgroup.h"
44 #include "trid_mainmenu.h"
45 
46 
47 //------------------------
48 
49 #define _DOCKLAYER(p)  ((DockLayer *)(p))
50 #define _DL_PTR        ((DockLayer *)APP_WIDGETS->dockobj[DOCKWIDGET_LAYER])
51 
52 //------------------------
53 
54 typedef struct _DockLayerArea DockLayerArea;
55 
56 typedef struct
57 {
58 	DockObject obj;
59 
60 	mWidget *param_ct;
61 	mIconButtons *ib;
62 	DockLayerArea *area;
63 }DockLayer;
64 
65 //------------------------
66 
67 /* DockLayer_param.c */
68 
69 mWidget *DockLayer_parameter_new(mWidget *parent);
70 void DockLayer_parameter_setValue(mWidget *wg);
71 
72 /* DockLayer_area.c */
73 
74 DockLayerArea *DockLayerArea_new(mWidget *parent);
75 void DockLayerArea_drawLayer(DockLayerArea *p,LayerItem *pi);
76 void DockLayerArea_setScrollInfo(DockLayerArea *p);
77 void DockLayerArea_changeCurrent_visible(DockLayerArea *p,LayerItem *lastitem,mBool update_all);
78 
79 //------------------------
80 
81 
82 
83 /** イベント */
84 
_event_handle(mWidget * wg,mEvent * ev)85 static int _event_handle(mWidget *wg,mEvent *ev)
86 {
87 	//ツールバーのコマンドはメインウィンドウへ送る
88 
89 	if(ev->type == MEVENT_COMMAND)
90 	{
91 		(((mWidget *)APP_WIDGETS->mainwin)->event)((mWidget *)APP_WIDGETS->mainwin, ev);
92 	}
93 
94 	return 1;
95 }
96 
97 /** mDockWidget ハンドラ : 内容作成 */
98 
_dock_func_create(mDockWidget * dockwg,int id,mWidget * parent)99 static mWidget *_dock_func_create(mDockWidget *dockwg,int id,mWidget *parent)
100 {
101 	DockLayer *p = _DL_PTR;
102 	mWidget *ct;
103 	mIconButtons *ib;
104 	int i;
105 	uint16_t bttid[] = {
106 		TRMENU_LAYER_NEW, TRMENU_LAYER_NEW_FOLDER, TRMENU_LAYER_COPY, TRMENU_LAYER_ERASE,
107 		TRMENU_LAYER_DELETE, TRMENU_LAYER_COMBINE, TRMENU_LAYER_DROP,
108 		TRMENU_LAYER_TB_MOVE_UP, TRMENU_LAYER_TB_MOVE_DOWN
109 	};
110 
111 	//コンテナ
112 
113 	ct = mContainerCreate(parent, MCONTAINER_TYPE_VERT, 0, 0, MLF_EXPAND_WH);
114 
115 	ct->event = _event_handle;
116 	ct->notifyTarget = MWIDGET_NOTIFYTARGET_SELF;
117 	ct->param = (intptr_t)p;
118 
119 	//上部のパラメータ部分
120 
121 	p->param_ct = DockLayer_parameter_new(ct);
122 
123 	DockLayer_parameter_setValue(p->param_ct);
124 
125 	//エリア (レイヤ名用に 12px フォントセット)
126 
127 	p->area = DockLayerArea_new(ct);
128 
129 	M_WIDGET(p->area)->font = APP_WIDGETS->font_dock12px;
130 
131 	//ツールバー
132 
133 	p->ib = ib = mIconButtonsNew(0, ct,
134 		MICONBUTTONS_S_TOOLTIP | MICONBUTTONS_S_DESTROY_IMAGELIST);
135 
136 	ib->wg.fLayout = MLF_EXPAND_W;
137 
138 	mIconButtonsSetImageList(ib, AppResource_loadIconImage("layer.png", APP_CONF->iconsize_layer));
139 	mIconButtonsSetTooltipTrGroup(ib, TRGROUP_DOCK_LAYER);
140 
141 	for(i = 0; i < 9; i++)
142 		mIconButtonsAdd(ib, bttid[i], i, i, 0);
143 
144 	mIconButtonsCalcHintSize(ib);
145 
146 	return ct;
147 }
148 
149 /** 作成 */
150 
DockLayer_new(mDockWidgetState * state)151 void DockLayer_new(mDockWidgetState *state)
152 {
153 	DockObject *p;
154 
155 	p = DockObject_new(DOCKWIDGET_LAYER,
156 			sizeof(DockLayer), MDOCKWIDGET_S_EXPAND, MWINDOW_S_ENABLE_DND,
157 			state, _dock_func_create);
158 
159 	mDockWidgetCreateWidget(p->dockwg);
160 }
161 
162 
163 //===============================
164 // 外部からの呼び出し
165 //===============================
166 
167 
168 /** すべて更新 */
169 
DockLayer_update_all()170 void DockLayer_update_all()
171 {
172 	DockLayer *p = _DL_PTR;
173 
174 	if(DockObject_canDoWidget((DockObject *)p))
175 	{
176 		DockLayer_parameter_setValue(p->param_ct);
177 
178 		DockLayerArea_setScrollInfo(p->area);
179 
180 		mWidgetUpdate(M_WIDGET(p->area));
181 	}
182 }
183 
184 /** カレントレイヤの上部パラメータ更新 */
185 
DockLayer_update_curparam()186 void DockLayer_update_curparam()
187 {
188 	DockLayer *p = _DL_PTR;
189 
190 	if(DockObject_canDoWidget((DockObject *)p))
191 		DockLayer_parameter_setValue(p->param_ct);
192 }
193 
194 /** カレントレイヤを更新 */
195 
DockLayer_update_curlayer(mBool setparam)196 void DockLayer_update_curlayer(mBool setparam)
197 {
198 	DockLayer *p = _DL_PTR;
199 
200 	if(DockObject_canDoWidget((DockObject *)p))
201 	{
202 		if(setparam)
203 			DockLayer_parameter_setValue(p->param_ct);
204 
205 		DockLayerArea_drawLayer(p->area, APP_DRAW->curlayer);
206 	}
207 }
208 
209 /** 指定レイヤのみ更新 */
210 
DockLayer_update_layer(LayerItem * item)211 void DockLayer_update_layer(LayerItem *item)
212 {
213 	DockLayer *p = _DL_PTR;
214 
215 	if(item && DockObject_canDoWidget_visible((DockObject *)p))
216 		DockLayerArea_drawLayer(p->area, item);
217 }
218 
219 /** カレント変更時の更新 (カレントが一覧上に見えるように)
220  *
221  * @param lastitem   カレント変更前のカレントレイヤ
222  * @param update_all フォルダ展開などによりリスト全体を更新 */
223 
DockLayer_update_changecurrent_visible(LayerItem * lastitem,mBool update_all)224 void DockLayer_update_changecurrent_visible(LayerItem *lastitem,mBool update_all)
225 {
226 	DockLayer *p = _DL_PTR;
227 
228 	if(DockObject_canDoWidget((DockObject *)p))
229 	{
230 		DockLayer_parameter_setValue(p->param_ct);
231 
232 		if(update_all)
233 			DockLayerArea_setScrollInfo(p->area);
234 
235 		DockLayerArea_changeCurrent_visible(p->area, lastitem, update_all);
236 	}
237 }
238 
239 /** アイコンサイズ変更 */
240 
DockLayer_changeIconSize()241 void DockLayer_changeIconSize()
242 {
243 	DockLayer *p = _DL_PTR;
244 
245 	if(DockObject_canDoWidget((DockObject *)p))
246 	{
247 		mIconButtonsReplaceImageList(p->ib,
248 			AppResource_loadIconImage("layer.png", APP_CONF->iconsize_layer));
249 
250 		DockObject_relayout_inWindowMode(DOCKWIDGET_LAYER);
251 	}
252 }
253