May 04, 2024, 10:19:14 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Simple Paint

Started by Ionic Wind Support Team, December 19, 2005, 10:35:32 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Ionic Wind Support Team

A partial conversion of the 'draw' program from Pro.  No bitmap functions , since they are not in the GUI library yet.

Might help some of you figure out where to 'put' things ;)  Compare to the original as a learning exercise.


//raster operations for SetRasterOp.  Will be in gui.inc
#define RMBLACK 0x1
#define RMWHITE 0x10
#define RMNOP 0xB
#define RMNOT 0x6
#define RMCOPYPEN 0xD
#define RMNOTCOPYPEN 0x4
#define RMMERGEPENNOT 0xE
#define RMMASKPENNOT 0x5
#define RMMERGENOTPEN 0xC
#define RMMASKNOTPEN 0x3
#define RMMERGEPEN 0xF
#define RMNOTMERGEPEN 0x2
#define RMMASKPEN 0x9
#define RMNOTMASKPEN 0x8
#define RMXORPEN 0x7
#define RMNOTXORPEN 0xA
DECLARE IMPORT,GetSystemMetrics(nIndex as INT),INT;

class DrawWnd : window
{
declare OnCreate(),int;
declare OnClose(),int;
declare OnMouseMove(int x,int y,int flags),int;
declare OnLButtonDown(int x,int y,int flags),int;
declare OnLButtonUp(int x,int y,int flags),int;
declare OnRButtonUp(int x,int y,int flags),int;
declare OnMenuPick(int nID),int;
declare OnMenuInit(unsigned int hMenu),int;
declare OnTimer(int nIDEvent),int;
int drawcolor,l,t,w,h,tempx,tempy,linesize,mode;
}

int run;

global sub main()
{
run = 1;
DrawWnd win;
menu m;
win.Create(0,0,640,480,AWS_CAPTION|AWS_SYSMENU|AWS_BORDER|AWS_SIZE|AWS_MINIMIZEBOX|
AWS_MAXIMIZEBOX|AWS_MAXIMIZE|AWS_AUTODRAW,0,"Simple Paint",0);
m.BeginMenu();
m.MenuTitle( "&File");
m.MenuItem( "Print",0,101);
m.MenuItem( "&Save",0,102);
m.MenuItem( "&Load",0,103);
m.MenuItem( "Quit",0,100);
m.MenuTitle( "Options");
m.MenuItem( "Color",0,99);
m.MenuItem( "Clear",0,1);
m.BeginPopup( "Line Size");
m.MenuItem( "1",AMF_CHECKED,2);
m.MenuItem( "2",0,3);
m.MenuItem( "3",0,4);
m.MenuItem( "4",0,5);
m.EndPopup();
m.MenuTitle( "Tools");
m.MenuItem( "Line",AMF_CHECKED,6);
m.MenuItem( "Rectangle",0,7);
m.MenuItem( "Circle",0,8);
m.MenuItem( "Spray",0,9);
m.MenuItem( "FILL",0,10);
m.EndMenu();
win.SetMenu(m.Detach());
do {wait(); }until run = 0;
return 0;
}

//our windows message handlers
DrawWnd::OnCreate(),int
{
drawcolor = 0;
linesize = 1;
FrontPen(drawcolor);
mode = 0;
return true;
}

DrawWnd::OnClose(),int
{
run = 0;
return true;
}

DrawWnd::OnMouseMove(int x,int y,int flags),int
{
tempx = x;
tempy = y;
IF(flags = 1)
{
SELECT mode
{
case 1:
SetRasterOp(RMXORPEN);
DrawRect(l,t,w,h,RGB(255,255,255));
SetRasterOp(RMCOPYPEN);
case 2:
SetRasterOp(RMXORPEN);
Ellipse(l,t,w,h,RGB(255,255,255));
SetRasterOp(RMCOPYPEN);
}
w = x - l;
h = y - t;
SELECT mode
{
case 0:
LineTo(x,y);
case 1:
SetRasterOp(RMXORPEN);
DrawRect(l,t,w,h,RGB(255,255,255));
SetRasterOp(RMCOPYPEN);
case 2:
SetRasterOp(RMXORPEN);
Ellipse(l,t,w,h,RGB(255,255,255));
SetRasterOp(RMCOPYPEN);
}
}
return true;
}

