Author Topic: Two functions to create boxes and frames  (Read 122 times)

iOtero

  • Sr. Member
  • ****
  • Posts: 171
    • View Profile
Two functions to create boxes and frames
« on: July 11, 2018, 06:45:40 AM »
It seems to me that AM does not have functions for this, so if someone can be useful, two functions to create boxes and frames:

Code: [Select]
// Two functions to create boxes and frames
//
// First: Create a white png 1x1 pixels sized. Save as "white_point.png"
// Create a folder named objs in your layout and copy "white_point.png" into it.
//
// Function draw_box(box_x,box_y,box_w,box_h,box_r,box_g,box_b,box_a,box_s)
//
// box_x --> The x coordinate of the top left corner of the box (in layout coordinates).
// box_y --> The y coordinate of the top left corner of the box (in layout coordinates).
// box_w --> The width of the box (in layout coordinates).
// box_h --> The height of the box (in layout coordinates).
// box_r --> Set red colour level for the box. Range is 0-255.
// box_g --> Set green colour level for the box. Range is 0-255.
// box_b --> Set blue colour level for the box. Range is 0-255.
// box_a --> Set alpha level for the box. Range is 0-255.
// box_s --> Width of the box shadow (in layout coordinates). Set 0 for no shadow.

function draw_box(box_x,box_y,box_w,box_h,box_r,box_g,box_b,box_a,box_s)
{
if(box_s != 0)
{
local bflw = fe.layout.width;
local bflh = fe.layout.height;

local dbox = fe.add_image("objs/sys/white_point.png", box_x+box_s, box_y+box_s, box_w, box_h);
dbox.set_rgb(0,0,0);
dbox.alpha=255;
}

local dbox = fe.add_image("objs/sys/white_point.png", box_x, box_y, box_w, box_h);
dbox.set_rgb(box_r,box_g,box_b);
dbox.alpha=box_a;

}

// Function draw_frame(box_x,box_y,box_w,box_h,box_r,box_g,box_b,box_a,box_s)
//
// frame_x --> The x coordinate of the top left corner of the frame (in layout coordinates).
// frame_y --> The y coordinate of the top left corner of the frame (in layout coordinates).
// frame_w --> The width of the frame (in layout coordinates).
// frame_h --> The height of the frame (in layout coordinates).
// frame_r --> Set red colour level for the frame. Range is 0-255.
// frame_g --> Set green colour level for the frame. Range is 0-255.
// frame_b --> Set blue colour level for the frame. Range is 0-255.
// frame_a --> Set alpha level for the frame. Range is 0-255.
// frame_fw --> The Width of the border of the frame (in layout coordinates).
// frame_fh --> The Height of the border of the frame (in layout coordinates).

function draw_frame(frame_x,frame_y,frame_w,frame_h,frame_r,frame_g,frame_b,frame_a,frame_fw,frame_fh)
{
local dframe1 = fe.add_image("objs/white_point.png", frame_x, frame_y, frame_w, frame_fh);
dframe1.set_rgb(frame_r,frame_g,frame_b);
dframe1.alpha=frame_a;

local dframe2 = fe.add_image("objs/white_point.png", frame_x, frame_y+frame_h, frame_w, frame_fh);
dframe2.set_rgb(frame_r,frame_g,frame_b);
dframe2.alpha=frame_a;

local dframe3 = fe.add_image("objs/white_point.png", frame_x, frame_y, frame_fw, frame_h);
dframe3.set_rgb(frame_r,frame_g,frame_b);
dframe3.alpha=frame_a;

local dframe4 = fe.add_image("objs/white_point.png", frame_x+frame_w, frame_y, frame_fw, frame_h+frame_fh);
dframe4.set_rgb(frame_r,frame_g,frame_b);
dframe4.alpha=frame_a;
}

// Example: Draw two boxes and one frame
local flx = fe.layout.width;
local fly = fe.layout.height;
local flw = fe.layout.width;
local flh = fe.layout.height;
draw_box(flx*0.3, fly*0.3, flw*0.5, flh*0.5, 175, 175, 175, 255,flw*0.005);
draw_box(flx*0.35, fly*0.35, flw*0.4, flh*0.4, 135, 175, 50, 150,0);
draw_frame(flx*0.35, fly*0.35, flw*0.4, flh*0.4, 255, 0, 0, 255, flw*0.002, flh*0.003);
« Last Edit: July 11, 2018, 08:20:07 AM by zlagos »

jedione

  • Hero Member
  • *****
  • Posts: 504
  • punktoe
    • View Profile
Re: Two functions to create boxes and frames
« Reply #1 on: July 11, 2018, 07:50:35 AM »
have to go to work,   but is this code actually work...

its a great idea.
help a friend....