Description:
Refactor out magic variable.
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
@@ -18,7 +18,8 | |||||
|
18 | private MouseState mousePrev; |
|
18 | private MouseState mousePrev; |
|
19 |
|
19 | ||
|
20 | private static int bar_height = 25; |
|
20 | private static int bar_height = 25; |
|
21 |
|
21 | private static int height = 500; | |
|
|
22 | private static int width = 700; | ||
|
22 |
|
23 | ||
|
23 | public BudgetWindow(Budget budget, SpriteFont font, int start_x, int start_y) |
|
24 | public BudgetWindow(Budget budget, SpriteFont font, int start_x, int start_y) |
|
24 | { |
|
25 | { |
@@ -34,7 +35,7 | |||||
|
34 | this.budget = budget; |
|
35 | this.budget = budget; |
|
35 |
|
36 | ||
|
36 | if ((mouseCur.LeftButton == ButtonState.Pressed) |
|
37 | if ((mouseCur.LeftButton == ButtonState.Pressed) |
|
37 |
&& MathUtils.Between(mouseCur.X, |
|
38 | && MathUtils.Between(mouseCur.X, width+x-20, width+x) |
|
38 | && MathUtils.Between(mouseCur.Y, y+bar_height, y+bar_height+20) |
|
39 | && MathUtils.Between(mouseCur.Y, y+bar_height, y+bar_height+20) |
|
39 | ) { |
|
40 | ) { |
|
40 |
|
41 | ||
@@ -42,7 +43,7 | |||||
|
42 |
|
43 | ||
|
43 | } |
|
44 | } |
|
44 | else if ((mouseCur.LeftButton == ButtonState.Pressed) |
|
45 | else if ((mouseCur.LeftButton == ButtonState.Pressed) |
|
45 |
&& MathUtils.Between(mouseCur.X, x, |
|
46 | && MathUtils.Between(mouseCur.X, x, width+x) |
|
46 | && MathUtils.Between(mouseCur.Y, y, 500 + y)) |
|
47 | && MathUtils.Between(mouseCur.Y, y, 500 + y)) |
|
47 | { |
|
48 | { |
|
48 | if (mousePrev.LeftButton == ButtonState.Released) |
|
49 | if (mousePrev.LeftButton == ButtonState.Released) |
@@ -53,7 +54,7 | |||||
|
53 | else |
|
54 | else |
|
54 | { |
|
55 | { |
|
55 | this.mouseEnd = new Vector2(mouseCur.X, mouseCur.Y); |
|
56 | this.mouseEnd = new Vector2(mouseCur.X, mouseCur.Y); |
|
56 |
this.x = MathUtils.Clamp(this.x + (int)(this.mouseEnd.X - this.mouseStart.X), 0, |
|
57 | this.x = MathUtils.Clamp(this.x + (int)(this.mouseEnd.X - this.mouseStart.X), 0, width); |
|
57 | this.y = MathUtils.Clamp(this.y + (int)(this.mouseEnd.Y - this.mouseStart.Y), 0, 400); |
|
58 | this.y = MathUtils.Clamp(this.y + (int)(this.mouseEnd.Y - this.mouseStart.Y), 0, 400); |
|
58 | } |
|
59 | } |
|
59 | } |
|
60 | } |
@@ -62,27 +63,23 | |||||
|
62 |
|
63 | ||
|
63 | this.mousePrev = mouseCur; |
|
64 | this.mousePrev = mouseCur; |
|
64 |
|
65 | ||
|
65 | // Console.Write(mouseCur.ToString()); |
|
||
|
66 |
|
|||
|
67 | return true; |
|
66 | return true; |
|
68 |
|
|||
|
69 | } |
|
67 | } |
|
70 |
|
68 | ||
|
71 | public void draw(SpriteBatch batch) |
|
69 | public void draw(SpriteBatch batch) |
|
72 | { |
|
70 | { |
|
73 |
|
71 | ||
|
74 |
|
72 | ||
|
75 | int height = 500; |
|
||
|
76 |
|
73 | ||
|
77 | FilledRectangle.drawFilledRectangle(batch, new Rectangle(x - 20, y+bar_height, 20, height), Color.White); |
|
74 | FilledRectangle.drawFilledRectangle(batch, new Rectangle(x - 20, y+bar_height, 20, height), Color.White); |
|
78 | Line.drawLine(batch, new Vector2(x, y + bar_height), new Vector2(x, y + bar_height + height), Color.Gray); |
|
75 | Line.drawLine(batch, new Vector2(x, y + bar_height), new Vector2(x, y + bar_height + height), Color.Gray); |
|
79 |
FilledRectangle.drawFilledRectangle(batch, new Rectangle(x + |
|
76 | FilledRectangle.drawFilledRectangle(batch, new Rectangle(x + width, y+bar_height, 20, height), Color.White); |
|
80 |
Line.drawLine(batch, new Vector2(x + |
|
77 | Line.drawLine(batch, new Vector2(x + width, y + bar_height), new Vector2(x + width, y + bar_height + height), Color.Gray); |
|
81 |
|
78 | ||
|
82 | for (int i = 1; i <= (height / bar_height); i++) |
|
79 | for (int i = 1; i <= (height / bar_height); i++) |
|
83 | { |
|
80 | { |
|
84 | Rectangle position = new Rectangle(this.x, bar_height * i + this.y, |
|
81 | Rectangle position = new Rectangle(this.x, bar_height * i + this.y, |
|
85 |
|
|
82 | width, bar_height); |
|
86 |
|
83 | ||
|
87 | if ((i % 2) == 0) |
|
84 | if ((i % 2) == 0) |
|
88 | { |
|
85 | { |
@@ -94,9 +91,9 | |||||
|
94 | } |
|
91 | } |
|
95 | } |
|
92 | } |
|
96 |
|
93 | ||
|
97 |
FilledRectangle.drawFilledRectangle(batch, new Rectangle(x + |
|
94 | FilledRectangle.drawFilledRectangle(batch, new Rectangle(x + width - 20, y+bar_height, 20, 20), Color.LightGray); |
|
98 | Vector2 dimensions = font.MeasureString("X"); |
|
95 | Vector2 dimensions = font.MeasureString("X"); |
|
99 |
batch.DrawString(font, "X", new Vector2(x+ |
|
96 | batch.DrawString(font, "X", new Vector2(x+width -20 + (dimensions.X/2), y+bar_height), Color.Black); |
|
100 |
|
97 | ||
|
101 | batch.DrawString(font, String.Format("BUDGET REPORT FOR {0:MMMMM yyyy}", this.budget.DateTime), new Vector2(x, bar_height * 1 + y), Color.Black); |
|
98 | batch.DrawString(font, String.Format("BUDGET REPORT FOR {0:MMMMM yyyy}", this.budget.DateTime), new Vector2(x, bar_height * 1 + y), Color.Black); |
|
102 |
|
99 |
You need to be logged in to leave comments.
Login now