Skip to content

Commit 772be3e

Browse files
committed
click/drag axis zoom started
1 parent 742874c commit 772be3e

File tree

3 files changed

+143
-6
lines changed

3 files changed

+143
-6
lines changed

projects/18-01-15_form_drawing/drawing/drawing/Form1.Designer.cs

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

projects/18-01-15_form_drawing/drawing/drawing/Form1.cs

Lines changed: 111 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,18 @@ public partial class Form1 : Form
1818

1919
public Form1()
2020
{
21+
2122
InitializeComponent();
22-
23+
24+
// prevent mouseover events until it's fully loaded
25+
panel1.Visible = false;
26+
pic_selection.Visible = false;
27+
28+
// last minute GUI customizations
29+
pic_selection.BackColor = Color.FromArgb(100, 255, 0, 0);
30+
2331
// doing this reduced panel flickering by double buffering
32+
// TIP: pictureboxes are double-buffered already
2433
typeof(Panel).InvokeMember("DoubleBuffered", System.Reflection.BindingFlags.SetProperty | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic, null, panel1, new object[] { true });
2534

2635
}
@@ -30,6 +39,7 @@ private void timer_init_Tick(object sender, EventArgs e)
3039
timer_init.Enabled = false;
3140
scottPlot = new ScottPlot(panel1.Width, panel1.Height);
3241
layout(null, null);
42+
panel1.Visible = true;
3343
}
3444

3545
/// <summary>
@@ -179,5 +189,105 @@ private void Focus_Reset(object sender, MouseEventArgs e)
179189
{
180190
button1.Focus();
181191
}
192+
193+
194+
/*
195+
*
196+
* MOUSE TRACKING
197+
*
198+
*
199+
*/
200+
201+
private Point Mouse_down_point;
202+
private Point Mouse_up_point;
203+
204+
private Rectangle Mouse_rectangle(Point p1, Point p2)
205+
{
206+
int X1 = Math.Min(p1.X, p2.X);
207+
int X2 = Math.Max(p1.X, p2.X);
208+
int Y1 = Math.Min(p1.Y, p2.Y);
209+
int Y2 = Math.Max(p1.Y, p2.Y);
210+
211+
Rectangle rect = new Rectangle(X1, Y1, X2-X1, Y2-Y1);
212+
return rect;
213+
}
214+
215+
private bool Mouse_in_zoom_horizontal(Point pt)
216+
{
217+
if (pt.X >= scottPlot.data_pos_left &&
218+
pt.X <= scottPlot.data_pos_right &&
219+
pt.Y >= scottPlot.data_pos_bottom &&
220+
pt.Y <= scottPlot.data_pos_bottom + 30)
221+
{
222+
return true;
223+
} else {
224+
return false;
225+
}
226+
}
227+
228+
private bool Mouse_in_zoom_vertical(Point pt)
229+
{
230+
if (pt.X >= scottPlot.data_pos_left - 30 &&
231+
pt.X <= scottPlot.data_pos_left &&
232+
pt.Y >= scottPlot.data_pos_top &&
233+
pt.Y <= scottPlot.data_pos_bottom)
234+
{
235+
return true;
236+
}
237+
else
238+
{
239+
return false;
240+
}
241+
}
242+
243+
private void panel1_MouseMove(object sender, MouseEventArgs e)
244+
{
245+
// rubber band rectangle
246+
if (System.Windows.Forms.Control.MouseButtons == MouseButtons.Left)
247+
{
248+
249+
Rectangle mouseRect = Mouse_rectangle(Mouse_down_point, e.Location);
250+
251+
if (Mouse_in_zoom_horizontal(Mouse_down_point))
252+
{
253+
panel1.Cursor = Cursors.NoMoveHoriz;
254+
int x1 = mouseRect.X;
255+
int x2 = mouseRect.X + mouseRect.Width;
256+
int y1 = scottPlot.data_pos_bottom;
257+
int y2 = scottPlot.data_pos_bottom + 7;
258+
pic_selection.Location = new Point(x1, y1);
259+
pic_selection.Size = new Size(x2 - x1, y2 - y1);
260+
}
261+
else if (Mouse_in_zoom_vertical(Mouse_down_point))
262+
{
263+
panel1.Cursor = Cursors.NoMoveVert;
264+
int x1 = scottPlot.data_pos_left - 7;
265+
int x2 = scottPlot.data_pos_left;
266+
int y1 = mouseRect.Y;
267+
int y2 = mouseRect.Y + mouseRect.Height;
268+
pic_selection.Location = new Point(x1, y1);
269+
pic_selection.Size = new Size(x2 - x1, y2 - y1);
270+
}
271+
} else
272+
{
273+
// left button is not pressed
274+
if (Mouse_in_zoom_horizontal(e.Location)) panel1.Cursor = Cursors.NoMoveHoriz;
275+
else if (Mouse_in_zoom_vertical(e.Location)) panel1.Cursor = Cursors.NoMoveVert;
276+
else panel1.Cursor = Cursors.Arrow;
277+
}
278+
}
279+
280+
281+
private void panel1_MouseDown(object sender, MouseEventArgs e)
282+
{
283+
Mouse_down_point = new Point(e.X, e.Y);
284+
pic_selection.Visible = true;
285+
}
286+
287+
private void panel1_MouseUp(object sender, MouseEventArgs e)
288+
{
289+
Mouse_up_point = new Point(e.X, e.Y);
290+
pic_selection.Visible = false;
291+
}
182292
}
183293
}

projects/18-01-15_form_drawing/drawing/drawing/ScottPlot.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ class ScottPlot
3232
private int data_pad_right;
3333
private int data_pad_bottom;
3434

35-
private int data_pos_left;
36-
private int data_pos_right;
37-
private int data_pos_top;
38-
private int data_pos_bottom;
35+
public int data_pos_left;
36+
public int data_pos_right;
37+
public int data_pos_top;
38+
public int data_pos_bottom;
3939

4040
private int data_width;
4141
private int data_height;
@@ -341,7 +341,16 @@ public Bitmap Render()
341341
return this.bitmap;
342342

343343
}
344-
344+
345+
/// <summary>
346+
/// return the bitmap we last rendered
347+
/// </summary>
348+
/// <returns></returns>
349+
public Bitmap RenderedLast()
350+
{
351+
return this.bitmap;
352+
}
353+
345354
/// <summary>
346355
/// format a number for a tick label by limiting its precision. axisSpan is X2-X1.
347356
/// </summary>

0 commit comments

Comments
 (0)