Java Code Examples for org.newdawn.slick.Graphics#drawLine()

The following examples show how to use org.newdawn.slick.Graphics#drawLine() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OptionsOverlay.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Renders a slider option.
 * @param g the graphics context
 * @param option the game option
 * @param cy the y coordinate
 */
private void renderSliderOption(Graphics g, GameOption option, int cy) {
	// draw option name and value
	final int padding = 10;
	String value = option.getValueString();
	int nameWidth = Fonts.MEDIUM.getWidth(option.getName());
	int valueWidth = Fonts.MEDIUM.getWidth(value);
	Fonts.MEDIUM.drawString(x + optionStartX, cy + optionTextOffsetY, option.getName(), COLOR_WHITE);
	Fonts.MEDIUM.drawString(x + optionStartX + optionWidth - valueWidth, cy + optionTextOffsetY, value, COLOR_BLUE);

	// calculate slider positions
	int sliderWidth = optionWidth - nameWidth - padding - padding - valueWidth;
	if (sliderWidth <= 1)
		return;  // menu hasn't slid in far enough to need to draw the slider
	int sliderStartX = (int) (x + optionStartX + nameWidth + padding);
	if (hoverOption == option) {
		sliderOptionStartX = sliderStartX;
		if (!isAdjustingSlider)
			sliderOptionWidth = sliderWidth;
		else
			sliderWidth = sliderOptionWidth;
	}
	int sliderEndX = sliderStartX + sliderWidth;

	// draw slider
	float sliderValue = (float) (option.getIntegerValue() - option.getMinValue()) / (option.getMaxValue() - option.getMinValue());
	float sliderBallPos = sliderStartX + (int) ((sliderWidth - controlImageSize) * sliderValue);
	g.setLineWidth(3f);
	g.setColor(COLOR_PINK);
	if (sliderValue > 0.0001f)
		g.drawLine(sliderStartX, cy + optionHeight / 2, sliderBallPos, cy + optionHeight / 2);
	sliderBallImg.draw(sliderBallPos, cy + controlImagePadding, COLOR_PINK);
	if (sliderValue < 0.999f) {
		float oldAlpha = COLOR_PINK.a;
		COLOR_PINK.a *= 0.45f;
		g.setColor(COLOR_PINK);
		g.drawLine(sliderBallPos + controlImageSize + 1, cy + optionHeight / 2, sliderEndX, cy + optionHeight / 2);
		COLOR_PINK.a = oldAlpha;
	}
}
 
Example 2
Source File: GeomAccuracyTest.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Draws arcs
 * @param g
 */
void arcTest(Graphics g) {
	
	if(hideOverlay == false) {
		g.setColor(overlayColor);
		g.drawLine(198, 100, 198, 198);
		g.drawLine(100, 198, 198, 198);
	}
	
	g.setColor(geomColor);
	g.drawArc(100, 100, 99, 99, 0, 90);


}
 
Example 3
Source File: GeomAccuracyTest.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Draws ovals
 * @param g
 */
void ovalTest(Graphics g) {

	g.setColor(geomColor);
	g.drawOval(100, 100, 99, 99);
	g.fillOval(100, 250, 99, 99);
	
	//Circle circ = new Circle(400, 100, 99);
	Ellipse elip = new Ellipse(449, 149, 49, 49);
	g.draw(elip);
	elip = new Ellipse(449, 299, 49, 49);
	g.fill(elip);
	
	if(hideOverlay == false) {
		g.setColor(overlayColor);
		g.drawLine(100, 149, 198, 149);
		g.drawLine(149, 100, 149, 198);
		
		g.drawLine(100, 149 + 150, 198, 149 + 150);
		g.drawLine(149, 100 + 150, 149, 198 + 150);
		
		g.drawLine(100 + 300, 149, 198 + 300, 149);
		g.drawLine(149 + 300, 100, 149 + 300, 198);			
		
		g.drawLine(100 + 300, 149 + 150, 198 + 300, 149 + 150);
		g.drawLine(149 + 300, 100 + 150, 149 + 300, 198 + 150);			
	}
	

}
 
