コピペ: OmegaChart Fibonacciトレースメント ChartCanvas.cs 追加修正ポイントには//☆Fibonacci ※差し替え その2

形式
Plain text
投稿日時
2018-08-19 18:00
公開期間
無期限
  1. using System;
  2. using System.Collections;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Windows.Forms;
  6. using System.Diagnostics;
  7. using Zanetti.Indicators;
  8. using Zanetti.Data;
  9. using Zanetti.Forms;
  10. namespace Zanetti.UI
  11. {
  12. /// <summary>
  13. /// </summary>
  14. internal class ChartCanvas : System.Windows.Forms.UserControl
  15. {
  16. private AbstractBrand _brand;
  17. private ChartDrawing _drawing;
  18. private ChartTitle _title;
  19. private System.Windows.Forms.HScrollBar _scrollBar;
  20. private Label _complementaryLabel;
  21. private int _diffX = 0;
  22. private int _diffY = 0;
  23. private int _destX = 0;
  24. private int _pivotX = 0;
  25. private int _destY = 0;
  26. private int _pivotY = 0;
  27. /// <summary>
  28. /// 必要なデザイナ変数です。
  29. /// </summary>
  30. private System.ComponentModel.Container components = null;
  31. public ChartCanvas()
  32. {
  33. // この呼び出しは、Windows.Forms フォーム デザイナで必要です。
  34. InitializeComponent();
  35. // TODO: InitializeComponent 呼び出しの後に初期化処理を追加します。
  36. this.BackColor = Env.Preference.BackBrush.Color;
  37. this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer, true);
  38. _drawing = new ChartDrawing(this);
  39. }
  40. /// <summary>
  41. /// 使用されているリソースに後処理を実行します。
  42. /// </summary>
  43. protected override void Dispose(bool disposing)
  44. {
  45. if (disposing)
  46. {
  47. if (components != null)
  48. {
  49. components.Dispose();
  50. }
  51. }
  52. base.Dispose(disposing);
  53. }
  54. #region コンポーネント デザイナで生成されたコード
  55. /// <summary>
  56. /// デザイナ サポートに必要なメソッドです。このメソッドの内容を
  57. /// コード エディタで変更しないでください。
  58. /// </summary>
  59. private void InitializeComponent()
  60. {
  61. this._scrollBar = new System.Windows.Forms.HScrollBar();
  62. _title = new ChartTitle();
  63. this.SuspendLayout();
  64. //
  65. // _scrollBar
  66. //
  67. this._scrollBar.Dock = System.Windows.Forms.DockStyle.Bottom;
  68. this._scrollBar.Enabled = false;
  69. this._scrollBar.LargeChange = 2;
  70. this._scrollBar.Location = new System.Drawing.Point(0, 83);
  71. this._scrollBar.Maximum = 4;
  72. this._scrollBar.Name = "_scrollBar";
  73. this._scrollBar.Size = new System.Drawing.Size(100, 17);
  74. this._scrollBar.TabIndex = 0;
  75. this._scrollBar.ValueChanged += new System.EventHandler(this.OnScrollBarValueChanged);
  76. _title.Location = new Point(0, 0);
  77. _title.Size = new Size(this.Width, Env.Layout.HeaderHeight);
  78. //
  79. // ChartCanvas
  80. //
  81. this.Controls.Add(this._scrollBar);
  82. this.Controls.Add(this._title);
  83. this.MouseUp += new MouseEventHandler(OnMouseUp);
  84. this.Name = "ChartCanvas";
  85. this.Size = new System.Drawing.Size(100, 100);
  86. this.ResumeLayout(false);
  87. _title.BringToFront();
  88. }
  89. #endregion
  90. public Label ComplementaryLabel
  91. {
  92. get
  93. {
  94. if (_complementaryLabel == null)
  95. {
  96. _complementaryLabel = new Label();
  97. _complementaryLabel.Visible = false;
  98. _complementaryLabel.Font = Env.Preference.DefaultFont;
  99. _complementaryLabel.TextAlign = ContentAlignment.MiddleLeft;
  100. _complementaryLabel.BorderStyle = BorderStyle.FixedSingle;
  101. _complementaryLabel.BackColor = Color.FromKnownColor(KnownColor.Info);
  102. _complementaryLabel.ForeColor = Color.FromKnownColor(KnownColor.InfoText);
  103. this.Controls.Add(_complementaryLabel);
  104. }
  105. return _complementaryLabel;
  106. }
  107. }
  108. public ChartTitle ChartTitle
  109. {
  110. get
  111. {
  112. return _title;
  113. }
  114. }
  115. public ChartDrawing DrawingEngine
  116. {
  117. get
  118. {
  119. return _drawing;
  120. }
  121. }
  122. public int BodyHeight
  123. {
  124. get
  125. {
  126. return this.Height - _scrollBar.Height;
  127. }
  128. }
  129. public void LoadBrand(AbstractBrand br, bool preserve_date)
  130. {
  131. int date = -1;
  132. if (preserve_date && _brand != null)
  133. {
  134. DataFarm f = _brand.ReserveFarm();
  135. if (!f.IsEmpty)
  136. {
  137. Debug.Assert(_drawing.FirstDateIndex >= 0 && _drawing.FirstDateIndex < f.TotalLength);
  138. if (_drawing.FirstDateIndex + Env.Layout.DisplayColumnCount >= f.TotalLength)
  139. date = -1; //最終データが見えているときは「最後が見えている」状態を維持
  140. else
  141. date = f.GetByIndex(_drawing.FirstDateIndex).Date;
  142. }
  143. }
  144. _brand = br;
  145. AdjustScrollBar();
  146. if (_scrollBar.Enabled)
  147. {
  148. DataFarm f = br.ReserveFarm();
  149. int v = date == -1 ? GetTotalDataLength() - Env.Layout.DisplayColumnCount : f.DateToIndex(date);
  150. if (v < 0) v = 0;
  151. if (v > _scrollBar.Maximum - _scrollBar.LargeChange + 1) v = _scrollBar.Maximum - _scrollBar.LargeChange + 1;
  152. _scrollBar.Value = v;
  153. }
  154. _drawing.SetBrand(br);
  155. //_title.InitUI();
  156. }
  157. public AbstractBrand GetBrand()
  158. {
  159. return _brand;
  160. }
  161. public int FirstDateIndex
  162. {
  163. get
  164. {
  165. return _drawing.FirstDateIndex;
  166. }
  167. }
  168. public void MoveToLatest()
  169. {
  170. AdjustScrollBar();
  171. int v = 0;
  172. if (_scrollBar.Enabled) v = GetTotalDataLength() - Env.Layout.DisplayColumnCount;
  173. if (v < 0) v = 0;
  174. _scrollBar.Value = v;
  175. Invalidate(false);
  176. }
  177. public void SetDateIndex(int first, int cursor)
  178. {
  179. _scrollBar.Value = first;
  180. DataFarm f = _brand.ReserveFarm();
  181. if (f.IsEmpty)
  182. _drawing.UpdateDateLineIndex(-1);
  183. else
  184. _drawing.UpdateDateLineIndex(Math.Min(cursor, f.FilledLength - 1));
  185. Invalidate(true);
  186. }
  187. public void ForceVisibleDate(int date, bool cut)
  188. {
  189. DataFarm f = _brand.ReserveFarm();
  190. if (f.IsEmpty) return;
  191. int index = f.DateToIndex(date);
  192. //スクロールしないと見えない
  193. if (_drawing.FirstDateIndex > index || index >= _drawing.FirstDateIndex + Env.Layout.DisplayColumnCount || cut)
  194. {
  195. int nv = index - Env.Layout.DisplayColumnCount / 2; //大体真ん中に表示
  196. if (nv < 0) nv = 0;
  197. if (nv >= f.TotalLength) nv = f.TotalLength - 1;
  198. _scrollBar.Value = nv;
  199. }
  200. _drawing.UpdateDateLineIndex(index);
  201. Invalidate(false);
  202. }
  203. public void ReloadFromPreference()
  204. {
  205. Preference pref = Env.Preference;
  206. Color bc = pref.BackBrush.Color;
  207. Color fc = pref.TextColor;
  208. this.BackColor = bc;
  209. this.ForeColor = fc;
  210. if (_complementaryLabel != null) _complementaryLabel.Font = pref.DefaultFont;
  211. //InitOscillatorGroupUI();
  212. _drawing.ClearScale();
  213. }
  214. public void ResetLayout()
  215. {
  216. //_oscillatorGroup.Visible = Env.Options.ShowOscillator;
  217. AdjustScrollBar(); //これは価格帯出来高の表示設定が変化したときだけでもよい
  218. _drawing.ClearScale();
  219. _title.InitUI();
  220. }
  221. //メッセージ処理がらみ
  222. protected override void OnLoad(EventArgs e)
  223. {
  224. base.OnLoad(e);
  225. Preference pref = Env.Preference;
  226. }
  227. protected override void OnPaint(PaintEventArgs e)
  228. {
  229. base.OnPaint(e);
  230. if (this.DesignMode || _brand == null) return;
  231. _drawing.PaintMain(e.Graphics, e.ClipRectangle);
  232. if (_currentFreeLine != null && _currentFreeLine.PivotHasEnoughDistanceTo(this.PointToClient(Control.MousePosition)))
  233. {
  234. IntPtr hdc = e.Graphics.GetHdc();
  235. _currentFreeLine.Draw(Env.Layout.ChartBodyRect, hdc);
  236. e.Graphics.ReleaseHdc(hdc);
  237. }
  238. //☆Fibonacci
  239. if (_currentFibonacci != null && _currentFibonacci.PivotHasEnoughDistanceTo(this.PointToClient(Control.MousePosition)))
  240. {
  241. IntPtr hdc = e.Graphics.GetHdc();
  242. _currentFibonacci.Draw(_drawing.PriceTrans, Env.Layout.ChartBodyRect, hdc);
  243. e.Graphics.ReleaseHdc(hdc);
  244. }
  245. //☆Fibonacci 追加ここまで
  246. }
  247. protected override void OnResize(EventArgs e)
  248. {
  249. base.OnResize(e);
  250. if (!this.DesignMode && _drawing != null && _brand != null && Env.Frame.WindowState != FormWindowState.Minimized)
  251. {
  252. bool last_is_visible = !_scrollBar.Enabled || _scrollBar.Value + _scrollBar.LargeChange >= _scrollBar.Maximum;
  253. _drawing.ClearScale();
  254. AdjustScrollBar();
  255. this.SuspendLayout();
  256. Preference pref = Env.Preference;
  257. //_oscillatorGroup.Top = this.BodyHeight - _oscillatorGroup.Height - 8;
  258. //_oscillatorGroup.Left = this.Width - Env.Layout.RemarkAreaWidth+5;
  259. if (!_brand.ReserveFarm().IsEmpty && last_is_visible)
  260. { //最新データ見えているときのリサイズはその状態を維持
  261. int v = _brand.ReserveFarm().TotalLength - Env.Layout.DisplayColumnCount;
  262. if (v < 0) v = 0;
  263. _scrollBar.Value = v; //このままValueChangedイベントも誘発
  264. }
  265. Invalidate(false);
  266. this.ResumeLayout();
  267. }
  268. }
  269. protected override void OnMouseMove(MouseEventArgs ev)
  270. {
  271. base.OnMouseMove(ev);
  272. if (_drawing == null) return;
  273. Preference pref = Env.Preference;
  274. //隠れてしまうIndicatorテキストの表示・非表示
  275. Point p = new Point(ev.X, ev.Y);//this.PointToClient(Control.MousePosition);
  276. if (_complementaryLabel != null && _complementaryLabel.Visible)
  277. {
  278. if (!new Rectangle(_complementaryLabel.Location, _complementaryLabel.Size).Contains(p))
  279. _complementaryLabel.Visible = false;
  280. }
  281. else
  282. {
  283. ArrayList ar = _drawing.TipEntries;
  284. if (ar != null)
  285. {
  286. foreach (ComplementaryTextEntry e in ar)
  287. {
  288. if (e.rect.Contains(p))
  289. {
  290. Label l = this.ComplementaryLabel;
  291. l.Location = new Point(e.rect.X - 2, e.rect.Y - 1);
  292. l.Size = new Size(e.rect.Size.Width + 5, e.rect.Size.Height + 2);
  293. l.Text = e.text;
  294. l.Visible = true;
  295. l.BringToFront();
  296. l.Invalidate();
  297. break;
  298. }
  299. }
  300. }
  301. }
  302. int offset = -1;
  303. if (p.X >= 0 && p.X < Env.Layout.ChartAreaWidth)
  304. {
  305. offset = (p.X - Env.Layout.CandleMiddleOffset) / Env.Layout.DatePitch;
  306. DataFarm farm = _brand.ReserveFarm();
  307. if (!farm.IsEmpty && _drawing.FirstDateIndex + offset >= farm.TotalLength) offset = -1;
  308. }
  309. //横線
  310. if (Env.Preference.MouseTrackingLineMode == MouseTrackingLineMode.Full)
  311. {
  312. int my = _drawing.NormalizeByYobine(ev.Y);
  313. if (my != _drawing.PriceLine._lastDrawn)
  314. {
  315. int h = Env.Layout.DefaultTextHeight;
  316. Rectangle yr = new Rectangle(0, _drawing.PriceLine._lastDrawn - h / 2, this.Width, h);
  317. Invalidate(yr, false);
  318. yr = new Rectangle(0, my - h / 2, this.Width, h);
  319. Invalidate(yr, false);
  320. }
  321. _drawing.PriceLine._nextToBeDrawn = my;
  322. }
  323. //必要なエリアのInvalidate
  324. int ld = _drawing.DateLine._lastDrawn;
  325. if (offset == -1)
  326. {
  327. if (ld != -1)
  328. {
  329. Rectangle r = Env.Layout.CurrentValueRect;
  330. Invalidate(r, false);
  331. int t = ld - _drawing.FirstDateIndex;
  332. r = new Rectangle((t - 1) * Env.Layout.DatePitch, 0, Env.Layout.DatePitch * 2, this.Height);
  333. Invalidate(r, false);
  334. }
  335. _drawing.UpdateDateLineIndex(-1);
  336. }
  337. else
  338. {
  339. if (_drawing.FirstDateIndex + offset != ld)
  340. {
  341. Rectangle r = Env.Layout.CurrentValueRect;
  342. //r.X += ChartDrawing.VALUEWINDOW_HEADER_WIDTH;
  343. Invalidate(r, false);
  344. //価格帯出来高
  345. if (Env.Preference.ShowAccumulativeVolume)
  346. Invalidate(Env.Layout.AccumulativeVolumeRect, false);
  347. //節の数値のこともあるので広めにInvalidateする
  348. if (ld != -1)
  349. {
  350. int t = ld - _drawing.FirstDateIndex;
  351. //Debug.WriteLine(String.Format("prev offset={0}", t));
  352. r = new Rectangle((t - 1) * Env.Layout.DatePitch, 0, Env.Layout.DatePitch * 2, this.Height);
  353. Invalidate(r, false);
  354. }
  355. r = new Rectangle((offset - 1) * Env.Layout.DatePitch, 0, Env.Layout.DatePitch * 2, this.Height);
  356. Invalidate(r, false);
  357. }
  358. _drawing.UpdateDateLineIndex(_drawing.FirstDateIndex + offset);
  359. }
  360. //☆Fibonacci
  361. if (_currentFibonacci != null && ev.Button == MouseButtons.Left && ((Control.ModifierKeys & Keys.Alt) == Keys.Alt))
  362. {
  363. Invalidate(_currentFibonacci.GetInclusion(this.ClientRectangle), false);
  364. _currentFibonacci.Destination = p;
  365. var h = Env.Layout.ChartAreaBottom - Env.Layout.OscillatorPaneHeightTotal - Env.Layout.VolumePaneHeight;
  366. var point = this.PointToScreen(new Point(this.Location.X, this.Location.Y + _title.Height));
  367. Rectangle r = new Rectangle(point.X, point.Y, Env.Layout.ChartAreaWidth, h);
  368. Cursor.Clip = r;
  369. }
  370. //今引いている直線の再描画
  371. else if (_currentFreeLine != null)
  372. {
  373. Invalidate(_currentFreeLine.GetInclusion(this.ClientRectangle), false);
  374. _currentFreeLine.Destination = p;
  375. }
  376. //左クリックしながら、マウスを動かした場合、コピー中と見なす。
  377. if (_diffX != 0 && _diffY != 0 && ev.Button == MouseButtons.Left && Win32.GetAsyncKeyState(System.Windows.Forms.Keys.ShiftKey) < 0 & 0x8000 != 0)
  378. {
  379. _currentFreeLine = new FreeLine(new Point(ev.X, ev.Y), new Point(ev.X - _diffX, ev.Y - _diffY));
  380. }
  381. //Controlキーを押しながら、マウスで左クリックしている時は、ピボット・コピー中と見なす。
  382. if (_diffX != 0 && _diffY != 0 && ev.Button == MouseButtons.Left && Win32.GetAsyncKeyState(System.Windows.Forms.Keys.ControlKey) < 0 & 0x8000 != 0)
  383. {
  384. int x, y = 0;
  385. if (_pivotX < _destX)//画面左から右へと引いたフリーライン
  386. {
  387. if ((_pivotX + _destX) / 2 > ev.X)//軸となる点は旧_dest
  388. {
  389. x = _destX;
  390. y = _destY;
  391. }
  392. else//軸となる点は旧_pivot
  393. {
  394. x = _pivotX;
  395. y = _pivotY;
  396. }
  397. }
  398. else//画面右から左へと引いたフリーライン
  399. {
  400. if ((_pivotX + _destX) / 2 > ev.X)//軸となる点は旧_pivot
  401. {
  402. x = _pivotX;
  403. y = _pivotY;
  404. }
  405. else//軸となる点は旧_dest
  406. {
  407. x = _destX;
  408. y = _destY;
  409. }
  410. }
  411. _currentFreeLine = new FreeLine(new Point(x, y), new Point(ev.X, ev.Y));
  412. }
  413. //接近した線があればそれをクリア
  414. bool near_line_found = false;
  415. foreach (FreeLine line in _drawing.FreeLines)
  416. {
  417. double d = line.GetDistance(p);
  418. FreeLine.LineDrawMode m = d < 3 ? FreeLine.LineDrawMode.Hilight : FreeLine.LineDrawMode.Normal;
  419. if (line.DrawMode != m)
  420. {
  421. line.DrawMode = m;
  422. Invalidate(line.GetInclusion(this.ClientRectangle), false);
  423. }
  424. if (!near_line_found) near_line_found = m == FreeLine.LineDrawMode.Hilight;
  425. }
  426. this.Cursor = near_line_found ? Cursors.Hand : Cursors.Default;
  427. //☆Fibonacci
  428. near_line_found = false;
  429. foreach (Fibonacci line in _drawing.Fibonaccies)
  430. {
  431. double distance = 5;
  432. double d = line.GetDistance(p);//☆Fibonacci 20180816 変更
  433. Fibonacci.LineDrawMode m = d < distance ? Fibonacci.LineDrawMode.Hilight : Fibonacci.LineDrawMode.Normal;
  434. if (line.DrawMode != m)
  435. {
  436. line.DrawMode = m;
  437. Invalidate(line.GetInclusion(this.ClientRectangle), false);
  438. }
  439. if (!near_line_found) near_line_found = m == Fibonacci.LineDrawMode.Hilight;
  440. }
  441. //this.Cursor = near_line_found ? Cursors.Hand : Cursors.Default;//☆Fibonacci 20180816 コメントアウト
  442. //☆Fibonacci 20180816 追加ここから
  443. if ((Control.ModifierKeys & Keys.Alt) == Keys.Alt && near_line_found)
  444. this.Cursor = Cursors.SizeNS;
  445. else if (near_line_found)
  446. this.Cursor = Cursors.Hand;
  447. else
  448. this.Cursor =Cursors.Default;
  449. //☆Fibonacci 20180816 追加ここまで
  450. //☆Fibonacci 追加ここまで
  451. }
  452. private void OnMouseUp(object sender, MouseEventArgs args)
  453. {
  454. Cursor.Clip = Rectangle.Empty;//☆Fibonacci
  455. if (args.Button == MouseButtons.Right)
  456. {
  457. ContextMenu m = Env.Frame.CreateContextMenu();
  458. m.Show(this, new Point(args.X, args.Y));
  459. }
  460. else if (args.Button == MouseButtons.Left)
  461. {
  462. if (_currentFreeLine != null)
  463. {
  464. if (_drawing.FreeLineCount == 10)
  465. {
  466. Util.Warning(Env.Frame, "線は1銘柄につき10本までしか引けません");
  467. Invalidate();
  468. }
  469. else if (Env.FreeLines.Count == 1000)
  470. {
  471. Util.Warning(Env.Frame, "線は全部で1000本までしか引けません");
  472. Invalidate();
  473. }
  474. else if (_currentFreeLine.PivotHasEnoughDistanceTo(_currentFreeLine.Destination))
  475. {
  476. _drawing.FixFreeLine(_currentFreeLine);
  477. }
  478. _currentFreeLine = null;
  479. }
  480. if (_drawing.RemoveHighlitedFreeLines()) Invalidate(); //削除されたやつがあればInvalidate
  481. //☆Fibonacci
  482. if (_currentFibonacci != null)
  483. {
  484. if (_drawing.FibonacciesCount == 10)
  485. {
  486. Util.Warning(Env.Frame, "線は1銘柄につき10本までしか引けません");
  487. Invalidate();
  488. }
  489. else if (Env.Fibonacci.Count == 1000)
  490. {
  491. Util.Warning(Env.Frame, "線は全部で1000本までしか引けません");
  492. Invalidate();
  493. }
  494. else if (_currentFibonacci.PivotHasEnoughDistanceTo(_currentFibonacci.Destination))
  495. {
  496. //クリックして選んだ2点の内側の最高値と最安値を取得
  497. _currentFibonacci.SetHighPriceAndLowPrice(_brand.ReserveFarm(), _drawing.PriceTrans, _currentFibonacci.Pivot.X, args.X, FirstDateIndex);
  498. _drawing.FixFibonacci(_currentFibonacci);
  499. }
  500. _currentFibonacci = null;
  501. this.Refresh();
  502. }
  503. if (_drawing.RemoveHighlitedFibonacci()) Invalidate(); //削除されたやつがあればInvalidate
  504. }
  505. }
  506. protected override bool IsInputChar(char charCode)
  507. {
  508. return false;
  509. }
  510. private void AdjustScrollBar()
  511. {
  512. if (_brand == null || _brand.ReserveFarm().IsEmpty)
  513. {
  514. _scrollBar.Enabled = false;
  515. }
  516. else
  517. {
  518. Preference pref = Env.Preference;
  519. int total = GetTotalDataLength();
  520. int display = Env.Layout.DisplayColumnCount;
  521. if (display >= total)
  522. {
  523. _scrollBar.Enabled = false;
  524. _scrollBar.Value = 0;
  525. _drawing.FirstDateIndex = 0;
  526. }
  527. else
  528. {
  529. int v = _scrollBar.Value;
  530. _scrollBar.LargeChange = display;
  531. _scrollBar.Maximum = total - 1;
  532. //Debug.WriteLine(String.Format("Adjusted disp={0} all={1} v={2}", display, all, v));
  533. if (v > _scrollBar.Maximum - display) _scrollBar.Value = _scrollBar.Maximum - display + 1;
  534. _scrollBar.Enabled = true;
  535. }
  536. }
  537. }
  538. private int GetTotalDataLength()
  539. {
  540. return _brand.ReserveFarm().TotalLength;
  541. }
  542. private void OnScrollBarValueChanged(object sender, EventArgs args)
  543. {
  544. if (this.DesignMode) return;
  545. int v = _scrollBar.Value;
  546. _drawing.FirstDateIndex = v;
  547. //Debug.WriteLine(String.Format("ValueChange max={0} lc={1} v={2}", _scrollBar.Maximum, _scrollBar.LargeChange, v));
  548. _drawing.ClearScale();
  549. Invalidate();
  550. }
  551. /*
  552. private void OnOscillatorGroupCheckedChanged(object sender, EventArgs args) {
  553. int i = _oscillatorGroupBoxes.IndexOf(sender);
  554. Debug.Assert(i!=-1);
  555. _drawing.OscillatorGroup = Env.CurrentIndicators.GetOscillatorGroupAt(i);
  556. Invalidate();
  557. }
  558. */
  559. //FreeLine関係
  560. private FreeLine _currentFreeLine;
  561. //☆Fibonacci
  562. private Fibonacci _currentFibonacci;
  563. protected override void OnMouseDown(MouseEventArgs e)
  564. {
  565. base.OnMouseDown(e);
  566. //☆Fibonacci 20180816 追加ここから
  567. //従来フィボナッチラインを延長
  568. if (e.Button == MouseButtons.Left && (Control.ModifierKeys & Keys.Alt) == Keys.Alt && this.Cursor == Cursors.SizeNS)
  569. {
  570. Point p = new Point(e.X, e.Y);
  571. foreach (Fibonacci line in _drawing.Fibonaccies)
  572. {
  573. double distance = 5;
  574. double d = line.GetDistance(p);
  575. if(line.GetDistanceUpside(p) < distance)//上のフィボナッチラインにマウスが近接 ≒ 上のラインを移動させる
  576. {
  577. if (line.Pivot.Y > line.Destination.Y)//下から上に引いたフィボナッチライン
  578. _currentFibonacci = new Fibonacci(line.Pivot, line.Destination);
  579. else
  580. _currentFibonacci = new Fibonacci(line.Destination, line.Pivot);
  581. _currentFibonacci.DrawMode = Fibonacci.LineDrawMode.Move;
  582. }
  583. else if (line.GetDistanceDownside(p) < distance)//下のフィボナッチラインにマウスが近接
  584. {
  585. if (line.Pivot.Y > line.Destination.Y)//下から上に引いたフィボナッチライン
  586. _currentFibonacci = new Fibonacci(line.Destination, line.Pivot);
  587. else
  588. _currentFibonacci = new Fibonacci(line.Pivot, line.Destination);
  589. _currentFibonacci.DrawMode = Fibonacci.LineDrawMode.Move;
  590. }
  591. }
  592. }//追加ここまで
  593. //フィボナッチラインを新規描画
  594. else if (e.Button == MouseButtons.Left && (Control.ModifierKeys & Keys.Alt) == Keys.Alt)//☆Fibonacci 20180816 if文をelse ifに
  595. {
  596. //_currentFibonacci = new Fibonacci(new Point(e.X, e.Y));//☆Fibonacci 20180816 コメントアウト
  597. _currentFibonacci = new Fibonacci(new PointF(e.X, e.Y));//☆Fibonacci 20180816
  598. }
  599. else if (e.Button == MouseButtons.Left)//☆Fibonacci if文をelse ifにする
  600. {
  601. if (_brand.ReserveFarm().IsEmpty) return;
  602. foreach (FreeLine line in _drawing.FreeLines)
  603. {
  604. if (line.DrawMode == FreeLine.LineDrawMode.Hilight && e.Button == MouseButtons.Left)
  605. {
  606. _diffX = line.Destination.X - line.Pivot.X;
  607. _diffY = line.Destination.Y - line.Pivot.Y;
  608. _destX = line.Destination.X;
  609. _destY = line.Destination.Y;
  610. _pivotX = line.Pivot.X;
  611. _pivotY = line.Pivot.Y;
  612. }
  613. }
  614. _currentFreeLine = new FreeLine(new Point(e.X, e.Y));
  615. }
  616. }
  617. protected override void OnDoubleClick(EventArgs e)
  618. {
  619. base.OnDoubleClick(e);
  620. var ev = (MouseEventArgs)e;
  621. _currentFreeLine = new FreeLine(new Point(0, ev.Y), new Point(ev.X, ev.Y));
  622. }
  623. public void ClearCurrentFreeLine()
  624. {
  625. if (_currentFreeLine != null)
  626. {
  627. Invalidate(_currentFreeLine.GetInclusion(Env.Layout.ChartBodyRect), false);
  628. _currentFreeLine = null;
  629. }
  630. }
  631. //DOJIMA用半日足修正
  632. #if DOJIMA
  633. protected override void OnDoubleClick(EventArgs e) {
  634. base.OnDoubleClick (e);
  635. if(Env.CurrentIndicators.Format!=ChartFormat.HalfDaily) return;
  636. int index = _drawing.DateLine._lastDrawn;
  637. DailyDataFarm f = _brand.ReserveFarm() as DailyDataFarm;
  638. if(index<0 || index>=f.FilledLength) return;
  639. Dojima.ModifyHalfDayData dlg = new Dojima.ModifyHalfDayData();
  640. dlg.InitUI(f.GetByIndex(index), Dojima.DojimaUtil.HalfDailyDataFarmCache.Get(f), index);
  641. if(dlg.ShowDialog(Env.Frame)==DialogResult.OK) {
  642. Invalidate(true); //全画面再描画
  643. }
  644. }
  645. #endif
  646. }
  647. }
ダウンロード 印刷用表示

このコピペの URL

JavaScript での埋め込み

iframe での埋め込み

元のテキスト