processing java mode draw a simple button

preview_player
Показать описание
This video shows you how to code a nice and simple button easily with processing
Рекомендации по теме
Комментарии
Автор

// hello i am going to show you how to code a simple button

float button_ok_x1 = 100.0;
float button_ok_y1 = 50.0;
float button_ok_x2 = 170.0;
float button_ok_y2 = 100.0;

float button_cancel_x1 = 200.0;
float button_cancel_y1 = 50.0;
float button_cancel_x2 = 315.0;
float button_cancel_y2 = 100.0;

float button_quit_x1 = 340.0;
float button_quit_y1 = 50.0;
float button_quit_x2 = 420.0;
float button_quit_y2 = 100.0;

String message = "";

void setup() {

size(displayWidth, displayHeight);
textSize(30);
}

void draw() {

background(0, 90, 200);

fill(255);
text(message, 100, 30);

draw_button("Ok", button_ok_x1, button_ok_y1, button_ok_x2, button_ok_y2, #7F82FC);
draw_button("Cancel", button_cancel_x1, button_cancel_y1, button_cancel_x2, button_cancel_y2, #7F82FC);
draw_button("Quit", button_quit_x1, button_quit_y1, button_quit_x2, button_quit_y2, #7F82FC);
}

void draw_button(String _text, float x1, float y1, float x2, float y2, color button_color) {

fill(button_color);
noStroke();

rect(x1, y1, x2 - x1, y2 - y1);

strokeWeight(3);
stroke(255);
// top of the button
line(x1, y1, x2, y1);
// left of the button
line(x1, y1, x1, y2);

stroke(0);
// bottom of the button
line(x1, y2, x2, y2);
// right of the button
line(x2, y1, x2, y2);

fill(255);
text(_text, x1 + 10, y1 + 35);
}

void mousePressed() {

if (mouseX > button_ok_x1 && mouseX < button_ok_x2 &&
mouseY > button_ok_y1 && mouseY < button_ok_y2) {
message = "ok button clicked";
}

if (mouseX > button_cancel_x1 && mouseX < button_cancel_x2 &&
mouseY > button_cancel_y1 && mouseY < button_cancel_y2) {
message = "cancel button clicked";
}

if (mouseX > button_quit_x1 && mouseX < button_quit_x2 &&
mouseY > button_quit_y1 && mouseY < button_quit_y2) {
exit();
}
}

coprocessingcoprocessing
Автор

This looks great, but you advertised drawing a simple button. You drew three buttins and totally confused me as to what code belongs to what button. This is not a nice and simple button exercise. Coild you redo the video showing only one button please

gameworn
welcome to shbcf.ru