Jump to content

draw image box from image parts


Fist

Recommended Posts

Posted

hello!

I barerly know anything about dxDraw that's why im here, So far i have used only ceGui but i want to learn how i can make dxDraw box with image parts that automaticly make box no matter what kind of size from images that are splitted into several images which contains box all together.

Posted

anyone? I mean't draw image and then around it would be bordered with images that would connect to each other to no matter what size box is.

Posted

Hello @Fist

as pack03 told you , you can use the function posted by me in the wiki , to help the others , but now you want it for an image

so it's pretty easy as i think , u can just edit the function from dxDrawRectangle => to dxDrawImage and edit the x,y,w,h and the color ...

 

Peace !

Posted
10 minutes ago, coNolel said:

Hello @Fist

as pack03 told you , you can use the function posted by me in the wiki , to help the others , but now you want it for an image

so it's pretty easy as i think , u can just edit the function from dxDrawRectangle => to dxDrawImage and edit the x,y,w,h and the color ...

 

Peace !

yes it actually would work, but i want to draw corner images aswell but in your code there are only top-bottom and left-right. How about right-top corner, left-top corner, etc.

Posted
Just now, Fist said:

yes it actually would work, but i want to draw corner images aswell but in your code there are only top-bottom and left-right. How about right-top corner, left-top corner, etc.

What do you mean , 

can you show me an image explaining what exactly do you want ?

Posted

aaaah

Just now, Fist said:

i posted image above already. http://prntscr.com/eiy10n

see there are images with corner parts. 

u can try this,  ( btw not tested ^^" )

function dxDrawBorderedImage( x, y, width, height, color1, color2, _width, postGUI )
    local _width = _width or 1
   -- dxDrawRectangle ( x+1, y+1, width-1, height-1, color1, postGUI )
 	dxDrawImage ( (x+width)/2-imageWidth,(y+height)/2-(imageHeight),  image)
    dxDrawLine ( x, y, x+width, y, color2, _width, postGUI ) -- Top
    dxDrawLine ( x, y, x, y+height, color2, _width, postGUI ) -- Left
    dxDrawLine ( x, y+height, x+width, y+height, color2, _width, postGUI ) -- Bottom
    dxDrawLine ( x+width, y, x+width, y+height, color2, _width, postGUI ) -- Right
end

i hope it works for you

Posted
2 minutes ago, coNolel said:

aaaah

u can try this,  ( btw not tested ^^" )


function dxDrawBorderedImage( x, y, width, height, color1, color2, _width, postGUI )
    local _width = _width or 1
   -- dxDrawRectangle ( x+1, y+1, width-1, height-1, color1, postGUI )
 	dxDrawImage ( (x+width)/2-imageWidth,(y+height)/2-(imageHeight),  image)
    dxDrawLine ( x, y, x+width, y, color2, _width, postGUI ) -- Top
    dxDrawLine ( x, y, x, y+height, color2, _width, postGUI ) -- Left
    dxDrawLine ( x, y+height, x+width, y+height, color2, _width, postGUI ) -- Bottom
    dxDrawLine ( x+width, y, x+width, y+height, color2, _width, postGUI ) -- Right
end

i hope it works for you

imageWidth and imageHeight doesn't exist?

Posted (edited)

i think he need this

 

On 3/11/2017 at 10:12, Fist said:

hello!

I barerly know anything about dxDraw that's why im here, So far i have used only ceGui but i want to learn how i can make dxDraw box with image parts that automaticly make box no matter what kind of size from images that are splitted into several images which contains box all together.

addEventHandler('onClientRender', root, function()
  dxDrawImageSection(400, 200, 64, 64, 0, 0, 64, 64, 'img.jpg') -- Draw a certain section
  dxDrawImage(400, 300, 128, 128, 'img.jpg') -- Draw the whole image to be able to identify the difference
end)

use this image

128x128.jpg

Edited by Ayush Rathore
Posted
function dxDrawBorderedImage( x, y, width, height, image, imageWidth, imageHeight, color1, _width, postGUI )
    local _width = _width or 1
   -- dxDrawRectangle ( x+1, y+1, width-1, height-1, color1, postGUI )
 	dxDrawImage ( (x+width)/2-imageWidth,(y+height)/2-(imageHeight),  image)
    dxDrawLine ( x, y, x+width, y, color1, _width, postGUI ) -- Top
    dxDrawLine ( x, y, x, y+height, color1, _width, postGUI ) -- Left
    dxDrawLine ( x, y+height, x+width, y+height, color1, _width, postGUI ) -- Bottom
    dxDrawLine ( x+width, y, x+width, y+height, color1, _width, postGUI ) -- Right
end

try this ^^"

  • Like 1
Posted (edited)
9 minutes ago, coNolel said:

function dxDrawBorderedImage( x, y, width, height, image, imageWidth, imageHeight, color1, _width, postGUI )
    local _width = _width or 1
   -- dxDrawRectangle ( x+1, y+1, width-1, height-1, color1, postGUI )
 	dxDrawImage ( (x+width)/2-imageWidth,(y+height)/2-(imageHeight),  image)
    dxDrawLine ( x, y, x+width, y, color1, _width, postGUI ) -- Top
    dxDrawLine ( x, y, x, y+height, color1, _width, postGUI ) -- Left
    dxDrawLine ( x, y+height, x+width, y+height, color1, _width, postGUI ) -- Bottom
    dxDrawLine ( x+width, y, x+width, y+height, color1, _width, postGUI ) -- Right
end

try this ^^"

i mean it draws it but it's just a 1 image, i can't tell or it works or not. Can you just edit that dxDrawBorderedRectangle by just adding corner images and those lines itself to images aswell?

Edited by Fist
Posted
1 minute ago, Fist said:

i mean it draws it but it's just a 1 image, i can't tell or it works or not. Can you just edit that dxDrawBorderedRectangle by just adding corner images and those lines itself to images aswell.

do u mean my post tell me

Posted
Just now, Ayush Rathore said:

do u mean my post tell me

i mean't his, but yours won't work for me 'cause those image parts are seprate images not 1 big image.

Posted

@coNolel 

i actually did it by my self, it actually was way simplier than i thought. Thanks to your sample i managed to make it. Thanks man alot!

6 minutes ago, Ayush Rathore said:

ok no problem :)

 

 

thanks for trying to help tho. I appreciate people like that. :)

  • Like 1