Example 4
Source File: UserSelectOverlay.java    From opsu with GNU General Public License v3.0 4 votes vote down vote up
/** Renders the user creation menu. */
private void renderUserCreate(Graphics g, float alpha) {
	COLOR_WHITE.a = COLOR_RED.a = alpha;
	COLOR_GRAY.a = alpha * 0.8f;

	// title
	String title = "Add User";
	Fonts.XLARGE.drawString(
		x + (width - Fonts.XLARGE.getWidth(title)) / 2,
		(int) (y + titleY),
		title, COLOR_WHITE
	);

	// user button
	int cy = (int) (y + usersStartY);
	String caption = "Click the profile below to create it.";
	Fonts.MEDIUM.drawString(x + (width - Fonts.MEDIUM.getWidth(caption)) / 2, cy, caption, COLOR_WHITE);
	cy += Fonts.MEDIUM.getLineHeight();
	newUserButton.draw(g, alpha);
	cy += UserButton.getHeight() + Fonts.MEDIUMBOLD.getLineHeight();

	// user name
	String nameHeader = "Name";
	Fonts.MEDIUMBOLD.drawString(x + (width - Fonts.MEDIUMBOLD.getWidth(nameHeader)) / 2, cy, nameHeader, COLOR_WHITE);
	cy += Fonts.MEDIUMBOLD.getLineHeight();
	Color textColor = COLOR_WHITE;
	String name = newUser.getName();
	if (name.isEmpty()) {
		name = "Type a name...";
		textColor = COLOR_GRAY;
	} else if (!UserList.get().isValidUserName(name))
		textColor = COLOR_RED;
	int textWidth = Fonts.LARGE.getWidth(name);
	int searchTextX = (int) (x + (width - textWidth) / 2);
	Fonts.LARGE.drawString(searchTextX, cy, name, textColor);
	cy += Fonts.LARGE.getLineHeight();
	g.setColor(textColor);
	g.setLineWidth(2f);
	g.drawLine(searchTextX, cy, searchTextX + textWidth, cy);
	cy += Fonts.MEDIUMBOLD.getLineHeight();

	// user icons
	renderUserIcons(g, newUser.getIconId(), "Icon", cy, alpha);
}
 
Example 5
Source File: NavMeshTest.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Render the game - in this case render the map and diagnostic data
 * 
 * @param container The container we're running the game in
 * @param g The graphics context on which to render
 */
public void render(GameContainer container, Graphics g)
		throws SlickException {
	g.translate(50,50);
	for (int x=0;x<50;x++) {
		for (int y=0;y<50;y++) {
			if (dataMap.blocked(this, x, y)) {
				g.setColor(Color.gray);
				g.fillRect((x*10)+1,(y*10)+1,8,8);
			}
		}
	}
	
	if (showSpaces) {
		for (int i=0;i<navMesh.getSpaceCount();i++) {
			Space space = navMesh.getSpace(i);
			if (builder.clear(dataMap, space)) {
				g.setColor(new Color(1,1,0,0.5f));
				g.fillRect(space.getX()*10, space.getY()*10, space.getWidth()*10, space.getHeight()*10);
			}
			g.setColor(Color.yellow);
			g.drawRect(space.getX()*10, space.getY()*10, space.getWidth()*10, space.getHeight()*10);

			if (showLinks) {
				int links = space.getLinkCount();
				for (int j=0;j<links;j++) {
					Link link = space.getLink(j);
					g.setColor(Color.red);
					g.fillRect((link.getX()*10)-2, (link.getY()*10)-2,5,5);
				}
			}
		}
	}
	
	if (path != null) {
		g.setColor(Color.white);
		for (int i=0;i<path.length()-1;i++) {
			g.drawLine(path.getX(i)*10, path.getY(i)*10, path.getX(i+1)*10, path.getY(i+1)*10);
		}
	}
}
 
Example 6
Source File: GraphicsTest.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
 */
public void render(GameContainer container, Graphics g) throws SlickException {
	g.setColor(Color.white);
	
	g.setAntiAlias(true);
	for (int x=0;x<360;x+=10) {
		g.drawLine(700,100,(int) (700+(Math.cos(Math.toRadians(x))*100)),
						   (int) (100+(Math.sin(Math.toRadians(x))*100)));
	}
	g.setAntiAlias(false);
	
	g.setColor(Color.yellow);
	g.drawString("The Graphics Test!", 300, 50);
	g.setColor(Color.white);
	g.drawString("Space - Toggles clipping", 400, 80);
	g.drawString("Frame rate capped to 100", 400, 120);
	
	if (clip) {
		g.setColor(Color.gray);
		g.drawRect(100,260,400,100);
		g.setClip(100,260,400,100);
	}

	g.setColor(Color.yellow);
	g.translate(100, 120);
	g.fill(poly);
	g.setColor(Color.blue);
	g.setLineWidth(3);
	g.draw(poly);
	g.setLineWidth(1);
	g.translate(0, 230);
	g.draw(poly);
	g.resetTransform();
	
	g.setColor(Color.magenta);
	g.drawRoundRect(10, 10, 100, 100, 10);
	g.fillRoundRect(10, 210, 100, 100, 10);
	
	g.rotate(400, 300, ang);
	g.setColor(Color.green);
	g.drawRect(200,200,200,200);
	g.setColor(Color.blue);
	g.fillRect(250,250,100,100);

	g.drawImage(image, 300,270);
	
	g.setColor(Color.red);
	g.drawOval(100,100,200,200);
	g.setColor(Color.red.darker());
	g.fillOval(300,300,150,100);
	g.setAntiAlias(true);
	g.setColor(Color.white);
	g.setLineWidth(5.0f);
	g.drawOval(300,300,150,100);
	g.setAntiAlias(true);
	g.resetTransform();
	
	if (clip) {
		g.clearClip();
	}
}
 
Example 7
Source File: InputTest.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Draw the line to the provided graphics context
 * 
 * @param g The graphics context on which to draw the line
 */
public void draw(Graphics g) {
	g.drawLine(oldx, oldy, newx, newy);
}