File: FormRealtimeConfig.cs

package info (click to toggle)
cadencii 3.3.9%2Bsvn20110818.r1732-5
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 35,880 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 (337 lines) | stat: -rw-r--r-- 13,906 bytes parent folder | download | duplicates (6)
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
/*
 * FormRealtimeConfig.cs
 * Copyright © 2009-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;

//INCLUDE-SECTION IMPORT ../BuildJavaUI/src/org/kbinani/cadencii/FormRealtimeConfig.java

import org.kbinani.*;
import org.kbinani.apputil.*;
import org.kbinani.windows.forms.*;
#else
using System;
using org.kbinani;
using org.kbinani.windows.forms;
using org.kbinani.apputil;

namespace org.kbinani.cadencii
{
    using BEventArgs = System.EventArgs;
    using BEventHandler = System.EventHandler;
    using boolean = System.Boolean;
#endif

#if JAVA
    public class FormRealtimeConfig extends BDialog {
#else
    public class FormRealtimeConfig : BDialog
    {
#endif
        private boolean m_game_ctrl_enabled = false;
        private double m_last_event_processed;
        private BTimer timer;

        public FormRealtimeConfig()
        {
#if JAVA
            super();
            initialize();
            timer = new BTimer();
#else
            InitializeComponent();
            timer = new BTimer( this.components );
#endif
            timer.setDelay( 10 );
            registerEventHandlers();
            setResources();
            Util.applyFontRecurse( this, AppManager.editorConfig.getBaseFont() );
        }

        #region public methods
        public float getSpeed()
        {
            return (float)numSpeed.getFloatValue();
        }
        #endregion

        #region event handlers
        public void FormRealtimeConfig_Load( Object sender, BEventArgs e )
        {
#if JAVA
            System.err.println( "info; FormRealtimeConfig#FormRealtimeConfig_Load; not implemented yet; \"int num_joydev = 0\"" );
            int num_joydev = 0;
#else
            int num_joydev = winmmhelp.JoyGetNumJoyDev();
#endif
            m_game_ctrl_enabled = (num_joydev > 0);
            if ( m_game_ctrl_enabled ) {
                timer.start();
            }
        }

        public void timer_Tick( Object sender, BEventArgs e )
        {
#if !JAVA
            try {
                double now = PortUtil.getCurrentTime();
                double dt_ms = (now - m_last_event_processed) * 1000.0;
                //JoystickState state = m_game_ctrl.CurrentJoystickState;
                int len = winmmhelp.JoyGetNumButtons( 0 );
                byte[] buttons = new byte[len];
                int pov0;
                winmmhelp.JoyGetStatus( 0, out buttons, out pov0 );
                //int[] pov = state.GetPointOfView();
                //int pov0 = pov[0];
                boolean btn_x = (buttons[AppManager.editorConfig.GameControlerCross] > 0x00);
                boolean btn_o = (buttons[AppManager.editorConfig.GameControlerCircle] > 0x00);
                boolean btn_tr = (buttons[AppManager.editorConfig.GameControlerTriangle] > 0x00);
                boolean btn_re = (buttons[AppManager.editorConfig.GameControlerRectangle] > 0x00);
                boolean pov_r = pov0 == 9000;  //(4500 <= pov0 && pov0 <= 13500);
                boolean pov_l = pov0 == 27000; //(22500 <= pov[0] && pov[0] <= 31500);
                boolean pov_u = pov0 == 0;     //(31500 <= pov[0] || (0 <= pov[0] && pov[0] <= 4500));
                boolean pov_d = pov0 == 18000; //(13500 <= pov[0] && pov[0] <= 22500);
                boolean L1 = (buttons[AppManager.editorConfig.GameControlL1] > 0x00);
                boolean R1 = (buttons[AppManager.editorConfig.GameControlR1] > 0x00);
                boolean L2 = (buttons[AppManager.editorConfig.GameControlL2] > 0x00);
                boolean R2 = (buttons[AppManager.editorConfig.GameControlR2] > 0x00);
                boolean SELECT = (buttons[AppManager.editorConfig.GameControlSelect] > 0x00);
                if ( dt_ms > AppManager.editorConfig.GameControlerMinimumEventInterval ) {
                    if ( btnStart.isFocusOwner() ) {
                        if ( btn_o ) {
                            timer.stop();
                            btnStart_Click( this, new EventArgs() );
                            m_last_event_processed = now;
                        } else if ( pov_r ) {
                            btnCancel.requestFocus();
                            m_last_event_processed = now;
                        } else if ( pov_d ) {
                            numSpeed.requestFocus();
                            m_last_event_processed = now;
                        }
                    } else if ( btnCancel.isFocusOwner() ) {
                        if ( btn_o ) {
                            timer.stop();
                            setDialogResult( BDialogResult.CANCEL );
                            close();
                        } else if ( pov_l ) {
                            btnStart.requestFocus();
                            m_last_event_processed = now;
                        } else if ( pov_d || pov_r ) {
                            numSpeed.requestFocus();
                            m_last_event_processed = now;
                        }
                    } else if ( numSpeed.isFocusOwner() ) {
                        if ( R1 ) {
                            if ( numSpeed.getFloatValue() + numSpeed.getIncrement() <= numSpeed.getMaximum() ) {
                                numSpeed.setFloatValue( numSpeed.getFloatValue() + numSpeed.getIncrement() );
                                m_last_event_processed = now;
                            }
                        } else if ( L1 ) {
                            if ( numSpeed.getFloatValue() - numSpeed.getIncrement() >= numSpeed.getMinimum() ) {
                                numSpeed.setFloatValue( numSpeed.getFloatValue() - numSpeed.getIncrement() );
                                m_last_event_processed = now;
                            }
                        } else if ( pov_l ) {
                            btnCancel.requestFocus();
                            m_last_event_processed = now;
                        } else if ( pov_u ) {
                            btnStart.requestFocus();
                            m_last_event_processed = now;
                        }
                    }
                }
            } catch ( Exception ex ) {
            }
#endif
        }

        public void btnStart_Click( Object sender, BEventArgs e )
        {
            setDialogResult( BDialogResult.OK );
            close();
        }

        public void btnCancel_Click( Object sender, BEventArgs e )
        {
            setDialogResult( BDialogResult.CANCEL );
        }
        #endregion

        #region helper methods
        private void registerEventHandlers()
        {
            this.Load += new BEventHandler( FormRealtimeConfig_Load );
            timer.Tick += new BEventHandler( timer_Tick );
            btnStart.Click += new BEventHandler( btnStart_Click );
            btnCancel.Click += new BEventHandler( btnCancel_Click );
        }

        private void setResources()
        {
        }
        #endregion

        #region UI implementation
#if JAVA
        #region UI Impl for Java
        //INCLUDE-SECTION FIELD ../BuildJavaUI/src/org/kbinani/cadencii/FormRealtimeConfig.java
        //INCLUDE-SECTION METHOD ../BuildJavaUI/src/org/kbinani/cadencii/FormRealtimeConfig.java
        #endregion
#else
        #region UI Impl for C#
        /// <summary>
        /// 必要なデザイナ変数です。
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// 使用中のリソースをすべてクリーンアップします。
        /// </summary>
        /// <param name="disposing">マネージ リソースが破棄される場合 true、破棄されない場合は false です。</param>
        protected override void Dispose( boolean disposing )
        {
            if ( disposing && (components != null) ) {
                components.Dispose();
            }
            base.Dispose( disposing );
        }

        #region Windows フォーム デザイナで生成されたコード

        /// <summary>
        /// デザイナ サポートに必要なメソッドです。このメソッドの内容を
        /// コード エディタで変更しないでください。
        /// </summary>
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            this.btnStart = new BButton();
            this.btnCancel = new BButton();
            this.lblRealTimeInput = new BLabel();
            this.lblSpeed = new BLabel();
            this.numSpeed = new BNumericUpDown();
            ((System.ComponentModel.ISupportInitialize)(this.numSpeed)).BeginInit();
            this.SuspendLayout();
            // 
            // btnStart
            // 
            this.btnStart.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
            this.btnStart.Location = new System.Drawing.Point( 25, 52 );
            this.btnStart.Name = "btnStart";
            this.btnStart.Size = new System.Drawing.Size( 120, 33 );
            this.btnStart.TabIndex = 0;
            this.btnStart.Text = "Start";
            this.btnStart.UseVisualStyleBackColor = true;
            // 
            // btnCancel
            // 
            this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.btnCancel.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
            this.btnCancel.Location = new System.Drawing.Point( 196, 52 );
            this.btnCancel.Name = "btnCancel";
            this.btnCancel.Size = new System.Drawing.Size( 120, 33 );
            this.btnCancel.TabIndex = 1;
            this.btnCancel.Text = "Cancel";
            this.btnCancel.UseVisualStyleBackColor = true;
            // 
            // lblRealTimeInput
            // 
            this.lblRealTimeInput.Font = new System.Drawing.Font( "Verdana", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)) );
            this.lblRealTimeInput.Location = new System.Drawing.Point( 23, 9 );
            this.lblRealTimeInput.Name = "lblRealTimeInput";
            this.lblRealTimeInput.Size = new System.Drawing.Size( 293, 28 );
            this.lblRealTimeInput.TabIndex = 2;
            this.lblRealTimeInput.Text = "Realtime Input";
            this.lblRealTimeInput.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            // 
            // lblSpeed
            // 
            this.lblSpeed.AutoSize = true;
            this.lblSpeed.Location = new System.Drawing.Point( 49, 114 );
            this.lblSpeed.Name = "lblSpeed";
            this.lblSpeed.Size = new System.Drawing.Size( 36, 12 );
            this.lblSpeed.TabIndex = 3;
            this.lblSpeed.Text = "Speed";
            // 
            // numSpeed
            // 
            this.numSpeed.DecimalPlaces = 1;
            this.numSpeed.Increment = new decimal( new int[] {
            1,
            0,
            0,
            65536} );
            this.numSpeed.Location = new System.Drawing.Point( 107, 112 );
            this.numSpeed.Maximum = new decimal( new int[] {
            30,
            0,
            0,
            65536} );
            this.numSpeed.Minimum = new decimal( new int[] {
            1,
            0,
            0,
            65536} );
            this.numSpeed.Name = "numSpeed";
            this.numSpeed.Size = new System.Drawing.Size( 120, 19 );
            this.numSpeed.TabIndex = 4;
            this.numSpeed.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
            this.numSpeed.Value = new decimal( new int[] {
            1,
            0,
            0,
            0} );
            // 
            // FormRealtimeConfig
            // 
            this.AcceptButton = this.btnStart;
            this.AutoScaleDimensions = new System.Drawing.SizeF( 6F, 12F );
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.BackColor = System.Drawing.SystemColors.Control;
            this.CancelButton = this.btnCancel;
            this.ClientSize = new System.Drawing.Size( 347, 161 );
            this.Controls.Add( this.numSpeed );
            this.Controls.Add( this.lblSpeed );
            this.Controls.Add( this.lblRealTimeInput );
            this.Controls.Add( this.btnCancel );
            this.Controls.Add( this.btnStart );
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "FormRealtimeConfig";
            this.ShowIcon = false;
            this.ShowInTaskbar = false;
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
            this.Text = "FormRealtimeConfig";
            ((System.ComponentModel.ISupportInitialize)(this.numSpeed)).EndInit();
            this.ResumeLayout( false );
            this.PerformLayout();

        }

        #endregion

        private BButton btnStart;
        private BButton btnCancel;
        private BLabel lblRealTimeInput;
        private BLabel lblSpeed;
        private BNumericUpDown numSpeed;
        #endregion
#endif
        #endregion
    }

#if !JAVA
}
#endif