-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPanel.java
More file actions
213 lines (131 loc) · 5.6 KB
/
Panel.java
File metadata and controls
213 lines (131 loc) · 5.6 KB
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
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JPanel;
import javax.swing.Timer;
import java.awt.event.*;
import java.awt.Graphics;
import java.awt.MouseInfo;
import java.util.ArrayList;
import java.awt.Image;
import javax.imageio.ImageIO;
import java.io.File;
import java.io.IOException;
import java.awt.Point;
import java.awt.Color;
import java.awt.Font;
public class Panel extends JPanel implements ActionListener, MouseListener
{
Timer t;
JLabel status;
JTextField pfSearch;
ArrayList<ContentTile> content = new ArrayList<ContentTile>();
Point[] mousePos = new Point[2];
Image pfp;
boolean mousePressed = false;
double camX = 0, camY = 0, camXVel = 0, camYVel = 0;
int TILESIZE = 125, SCREENWIDTH = 1920, SCREENHEIGHT = 1080;
public Panel()
{
Timer t = new Timer(16, this);
status = new JLabel("this is a test");
pfSearch = new JTextField("Search ");
add(pfSearch);
setFocusable(true);
addMouseListener(this);
setBackground(new Color(0x546E81));
try{
pfp = ImageIO.read(new File("./Resources/pfp.jpg"));
}
catch(IOException ioe)
{
System.out.println("cannot read pfp");
}
for(int i = 0; i < mousePos.length; i++)
mousePos[i] = MouseInfo.getPointerInfo().getLocation();
//content.add(new ContentTile((int) (((SCREENWIDTH / 2.0) - (((TILESIZE + 10) * 10 - 10)/ 2.0))), 0, "./Resources/Dog.png"));
for(int i = 0; i < 10; i++)
{
for(int j = 0; j < 10; j++)
{
content.add(new ContentTile((int) (((SCREENWIDTH / 2.0) - (((TILESIZE + 10) * 10 - 10)/ 2.0)) + i * (TILESIZE + 10)), j * (TILESIZE + 10), "./Resources/" +((int) (Math.random() * 24))+ ".jpg"));
}
}
t.start();
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
g.setColor(new Color(0xBED1DF));
g.fillRect(SCREENWIDTH / 2 - 450, 0, 900, SCREENHEIGHT);
g.drawImage(pfp, 105, 105, 300, 300, null);
g.setColor(Color.BLACK);
g.drawOval(105, 105, 300, 300);
g.setColor(Color.WHITE);
g.drawOval(104, 104, 302, 302);
g.setFont(new Font("TimesRoman", Font.PLAIN, 32));
g.drawString("First Last", 255 - (int) (g.getFontMetrics().stringWidth("First Last") / 2.0), 450);
g.setColor(Color.GRAY);
g.setFont(new Font("TimesRoman", Font.PLAIN, 20));
g.drawString("@username", 255 - (int) (g.getFontMetrics().stringWidth("@username") / 2.0), 480);
g.setColor(Color.WHITE);
g.drawString("Followers ___ | Following ___", 255 - (int) (g.getFontMetrics().stringWidth("Followers xxx | Following xxx") / 2.0), 520);
for(ContentTile ct: content)
{
double adjustedX = (((ct.x + camX) < 0 ? ((TILESIZE + 10) * 10) + ((ct.x + camX) % ((TILESIZE + 10) * 10)) : (ct.x + camX)) % ((TILESIZE + 10) * 10)) + 400, adjustedY = (((ct.y + camY) < 0 ? ((TILESIZE + 10) * 10) + ((ct.y + camY) % ((TILESIZE + 10) * 10)) : (ct.y + camY)) % ((TILESIZE + 10) * 10));
//double scale = 1 / (Math.min(Math.sqrt(Math.pow(adjustedX - 960, 2) + Math.pow(adjustedY - 540, 2)), 500) - 500) + 1;
//double scale = 1 - (Math.sqrt(Math.pow(adjustedX - 960, 2) + Math.pow(adjustedY - 540, 2)) / 500);
double scale = 1 - (Math.pow(1.012, Math.sqrt(Math.pow(adjustedX - 960, 2) + Math.pow(adjustedY - 540, 2))) / 200.0);
//scale = 1;
if(scale >= .01)
{
g.setColor(ct.color);
g.fillRect((int) (adjustedX - (TILESIZE * scale / 2.0)), (int) (adjustedY - (TILESIZE * scale / 2.0)), (int) (TILESIZE * scale), (int) (TILESIZE * scale));
if(ct.image != null)
{
g.drawImage(ct.image, (int) (adjustedX - (TILESIZE * scale / 2.0)), (int) (adjustedY - (TILESIZE * scale / 2.0)), (int) (TILESIZE * scale), (int) (TILESIZE * scale), null);
}
g.setColor(Color.BLACK);
g.drawRect((int) (adjustedX - (TILESIZE * scale / 2.0)), (int) (adjustedY - (TILESIZE * scale / 2.0)), (int) (TILESIZE * scale), (int) (TILESIZE * scale));
g.setColor(Color.WHITE);
g.drawRect((int) (adjustedX - (TILESIZE * scale / 2.0)) - 1, (int) (adjustedY - (TILESIZE * scale / 2.0)) - 1, (int) (TILESIZE * scale) + 2, (int) (TILESIZE * scale) + 2);
}
}
}
public void actionPerformed(ActionEvent ae)
{
for(int i = mousePos.length - 1; i > 0; i--)
mousePos[i] = mousePos[i - 1];
mousePos[0] = MouseInfo.getPointerInfo().getLocation();
if(mousePressed)
{
camX += mousePos[0].x - mousePos[1].x;
camY += mousePos[0].y - mousePos[1].y;
}
camX += camXVel;
camY += camYVel;
camXVel *= .95;
camYVel *= .95;
repaint();
}
public void mouseClicked(MouseEvent e)
{
}
public void mouseEntered(MouseEvent e)
{
}
public void mouseExited(MouseEvent e)
{
}
public void mousePressed(MouseEvent e)
{
mousePressed = true;
camXVel = 0;
camYVel = 0;
}
public void mouseReleased(MouseEvent e)
{
mousePressed = false;
camXVel = (mousePos[0].x - mousePos[mousePos.length - 1].x) / 2.0;
camYVel = (mousePos[0].y - mousePos[mousePos.length - 1].y) / 2.0;
}
}