THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 26/08/2011 at 08:51, xxxxxxxx wrote:
Here's a simple example using a Button , Textbox, and a UserArea.
Note the path to the bitmap image is at the end of the script:
// be sure to use a unique ID obtained from www.plugincafe.com
var PLUGIN_ID = 10000010;
// be sure to use a unique ID obtained from www.plugincafe.com
enum
{
But_clicked, // This is the ID name I gave my Button. Use whatever name you want
DLG_EDIT_BOX = 1000,
_DUMMY_ // This is needed for the enum type to work.
}
// global variables
var bmp;
var text;
// definition of my user area
class MyUserArea : GeUserArea
{
public:
MyUserArea(id,dialog);
Init();
GetUserWidth();
GetUserHeight();
Draw(x1,y1,x2,y2);
}
MyUserArea::MyUserArea(id,dialog)
{
super(id,dialog);
}
MyUserArea::Init()
{
}
MyUserArea::GetUserWidth()
{
return 128;
}
MyUserArea::GetUserHeight()
{
return 128;
}
MyUserArea::Draw(x1,y1,x2,y2)
{
OffScreenOn();
SetClippingRegion(x1,y1,x2,y2);
DrawBitmap(bmp, 0, 0, 127, 127, x1, y1, x2, y2, BMP_NORMALSCALED);
}
class MyDialog : GeDialog // definition of my Dialog class
{
private:
var ua;
public:
MyDialog();
CreateLayout();
Init();
Command(id,msg);
}
MyDialog::MyDialog()
{
super(PLUGIN_ID);
ua=NULL;
}
MyDialog::CreateLayout()
{
SetTitle("Test Bitmap Dialog");
AddUserArea(5000,BFH_SCALEFIT|BFV_SCALEFIT,0,0);
ua = new(MyUserArea,5000,this);
AddEditText(DLG_EDIT_BOX, 0, 200, 0);
AddButton(But_clicked, BFH_SCALEFIT, 250, 20, "Click Me");
return TRUE;
}
MyDialog::Init()
{
return TRUE;
}
MyDialog::Command(id,msg)
{
var doc = GetActiveDocument();
if (id == DLG_EDIT_BOX) //you got input from the text edit box.
{
text = GetString(DLG_EDIT_BOX); //grab the string from the edit box and store it into the text variable.
var len = sizeof(text); //find the size of the string (strlen for the C programmers)
}
if(id == But_clicked)
{
println("Button Clicked");
var obj = doc->GetActiveObject();
if(!obj)
{
TextDialog("No Cube object was selected\n" + "Please select one", DLG_OK + DLG_ICONEXCLAMATION);
return;
}
obj#PRIM_CUBE_DOFILLET=TRUE;
SetString(DLG_EDIT_BOX, "It Worked!");
}
EventAdd();
}
class MyMenuPlugin : MenuPlugin
{
public:
MyMenuPlugin();
GetID();
GetName();
GetHelp();
Execute(doc);
RestoreLayout(secret,subid);
}
MyMenuPlugin::MyMenuPlugin()
{
super();
}
MyMenuPlugin::GetID()
{
return PLUGIN_ID;
}
MyMenuPlugin::GetName()
{
return "Test bitmap Dialog"; // The name shown in plugins menu
}
MyMenuPlugin::GetHelp()
{
return "Shows programming of bitmap area";
}
var d;
MyMenuPlugin::Execute(doc)
{
d->Open(TRUE,-1,-1);
}
MyMenuPlugin::RestoreLayout(secret,subid)
{
if (!d) d = new(MyDialog);
d->RestoreLayout(secret);
}
main()
{
d = new(MyDialog);
if (!bmp) bmp = new(BaseBitmap, 128, 128);
var fn = new(Filename);
fn->SetFullString("c:/Test.jpg");// references the c: directory
bmp->Load(fn);
Register(MyMenuPlugin);
}
-ScottA