Jump to content

Recommended Posts

Posted

I have moved this from "Canvas Load PNG Image at X/Y with Transparency (Opacity)" so it can have it's own thread.

I need to Draw a Closed Polygon with Fill, not draw a polygon, then locate that polygon, then fill that polygon which is inconsistent due to anti-aliasing issues with irregular shapes.

It appears UniGUI Canvas has no Polygon function (please add in future).

Farshad, I found this on the Internet and ask for help to make it work.

var context='#1'._cc_; 
var poly = [5, 5, 100, 50, 50, 100, 10, 90]; 
var shape = poly.slice(0);
{
  context.fillStyle = '#f00'; 
  context.beginPath();
  context.moveTo(shape.shift(), shape.shift());
  while(shape.length) 
  {
    context.lineTo(shape.shift(), shape.shift());
  } 
  context.closePath();
  context.fill();

 

Posted

Farshad, this is very important for me, please show using code above how to draw an irregular closed polygon with flood fill as one action, not separate actions. 

  • Administrators
Posted
function click(sender, e, eOpts)
{
  var context=MainForm.UniCanvas1._cc_; 
   var poly = [5, 5, 100, 50, 50, 100, 10, 90]; 
   var shape = poly.slice(0);
   {
     context.fillStyle = '#f00'; 
     context.beginPath();
     context.moveTo(shape.shift(), shape.shift());
     while(shape.length) 
     {
       context.lineTo(shape.shift(), shape.shift());
     } 
     context.closePath();
     context.fill();
   } 
}

Worked for me.

Posted

The code mimics your Draw PNG Image JS, when I run it, it says cannot run JS here, please look at the code - thanks. 

Posted

Yes, but when I implement this code outside of the canvas click event, in other words from a button click, I get these errors below.

JS-Error.jpg

Posted

It is a massive graphics webapp, please cut the above code out of the Events editor and put in a button click and you will get the same results.

 

Posted

  cArea.JSInterface.JSCode('var context=MainForm.cArea._cc_; '+
                           'var poly = ['+s+']; '+
                           'var shape = poly.slice(0); '+
                           '{ '+
                           '  context.fillStyle = ''#f00'' '+
                           '  context.beginPath(); '+
                           '  context.moveTo(shape.shift(), shape.shift()); '+
                           '  while(shape.length) '+
                           '  { '+
                           '    context.lineTo(shape.shift(), shape.shift()); '+
                           '  } '+
                           '  context.closePath(); '+
                           '  context.fill(); '+
                           '} '
                          );
 

  • Administrators
Posted

 

procedure TMainForm.UniButton1Click(Sender: TObject);
begin
  UniCanvas1.JSInterface.JSCode('var context = MainForm.UniCanvas1._cc_; '+
                             'var poly = [5, 5, 100, 50, 50, 100, 10, 90];'+
                             'var shape = poly.slice(0); '+
                             '  context.fillStyle = "#f00"; '+
                             '  context.beginPath(); '+
                             '  context.moveTo(shape.shift(), shape.shift()); '+
                             '  while(shape.length) '+
                             '  { '+
                             '    context.lineTo(shape.shift(), shape.shift()); '+
                             '  } '+
                             '  context.closePath(); '+
                             '  context.fill();'
                            );
end;

 

  • Like 1
Posted

Tried a few variations, still no go.

  with cArea do begin
    JSInterface.JSCall('var context=MainForm.cArea._cc_; '+
                       'var poly = ['+s+']; '+
                       'var shape = poly.slice(0); '+
                       '{ '+
                       '  context.fillStyle = ''#f00'' '+
                       '  context.beginPath(); '+
                       '  context.moveTo(shape.shift(), shape.shift()); '+
                       '  while(shape.length) '+
                       '  { '+
                       '    context.lineTo(shape.shift(), shape.shift()); '+
                       '  } '+
                       '  context.closePath(); '+
                       '  context.fill(); '+
                       '}; '
                      );
  end;
 

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...