File: WaveformZoomController.cs

package info (click to toggle)
cadencii 3.3.9%2Bsvn20110818.r1732-6
  • links: PTS
  • area: main
  • in suites: buster
  • size: 35,916 kB
  • sloc: cs: 160,836; java: 42,449; cpp: 7,605; ansic: 1,728; perl: 1,087; makefile: 236; php: 142; xml: 117; sh: 21
file content (244 lines) | stat: -rw-r--r-- 8,088 bytes parent folder | download | duplicates (5)
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
/*
 * WaveformZoomController.cs
 * Copyright © 2011 kbinani
 *
 * This file is part of org.kbinani.cadencii.
 *
 * org.kbinani.cadencii is free software; you can redistribute it and/or
 * modify it under the terms of the GPLv3 License.
 *
 * org.kbinani.cadencii is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 */
#if JAVA

package org.kbinani.cadencii;

import java.awt.*;

import org.kbinani.*;

#else

using org.kbinani.java.awt;

namespace org.kbinani.cadencii
{
    using boolean = System.Boolean;
#endif

#if JAVA
    class WaveformZoomController extends ControllerBase implements WaveformZoomUiListener
#else
    class WaveformZoomController : ControllerBase, WaveformZoomUiListener
#endif
    {
        /// <summary>
        /// 波形表示部の拡大ボタン上でマウスが下りた状態かどうか
        /// </summary>
        private boolean mWaveViewButtonZoomMouseDowned = false;
        /// <summary>
        /// 波形表示部のAutoMaximizeボタン上でマウスが下りた状態かどうか
        /// </summary>
        private boolean mWaveViewButtonAutoMaximizeMouseDowned = false;
        /// <summary>
        /// 波形表示部の縦軸の拡大率を自動最大化するかどうか
        /// </summary>
        private boolean mWaveViewAutoMaximize = false;
        /// <summary>
        /// 波形表示部分のズーム時に,マウスが下りた瞬間のY座標
        /// </summary>
        private int mWaveViewMouseDownedLocationY;
        /// <summary>
        /// 波形表示部の拡大ボタン上でマウスが下りた瞬間の,波形表示部の縦軸拡大率.
        /// </summary>
        private float mWaveViewInitScale;

        private WaveView mWaveView = null;
        private FormMain mFormMain = null;
        private WaveformZoomUi mUi = null;

        /// <summary>
        /// Wave表示部等のボタンと他のコンポーネントの間のスペース
        /// </summary>
        const int SPACE = 4;

        public WaveformZoomController( FormMain form_main, WaveView wave_view )
        {
            mWaveView = wave_view;
            mFormMain = form_main;

            mUi = (WaveformZoomUi)new WaveformZoomUiImpl();
            mUi.setListener( this );
        }

        public void refreshScreen()
        {
            mFormMain.refreshScreen();
        }

        public void setAutoMaximize( boolean value )
        {
            mWaveView.setAutoMaximize( value );
        }

        public float getScale()
        {
            return mWaveView.getScale();
        }

        public void setScale( float value )
        {
            mWaveView.setScale( value );
        }

        public WaveformZoomUi getUi()
        {
            return mUi;
        }

        public void receivePaintSignal( Graphics g )
        {
            int key_width = AppManager.keyWidth;
            int width = key_width - 1;
            int height = mUi.getHeight() - 1;

            // 背景を塗る
            g.setColor( PortUtil.DarkGray );
            g.fillRect( 0, 0, width, height );

            // AutoMaximizeのチェックボックスを描く
            g.setColor( mWaveViewButtonAutoMaximizeMouseDowned ? PortUtil.Gray : PortUtil.LightGray );
            g.fillRect( SPACE, SPACE, 16, 16 );
            g.setColor( PortUtil.Gray );
            g.drawRect( SPACE, SPACE, 16, 16 );
            if ( mWaveViewAutoMaximize )
            {
                g.setColor( PortUtil.Gray );
                g.fillRect( SPACE + 3, SPACE + 3, 11, 11 );
            }
            g.setColor( Color.black );
            g.setFont( AppManager.baseFont8 );
            g.drawString(
                "Auto Maximize",
                SPACE + 16 + SPACE,
                SPACE + AppManager.baseFont8Height / 2 - AppManager.baseFont8OffsetHeight + 1 );

            // ズーム用ボタンを描く
            int zoom_button_y = SPACE + 16 + SPACE;
            int zoom_button_height = height - SPACE - zoom_button_y;
            Rectangle rc = getButtonBoundsWaveViewZoom();
            if ( !mWaveViewAutoMaximize )
            {
                g.setColor( mWaveViewButtonZoomMouseDowned ? PortUtil.Gray : PortUtil.LightGray );
                g.fillRect( rc.x, rc.y, rc.width, rc.height );
            }
            g.setColor( PortUtil.Gray );
            g.drawRect( rc.x, rc.y, rc.width, rc.height );
            g.setColor( mWaveViewAutoMaximize ? PortUtil.Gray : Color.black );
            rc.y = rc.y + 1;
            PortUtil.drawStringEx(
                g, (mWaveViewButtonZoomMouseDowned ? "↑Move Mouse↓" : "Zoom"), AppManager.baseFont9,
                rc, PortUtil.STRING_ALIGN_CENTER, PortUtil.STRING_ALIGN_CENTER );
        }

        public void receiveMouseDownSignal( int x, int y )
        {
            Point p = new Point( x, y );

            int width = AppManager.keyWidth - 1;
            int height = mUi.getHeight();

            // AutoMaximizeボタン
            Rectangle rc = new Rectangle( SPACE, SPACE, width - SPACE - SPACE, 16 );
            if ( Utility.isInRect( p, rc ) )
            {
                mWaveViewButtonAutoMaximizeMouseDowned = true;
                mWaveViewButtonZoomMouseDowned = false;

                mUi.repaint();
                return;
            }

            if ( !mWaveViewAutoMaximize )
            {
                // Zoomボタン
                rc = getButtonBoundsWaveViewZoom();
                if ( Utility.isInRect( p, rc ) )
                {
                    mWaveViewMouseDownedLocationY = p.y;
                    mWaveViewButtonZoomMouseDowned = true;
                    mWaveViewButtonAutoMaximizeMouseDowned = false;
                    mWaveViewInitScale = mWaveView.getScale();

                    mUi.repaint();
                    return;
                }
            }

            mWaveViewButtonAutoMaximizeMouseDowned = false;
            mWaveViewButtonZoomMouseDowned = false;
            mUi.repaint();
        }

        public void receiveMouseMoveSignal( int x, int y )
        {
            if ( !mWaveViewButtonZoomMouseDowned )
            {
                return;
            }

            int height = mUi.getHeight();
            int delta = mWaveViewMouseDownedLocationY - y;
            float scale = mWaveViewInitScale + delta * 3.0f / height * mWaveViewInitScale;
            mWaveView.setScale( scale );

            mFormMain.refreshScreen();
        }

        public void receiveMouseUpSignal( int x, int y )
        {
            int width = AppManager.keyWidth - 1;
            int height = mUi.getHeight();

            // AutoMaximizeボタン
            if ( Utility.isInRect( x, y, SPACE, SPACE, width - SPACE - SPACE, 16 ) )
            {
                if ( mWaveViewButtonAutoMaximizeMouseDowned )
                {
                    mWaveViewAutoMaximize = !mWaveViewAutoMaximize;
                    mWaveView.setAutoMaximize( mWaveViewAutoMaximize );
                }
            }

            mWaveViewButtonAutoMaximizeMouseDowned = false;
            mWaveViewButtonZoomMouseDowned = false;
#if JAVA
            mFormMain.refreshScreen();
#else
            mUi.repaint();
#endif
        }

        /// <summary>
        /// 波形表示部のズームボタンの形を取得します
        /// </summary>
        /// <returns></returns>
        private Rectangle getButtonBoundsWaveViewZoom()
        {
            int width = AppManager.keyWidth - 1;
            int height = mUi.getHeight() - 1;

            int y = SPACE + 16 + SPACE;
            return new Rectangle( SPACE, y, width - SPACE - SPACE, height - SPACE - y );
        }
    }

#if JAVA

#else

}

#endif