DrawWnd::OnLButtonDown(int x,int y,int flags),int
{
l = x;
t = y;
w = 0;
h = 0;
Move(l,t);
IF mode = 3
StartTimer(10);
IF mode = 4
FloodFill(l,t,drawcolor);
return true;
}

DrawWnd::OnLButtonUp(int x,int y,int flags),int
{
Select mode
{
CASE 1:
DrawRect(l,t,x-l,y-t,drawcolor,drawcolor);
CASE 2:
Ellipse(l,t,x-l,y-t,drawcolor,drawcolor);
CASE 3:
StopTimer();
}
return true;
}

DrawWnd::OnRButtonUp(int x,int y,int flags),int
{
menu m;
m.BeginContextMenu();
m.MenuItem("Color",0,99);
m.MenuItem( "Clear",0,1);
m.BeginPopup( "Line Size");
m.MenuItem( "1",(linesize = 1) * AMF_CHECKED,2);
m.MenuItem( "2",(linesize = 2) * AMF_CHECKED,3);
m.MenuItem( "3",(linesize = 3) * AMF_CHECKED,4);
m.MenuItem( "4",(linesize = 4) * AMF_CHECKED,5);
m.EndPopup();
m.EndMenu();
ShowContextMenu(m.m_hMenu,x,y);

return true;
}

DrawWnd::OnMenuPick(int nID),int
{
int w,h;
unsigned int hBitmap;
string filter;
string filename;
rect rcClient;
//clear the window
IF(nID = 1)
{
//GETSCREENSIZE w,h
w = GetSystemMetrics(0);
h = GetSystemMetrics(1);
DrawRect(0,0,w,h,RGB(255,255,255),RGB(255,255,255));
}
//set line size
IF(nID > 1 & nID < 6)
{
SetLineStyle(LSSOLID, nID - 1);
linesize = nID - 1;
}
//pick a tool
IF(nID > 5 & nID < 11)
{
mode = nID - 6;
}
//'pick a color
IF(nID = 99)
{
temp = drawcolor;
drawcolor = ColorRequest(this,drawcolor);
IF(drawcolor = -1)
drawcolor = temp;
FrontPen(drawcolor);
}
//quit
IF nID = 100
{
run = 0;
}
//print
IF nID = 101
{
//to be implimented
}
//save the image
IF nID = 102
{
filter = "Bitmap Files (*.bmp)|*.bmp||";
filename = FileRequest("Save Bitmap",this,0,filter,"bmp");
if len(filename)
{
rcClient = GetClientRect();
//SaveBitmap(filename,mywin,bml,bmt,bmw,bmh)
}
}
//load a btimap
IF nID = 103
{
filter = "Bitmap Files (*.bmp)|*.bmp||";
filename = FILEREQUEST("Load Bitmap",this,1,filter,"bmp");
if len(filename)
{
//hbitmap = loadimage(filename,0);
//if hbitmap
//{
// w = GetSystemMetrics(0);
// h = GetSystemMetrics(1);
// DrawRect(0,0,w,h,RGB(255,255,255),RGB(255,255,255));
// getbitmapsize hbitmap,bmw,bmh
// showimage mywin,hbitmap,0,0,0,bmw,bmh
// deleteimage hbitmap,0
//}
}
}
return true;
}

DrawWnd::OnMenuInit(unsigned int hMenu),int
{
menu m;
m.Attach(hMenu);
m.CheckMenuItem(6,(mode = 0));
m.CheckMenuItem(7,(mode = 1));
m.CheckMenuItem(8,(mode = 2));
m.CheckMenuItem(9,(mode = 3));
m.CheckMenuItem(10,(mode = 4));
m.CheckMenuItem(2,(linesize = 1));
m.CheckMenuItem(3,(linesize = 2));
m.CheckMenuItem(4,(linesize = 3));
m.CheckMenuItem(5,(linesize = 4));
m.Detach();
return false;
}

DrawWnd::OnTimer(int nIDEvent),int
{
float temp,temp2,out1,out2;
int x;
for( x = 0; x < 10;x++)
{
temp = RND(360) * (3.1415/180.0);
temp2 = RND(10);
out1 = SIN(temp) * temp2;
out2 = COS(temp) * temp2;
SetPixel(tempx+out1,tempy+out2);
}
return true;
}
Ionic Wind Support Team