Posted

This is what you are looking for:

function drawImageBox( x, y, w, h )
	-- you should probably check here for valid size etc.
	-- w and h need to be at least 32, 48 would probably be even better
	
	dxDrawImage( x,		y,		16,		16,		"images/left-up.png" )
	dxDrawImage( x+16,	y,		w-32,	16,		"images/up.png" )
	dxDrawImage( x+w-16,y,		16,		16,		"images/right-up.png" )
	dxDrawImage( x,		y+16,	16,		h-32,	"images/left.png" )
	dxDrawImage( x+16,	y+16,	w-32,	h-32,	"images/center.png" )
	dxDrawImage( x+w-16,y+16,	16,		h-32,	"images/right.png" )
	dxDrawImage( x,		y+h-16,	16,		16,		"images/left-down.png" )
	dxDrawImage( x+16,	y+h-16,	w-32,	16,		"images/down.png" )
	dxDrawImage( x+w-16,y+h-16,	16,		16,		"images/right-down.png" )
end

 

Posted
34 minutes ago, 3aGl3 said:

This is what you are looking for:


function drawImageBox( x, y, w, h )
	-- you should probably check here for valid size etc.
	-- w and h need to be at least 32, 48 would probably be even better
	
	dxDrawImage( x,		y,		16,		16,		"images/left-up.png" )
	dxDrawImage( x+16,	y,		w-32,	16,		"images/up.png" )
	dxDrawImage( x+w-16,y,		16,		16,		"images/right-up.png" )
	dxDrawImage( x,		y+16,	16,		h-32,	"images/left.png" )
	dxDrawImage( x+16,	y+16,	w-32,	h-32,	"images/center.png" )
	dxDrawImage( x+w-16,y+16,	16,		h-32,	"images/right.png" )
	dxDrawImage( x,		y+h-16,	16,		16,		"images/left-down.png" )
	dxDrawImage( x+16,	y+h-16,	w-32,	16,		"images/down.png" )
	dxDrawImage( x+w-16,y+h-16,	16,		16,		"images/right-down.png" )
end

 

well, i already figured it out. But thanks anyway for your time, also do you know by any chance how to get longest string from table?

Posted

Don't think there is a native function for that but this is how I'd do it:

function getLongestString( table )
  local longest

  for k, v in pairs( table ) do
    if not longest or string.len(v) > string.len(longest) then
      longest = v
    end
  end
  
  return longest
end

 

  • Like 1
Posted
16 minutes ago, 3aGl3 said:

Don't think there is a native function for that but this is how I'd do it:


function getLongestString( table )
  local longest

  for k, v in pairs( table ) do
    if not longest or string.len(v) > string.len(longest) then
      longest = v
    end
  end
  
  return longest
end

 

thanks mate.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...