gdx-studio

#libgdx#java#desktop

git clone https://git.pyrossh.dev/gdx-studio

An IDE for creating Games using libgdx and Java supported on all platforms Android, iOS, Desktop


src/gdxstudio/Style.java
a9b2a64 1
package gdxstudio;
a62d533 2
import java.awt.Color;
a62d533 3
import java.awt.FlowLayout;
a62d533 4
import java.awt.GradientPaint;
a62d533 5
import java.awt.Graphics;
a62d533 6
import java.awt.Graphics2D;
a62d533 7
import java.awt.Rectangle;
a62d533 8
import java.awt.event.ActionEvent;
a62d533 9
import java.awt.event.ActionListener;
a62d533 10
import java.util.ArrayList;
a62d533 11
import java.util.HashMap;
a62d533 12
a62d533 13
import javax.swing.JButton;
a62d533 14
import javax.swing.JLabel;
a62d533 15
import javax.swing.JPanel;
a62d533 16
a62d533 17
import web.laf.lite.layout.ToolbarLayout;
a62d533 18
import web.laf.lite.layout.VerticalFlowLayout;
a62d533 19
import web.laf.lite.utils.ColorUtils;
a62d533 20
import web.laf.lite.utils.UIUtils;
a62d533 21
a62d533 22
public enum Style {
7c84877 23
	BLUE, DARK;
7c84877 24
	private static Style currentStyle = Style.BLUE;
7c84877 25
	public static Color topColor;
7c84877 26
	public static Color botColor;
7c84877 27
	public static Color headerTopLine;
7c84877 28
	public static Color headerBg;
7c84877 29
	public static Color headerBgBot;
7c84877 30
	public static Color headerFg;
7c84877 31
	public static Color border;
7c84877 32
	public static Color focus;
7c84877 33
	public static Color font;
7c84877 34
	public static Color listBg;
7c84877 35
	public static Color listSelect;
7c84877 36
7c84877 37
	public static Color topLineColor = new Color(0x4580c8);
7c84877 38
	public static Color bottomColor = new Color(0x1956ad);
7c84877 39
7c84877 40
	private static HashMap<Style, ArrayList<Color>> stylesMap = new HashMap<Style, ArrayList<Color>>();
7c84877 41
	/* top, bot, headerTopline, headerBg, headerBgBot, headerFg, border, focus, font, listBg, listSelect*/
7c84877 42
	private static String blueColors = "e4e4e4,d1d1d1,e8eaeb,2a3b57,1a2b47,ffffff,"
7c84877 43
			+ "808080,ef8e39,000000,ffffff,000080";
7c84877 44
	private static String darkColors = "213134,272b2f,6C788C,20272a,0b0e20,93c705,"
7c84877 45
			+ "404040,ef8e39,e4e0e2,272b2f,000080";
7c84877 46
	static {
7c84877 47
		stylesMap.put(Style.BLUE, getColor(blueColors));
7c84877 48
		stylesMap.put(Style.DARK, getColor(darkColors));
7c84877 49
		setStyle(Style.BLUE);
7c84877 50
	}
7c84877 51
7c84877 52
	public static void setStyle(Style style){
7c84877 53
		currentStyle = style;
7c84877 54
		topColor = stylesMap.get(currentStyle).get(0);
7c84877 55
		botColor = stylesMap.get(currentStyle).get(1);
7c84877 56
		headerTopLine = stylesMap.get(currentStyle).get(2);
7c84877 57
		headerBg = stylesMap.get(currentStyle).get(3);
7c84877 58
		headerBgBot = stylesMap.get(currentStyle).get(4);
7c84877 59
		headerFg = stylesMap.get(currentStyle).get(5);
7c84877 60
		border = stylesMap.get(currentStyle).get(6);
7c84877 61
		focus = stylesMap.get(currentStyle).get(7);
7c84877 62
		font = stylesMap.get(currentStyle).get(8);
7c84877 63
		listBg = stylesMap.get(currentStyle).get(9);
7c84877 64
		listSelect = stylesMap.get(currentStyle).get(10);
7c84877 65
	}
7c84877 66
7c84877 67
	private static ArrayList<Color> getColor(String colorsString){
7c84877 68
		ArrayList<Color> listColor = new ArrayList<Color>();
7c84877 69
		for(String c: colorsString.split(","))
7c84877 70
			listColor.add(ColorUtils.parseHexColor(c));
7c84877 71
		return listColor;
7c84877 72
	}
7c84877 73
7c84877 74
	public static Color canvasBg = new Color(108, 108, 108);
7c84877 75
	public static Color canvasScreen = new Color(28, 28, 28);
7c84877 76
	public static Color canvasShadowTop = new Color(108, 108, 108);
7c84877 77
	public static Color canvasShadowBot = new Color(155, 155, 155);
7c84877 78
	public static Color canvasBox = new Color(83, 82, 82);
7c84877 79
7c84877 80
	private static Color scrollBg = new Color ( 245, 245, 245 );
7c84877 81
	private static Color scrollBorder = new Color ( 230, 230, 230 );
a62d533 82
7c84877 83
	private static Color scrollBarBorder = new Color ( 201, 201, 201 );
7c84877 84
	private static Color scrollGradientLeft = new Color ( 239, 239, 239 );
7c84877 85
	private static Color scrollSelGradientLeft = new Color ( 203, 203, 203 ); //33
7c84877 86
	private static Color scrollGradientRight = new Color ( 211, 211, 211 );        
7c84877 87
	private static Color scrollSelGradientRight = new Color ( 175, 175, 175 );//-45
a62d533 88
7c84877 89
	public static HashMap<String, JButton> btnMap = new HashMap<String, JButton>();
7c84877 90
	public static ArrayList<JButton> viewGroup = new ArrayList<JButton>();
7c84877 91
	private static GradientPaint headerBgPaint;
a62d533 92
7c84877 93
	private static final int margin = 15;
a9b2a64 94
	private static int screenX = 0;
a9b2a64 95
	private static int screenY = 0;
a9b2a64 96
	private static int screenW = 0;
a9b2a64 97
	private static int screenH = 0;
a9b2a64 98
	
a9b2a64 99
	public static void setScreenPosition(int x, int y){
a9b2a64 100
		screenX = x - 5;
a9b2a64 101
		screenY = y + 5;
a9b2a64 102
	}
a9b2a64 103
	
a9b2a64 104
	public static void setScreenSize(int width, int height){
a9b2a64 105
		screenW = width + 40;
a9b2a64 106
		screenH = height + 25;
a9b2a64 107
	}
a62d533 108
a9b2a64 109
	public static void drawScreen(Graphics g, int width, int height){
7c84877 110
		g.setColor(Style.canvasBg);
7c84877 111
		g.fillRect(0, 0, width, height); //bg
7c84877 112
		g.setColor(Color.black);
a9b2a64 113
		g.fillRoundRect(screenX, screenY, screenW, screenH, 10, 10);
7c84877 114
		g.setColor(Style.canvasShadowBot);
a9b2a64 115
		g.drawLine(screenX+5, screenY+screenH, screenX+screenW-5, screenY+screenH);//hoz shadow y same
a9b2a64 116
		g.drawLine(screenX+screenW, screenY+5, screenX+screenW, screenY+screenH-5);// vert shadow x same
7c84877 117
		g.setColor(Style.canvasBox);
a9b2a64 118
		g.fillRect(0, screenH+3*margin, width, 2);
a9b2a64 119
		g.fillRect(0, screenH+3*margin+3, width, height-screenH+3*margin-3);
7c84877 120
	}
7c84877 121
7c84877 122
	public static Color tableHeaderTopLineColor = new Color ( 232, 234, 235 );
7c84877 123
	public static Color tableHeaderTopBgColor = new Color ( 226, 226, 226 );
7c84877 124
	public static Color tableHeaderBotBgColor = new Color ( 201, 201, 201 );
7c84877 125
	public static Color tableHeaderBotLineColor = new Color ( 104, 104, 104 );
7c84877 126
	public static void drawTableHeader(Graphics g, int width, int height){
7c84877 127
		Graphics2D g2d = ( Graphics2D ) g;
7c84877 128
		// Table header background
7c84877 129
		GradientPaint bgPaint = new GradientPaint (0, 1, topColor, 0, height - 1, botColor);
7c84877 130
		g2d.setPaint(bgPaint);
7c84877 131
		g2d.fillRect(0, 1, width, height - 1);
7c84877 132
7c84877 133
		// Header top and bottom lines
7c84877 134
		//g2d.setColor(headerTopLine);
a62d533 135
		// g2d.drawLine( 0, 0, width, 0);
7c84877 136
	}
7c84877 137
7c84877 138
	final public static void drawHorizontalBar(Graphics g, int width, int height){
7c84877 139
		Graphics2D g2d = ( Graphics2D ) g;
7c84877 140
		GradientPaint paint = new GradientPaint(0, 1, Style.topColor, 0, height, Style.botColor);
7c84877 141
		g2d.setPaint(paint);
7c84877 142
		g2d.fillRect(0, 0, width, height);
7c84877 143
	}
a62d533 144
7c84877 145
	final public static void drawVerticalScrollTrack( Graphics g, Rectangle thumbRect, int width,int height,
7c84877 146
			boolean drawBorder ){
7c84877 147
		if (drawBorder){
7c84877 148
			Graphics2D g2d = ( Graphics2D ) g;
7c84877 149
			g2d.setPaint ( scrollBg );
7c84877 150
			g2d.fillRect ( 0, 0, width, height );
7c84877 151
			int vBorder = width - 1; //maybe 0
7c84877 152
			g2d.setColor ( scrollBorder );
7c84877 153
			g2d.drawLine ( vBorder, 0, vBorder, height - 1 );
7c84877 154
		}
7c84877 155
	}
a62d533 156
7c84877 157
	final public static void drawHorizontalScrollTrack( Graphics g, Rectangle thumbRect, int width,int height,
7c84877 158
			boolean drawBorder ){
7c84877 159
		if (drawBorder){
7c84877 160
			Graphics2D g2d = ( Graphics2D ) g;
7c84877 161
			g2d.setPaint ( scrollBg );
7c84877 162
			g2d.fillRect ( 0, 0, width, height );
7c84877 163
			g2d.setColor ( scrollBorder );
7c84877 164
			g2d.drawLine ( 0, 0, width, 0 );
7c84877 165
		}
7c84877 166
	}
a62d533 167
7c84877 168
	final public static void drawVerticalScrollBar( Graphics g, Rectangle thumbRect, int width, boolean isDragging){
7c84877 169
		Graphics2D g2d = ( Graphics2D ) g;
7c84877 170
		Color leftColor = isDragging ? scrollSelGradientLeft : scrollGradientLeft;
7c84877 171
		Color rightColor = isDragging ? scrollSelGradientRight : scrollGradientRight;
7c84877 172
		g2d.setPaint ( new GradientPaint ( 3, 0, leftColor, width - 4, 0, rightColor ) );
7c84877 173
		g2d.fillRoundRect ( thumbRect.x + 2, thumbRect.y + 1, thumbRect.width - 4, thumbRect.height - 3, 0, 0);
7c84877 174
		g2d.setPaint ( scrollBarBorder );
7c84877 175
		g2d.drawRoundRect ( thumbRect.x + 2, thumbRect.y + 1, thumbRect.width - 4, thumbRect.height - 3, 0, 0);
7c84877 176
	}
7c84877 177
7c84877 178
	final public static void drawHorizontalScrollBar( Graphics g, Rectangle thumbRect, int width, boolean isDragging){
7c84877 179
		Graphics2D g2d = ( Graphics2D ) g;
7c84877 180
		Color leftColor = isDragging ? scrollSelGradientLeft : scrollGradientLeft;
7c84877 181
		Color rightColor = isDragging ? scrollSelGradientRight : scrollGradientRight;
7c84877 182
		g2d.setPaint ( new GradientPaint ( 0, thumbRect.y + 2, leftColor, 0, thumbRect.y + 2 + thumbRect.height - 4, rightColor ) );
7c84877 183
		g2d.fillRoundRect ( thumbRect.x + 1, thumbRect.y + 2, thumbRect.width - 3, thumbRect.height - 4, 0, 0);
7c84877 184
		g2d.setPaint ( scrollBarBorder );
7c84877 185
		g2d.drawRoundRect ( thumbRect.x + 1, thumbRect.y + 2, thumbRect.width - 3, thumbRect.height - 4, 0, 0);
7c84877 186
	}
7c84877 187
7c84877 188
	public static class TitleLabel extends JLabel {
7c84877 189
		private static final long serialVersionUID = 1L;
7c84877 190
		public TitleLabel(String text){
7c84877 191
			setText(text);
7c84877 192
			UIUtils.setBoldFont(this);
7c84877 193
			setVerticalTextPosition(JLabel.CENTER);
7c84877 194
			setHorizontalTextPosition(JLabel.CENTER);
7c84877 195
			setHorizontalAlignment(JLabel.CENTER);
7c84877 196
			setForeground(Style.headerFg);
7c84877 197
		}
a9b2a64 198
		public TitleLabel(String text, String icon){
a9b2a64 199
			this(text);
a9b2a64 200
			setIcon(Icon.icon(icon));
a9b2a64 201
			setHorizontalTextPosition(JLabel.RIGHT);
a9b2a64 202
		}
7c84877 203
		@Override
7c84877 204
		public void setText(String text){
7c84877 205
			super.setText(text.toUpperCase());
7c84877 206
		}
7c84877 207
		@Override
7c84877 208
		public void paint ( Graphics g){
7c84877 209
			Graphics2D g2d = ( Graphics2D ) g;
7c84877 210
			if(headerBgPaint == null)
7c84877 211
				headerBgPaint = new GradientPaint ( 0, 1, Style.headerBg, 
7c84877 212
						0, getHeight()-1, Style.headerBgBot);
7c84877 213
			g2d.setPaint ( headerBgPaint );
7c84877 214
			g2d.fillRect ( 0, 1, getWidth(), getHeight() - 1 );
7c84877 215
			g2d.setColor ( Style.headerTopLine);
7c84877 216
			g2d.drawLine ( 0, 0, getWidth (), 0 );
7c84877 217
			super.paint(g);
7c84877 218
		}
7c84877 219
	}
7c84877 220
7c84877 221
	public static class TitleButton extends JButton {
7c84877 222
		private static final long serialVersionUID = 1L;
7c84877 223
		public TitleButton(String text, ActionListener al){
7c84877 224
			setText(text);
7c84877 225
			//btn.setOpaque(true);
7c84877 226
			//btn.setBackground(headerBg);
7c84877 227
			setForeground(Style.headerFg);
7c84877 228
			UIUtils.setBoldFont(this);
7c84877 229
			UIUtils.setRolloverDecoratedOnly(this,true);
7c84877 230
			UIUtils.setLeftRightSpacing(this, 4);
7c84877 231
			UIUtils.setRound(this, 0);
7c84877 232
			UIUtils.setUndecorated(this, true);
7c84877 233
			UIUtils.setShadeWidth(this, 2);
7c84877 234
			setVerticalTextPosition(JLabel.CENTER);
7c84877 235
			setHorizontalTextPosition(JLabel.CENTER);
7c84877 236
			setHorizontalAlignment(JLabel.CENTER);
7c84877 237
			if(al != null)
7c84877 238
				addActionListener(al);
7c84877 239
		}
7c84877 240
		@Override
7c84877 241
		public void setText(String text){
7c84877 242
			super.setText(text.toUpperCase());
7c84877 243
		}
7c84877 244
		@Override
7c84877 245
		public void paint( Graphics g){
7c84877 246
			Graphics2D g2d = ( Graphics2D ) g;
7c84877 247
			if(headerBgPaint == null)
7c84877 248
				headerBgPaint = new GradientPaint ( 0, 1, Style.headerBg, 
7c84877 249
						0, getHeight()-1, Style.headerBgBot);
7c84877 250
			g2d.setPaint ( headerBgPaint );
7c84877 251
			g2d.fillRect ( 0, 1, getWidth (), getHeight () - 1 );
7c84877 252
7c84877 253
			// Header top and bottom lines
7c84877 254
			g2d.setColor ( Style.headerTopLine );
7c84877 255
			g2d.drawLine ( 0, 0, getWidth (), 0 );
7c84877 256
			super.paint(g);
7c84877 257
		}
a62d533 258
	}
7c84877 259
	
7c84877 260
	/* ToolBar Related Methods */
a62d533 261
	// This is for Menu Items
a62d533 262
	final public static JButton createMenuButton(String title){
a62d533 263
		JButton btn = new JButton(title);
a62d533 264
		btn.setFocusable(false);
a62d533 265
		btn.setOpaque(false);
7c84877 266
		UIUtils.setRolloverDecoratedOnly(btn, true);
7c84877 267
		UIUtils.setRound(btn, 0);
7c84877 268
		UIUtils.setLeftRightSpacing(btn, 5);
7c84877 269
		UIUtils.setShadeWidth(btn, 0);
7c84877 270
		UIUtils.setInnerShadeWidth(btn, 0);
a62d533 271
		return btn;
a62d533 272
	} 
7c84877 273
a62d533 274
	// This is for ToolButtons without Popup
a62d533 275
	final public static JPanel createToolPanel(String text, String iconname,final ActionListener onClick){
a62d533 276
		final JPanel pan = new JPanel(new VerticalFlowLayout(FlowLayout.CENTER, 0, 0));
a62d533 277
		pan.setOpaque(false);
a62d533 278
		UIUtils.setRound(pan, 0);
a62d533 279
		UIUtils.setShadeWidth(pan, 0);
a62d533 280
		JButton btn = createMenuButton(text);
a62d533 281
		btn.setIcon(Icon.icon(iconname));
a62d533 282
		if(onClick != null)
a62d533 283
			btn.addActionListener(onClick);
a62d533 284
		btnMap.put(iconname, btn);
a62d533 285
		pan.add(btn);
a62d533 286
		return pan;
a62d533 287
	}
a62d533 288
7c84877 289
	/* SideBar Related Methods */
a62d533 290
	// This is for ToolButtons with Popup
7c84877 291
	final public static JButton createToolButton(String tooltip, String iconname, ActionListener al){
a62d533 292
		final JButton btn = new JButton(Icon.icon(iconname));
7c84877 293
		btn.setToolTipText(tooltip);
7c84877 294
		UIUtils.setRolloverDecoratedOnly(btn,true);
7c84877 295
		UIUtils.setLeftRightSpacing(btn, 0);
a62d533 296
		btn.setFocusable(false);
7c84877 297
		if(al != null)
7c84877 298
			btn.addActionListener(al);
a62d533 299
		return btn;
a62d533 300
	}
7c84877 301
a62d533 302
	// This is for ToolButtons without Popup
a62d533 303
	public static JButton createPopUpToolButton(String iconname){
a62d533 304
		JButton btn = new JButton(Icon.icon(iconname));
a62d533 305
		btn.setFocusable(false);
a62d533 306
		btn.setToolTipText(iconname.toUpperCase());
a62d533 307
		btn.setOpaque(false);
7c84877 308
		UIUtils.setLeftRightSpacing(btn, 4);
7c84877 309
		UIUtils.setRound(btn, 0);
7c84877 310
		UIUtils.setUndecorated(btn, true);
a62d533 311
		return btn;
a62d533 312
	}
7c84877 313
a62d533 314
	static int currentIndex = 1;
a62d533 315
	public static void viewButton(String text, String ic){
a62d533 316
		final int id = Integer.valueOf(currentIndex);
a62d533 317
		currentIndex += 1;
a62d533 318
		JButton btn = new JButton(text,Icon.icon(ic));
a62d533 319
		UIUtils.setDrawFocus(btn, false);
7c84877 320
		UIUtils.setShadeWidth(btn, 0);
a9b2a64 321
		UIUtils.setRound(btn, 0);
a62d533 322
		viewGroup.add(btn);
a62d533 323
		btn.addActionListener(new ActionListener(){
a62d533 324
			@Override
a62d533 325
			public void actionPerformed(ActionEvent arg0) {
a62d533 326
				Content.toggleView(id);
a62d533 327
			}
7c84877 328
		});
a62d533 329
	}
7c84877 330
a62d533 331
	final public static JPanel createButtonToolBarPanel(){
a62d533 332
		JPanel tools = new JPanel(new ToolbarLayout(ToolbarLayout.HORIZONTAL)){
a62d533 333
			private static final long serialVersionUID = 1L;
a62d533 334
a62d533 335
			@Override
a62d533 336
			public void paintComponent(Graphics g){
7c84877 337
				Style.drawHorizontalBar(g, getWidth (), getHeight ());
7c84877 338
				g.setColor(Color.GRAY);
7c84877 339
				g.drawLine(0, getHeight()-1, getWidth(), getHeight()-1);
a62d533 340
			}
a62d533 341
		};
a62d533 342
		return tools;
a62d533 343
	}
7c84877 344
a62d533 345
	public static JPanel createButtonToolBar(ActionListener al, String[] list){
a62d533 346
		JPanel tools = createButtonToolBarPanel();
a62d533 347
		for(int i=0;i< list.length-1; i++){
a62d533 348
			if(i != 0)
a62d533 349
				if(i%2 != 0) 
a62d533 350
					continue;
a62d533 351
			final JButton btn = new JButton(Icon.icon(list[i+1]));
7c84877 352
			UIUtils.setRolloverDecoratedOnly(btn,true);
7c84877 353
			UIUtils.setLeftRightSpacing(btn, 0);
7c84877 354
			btn.setFocusable(false);
7c84877 355
			btn.setToolTipText(list[i]);
7c84877 356
			btn.addActionListener(al);
7c84877 357
			tools.add(btn);
a62d533 358
		}
a62d533 359
		return tools;
a62d533 360
	}
a62d533 361
}