Gamebot
Member
I am currently creating a nodal system for inputs and outputs. One of the features I would like to implement is to allow for grouping boxes. Therefore, to keep organized and move many nodals at once.
It should be noted I am simply drawing rectangles as there are no sprites. Therefore, there are no tiles either. I was looking into finding out if one of three conditions existed, completely in, completely out, or both when I move a nodal box into a group box. It just so happens rectangle_in_rectangle is exactly what I needed (So I thought). However, a few complications has a risen with this. It's not working as I expected. If I've made a mistake somewhere that I am just blaten too, well my apologies. Here is a clearer picture of what's happening:
Each nodal box should have an in/out number which corresponds to the return of the rectangle_in_rectangle arguments.
0 = Out of bounds. However, I made it noone.
1 = in bounds
2 = half bounds (Part in part out)
All is well except the second nodal box on the top row. It is reading that I am part of the way within the group box, yet you can clearly see I am within the bounds completely. Here is the code:
OBJ_NODAL_BOX
CREATE:
STEP:
ALARM [0]:
DRAW:
OBJ_GROUP_BOX
CREATE:
DRAW:
Any thoughts would be helpful also.
EDIT: Sorry everybody I DID make a typo in my code which has now been fixed (Above too). How I missed that don't know. I had figured out that a "y" value had been replaced with an "x" value.
It should be noted I am simply drawing rectangles as there are no sprites. Therefore, there are no tiles either. I was looking into finding out if one of three conditions existed, completely in, completely out, or both when I move a nodal box into a group box. It just so happens rectangle_in_rectangle is exactly what I needed (So I thought). However, a few complications has a risen with this. It's not working as I expected. If I've made a mistake somewhere that I am just blaten too, well my apologies. Here is a clearer picture of what's happening:
Each nodal box should have an in/out number which corresponds to the return of the rectangle_in_rectangle arguments.
0 = Out of bounds. However, I made it noone.
1 = in bounds
2 = half bounds (Part in part out)
All is well except the second nodal box on the top row. It is reading that I am part of the way within the group box, yet you can clearly see I am within the bounds completely. Here is the code:
OBJ_NODAL_BOX
CREATE:
Code:
// Width and height of our box. nsize = nodesize in pixels.
wid = 96;
hei = 96;
nsize = 4;
// Text and group attached to
txt = "Nodal Box";
group = noone;
// To get mouse_x and mouse_y relative to x and y for moving around in the grid.
xx = 0;
yy = 0;
pressed = false;
// Number of input nodes (Left) and Output nodes (right) of each box
in_node_num = 3;
out_node_num = 3;
Code:
if point_in_rectangle(mouse_x, mouse_y, x + nsize, y + nsize, x + wid - nsize, y + hei - nsize){
if (mouse_check_button_pressed(mb_left)){
if (alarm[0] = -1) alarm[0] = 1;
}
}
if (pressed)
{
depth = -1;
x = mouse_x + xx;
y = mouse_y + yy;
move_snap(global.gridwid, global.gridhei);
}
/***** The problem lies here? *****/
if (mouse_check_button_released(mb_left)){
pressed = false; depth = 0;
// If entire node box is within the group box ("1") then attach node box to group box
var colis = rectangle_in_rectangle(x - nsize, y - nsize, x + wid + nsize, y + hei + nsize, obj_group.x, obj_group.y, obj_group.x + obj_group.wid, obj_group.y + obj_group.hei)
switch (colis)
{
case 0: group = noone; break; // Not in bounds
case 1: group = "1"; break; // In bounds
case 2: group = "2"; break; // Half way
default: exit; break;
}
}
Code:
pressed = true;
xx = x - mouse_x;
yy = y - mouse_y;
Code:
// Draw box
draw_roundrect_color_ext(x, y, x + wid, y + hei, 5, 5, c_lime, c_lime, false);
draw_roundrect_color_ext(x, y, x + wid, y + 16, 5, 5, c_white, c_white, false);
// Draw border if pressed
if (pressed){
draw_rectangle_color(x - 1, y - 1, x + wid + 1, y + hei + 1, 10, 10, c_black, c_black, true);
draw_rectangle_color(x, y, x + wid, y + hei, 10, 10, c_black, c_black, true);
}
// Draw nodals
var tnum = 24/9;
var nodehei = hei/tnum;
// Input nodals on left
for(i = 0; i < in_node_num; i++)
{
if (point_in_circle(mouse_x, mouse_y, x, y + nodehei + (i * 24), nsize))
{
draw_circle_color(x, y + nodehei + (i * 24), nsize, c_orange, c_orange, false)
draw_circle_color(x, y + nodehei + (i * 24), nsize, c_black, c_black, true)
global.in = y + nodehei + (i * 24);
}
else{
draw_circle_color(x, y + nodehei + (i * 24), nsize, c_white, c_white, false)
draw_circle_color(x, y + nodehei + (i * 24), nsize, c_black, c_black, true)
}
}
// Output nodals on right
for(o = 0; o < out_node_num; o++)
{
if (point_in_circle(mouse_x, mouse_y, x + wid, y + nodehei + (o * 24), nsize))
{
draw_circle_color(x + wid, y + nodehei + (o * 24), nsize, c_orange, c_orange, false)
draw_circle_color(x + wid, y + nodehei + (o * 24), nsize, c_black, c_black, true)
global.out = y + nodehei + (o * 24);
}
else{
draw_circle_color(x + wid, y + nodehei + (o * 24), nsize, c_white, c_white, false)
draw_circle_color(x + wid, y + nodehei + (o * 24), nsize, c_black, c_black, true)
}
}
// Draw title and other information
draw_set_font(fnt_nodebox);
draw_set_color(c_black);
draw_set_halign(fa_middle);
draw_set_valign(fa_center);
var strhei = string_height(" ");
draw_text(x + wid/2, y + strhei/2, txt)
draw_text(x + wid/2, y + strhei/2 * 3, "In/Out: " + string(group))
CREATE:
Code:
wid = 288;
hei = 288;
Code:
draw_set_color(c_gray);
draw_rectangle(x, y, x + wid, y + hei, false);
draw_set_color(c_white);
draw_rectangle(x + 1, y + 1, x + wid - 1, y + 16, false)
draw_set_color(c_black);
draw_rectangle(x, y, x + wid, y + hei, true);
draw_text(x + wid/2, y + 8, "GroupBox1" + " id = " + string(id))
EDIT: Sorry everybody I DID make a typo in my code which has now been fixed (Above too). How I missed that don't know. I had figured out that a "y" value had been replaced with an "x" value.
Last edited: