GIDForums  

Go Back   GIDForums > Computer Programming Forums > FLTK Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 24-Aug-2007, 05:27
nimeesh nimeesh is offline
New Member
 
Join Date: Aug 2007
Posts: 2
nimeesh is on a distinguished road
Question

Free Hand Drawing in FLTK


Hi All,
I'm new to fltk. I'm trying one assignment.
I want to provide the provision where i shuld be able to write on fltk window...
kind of free hand drawing with mouse...its like writing/ drawing on paper..

so lines are not straight ...it shuld appear as user moves the cursor..(like mspaint of windows)

Do i need to use Open GL or what exactly..

I want to know the start point for such application...

What & all things i shuould read to start with this...

Thanks in Advance..

Nimeesh
  #2  
Old 25-Aug-2007, 01:23
msephton msephton is offline
New Member
 
Join Date: Aug 2007
Posts: 2
msephton is on a distinguished road

Re: Free Hand Drawing in FLTK


You can do free hand drawing using openGL if you wish, or you can use the fltk drawing functions.
For both openGL and fltk, I can think of two approaches.
1) You can store data for each of the shapes or lines or points the user draws.
2) You could just allow the user to click on the screen to change the color of the pixel where the user clicks.
I attach a few examples:
freedraw1 (uses opengL and method 1)
freedraw11.cpp (uses openGL and method 2)
freedraw2.cpp (uses fltk drawing functions and method 1)
freedraw21 (uses fltk drawing functions and method 2)

--freedraw1-
CPP / C++ / C Code:
#include <FL/Fl.h>
#include <FL/Fl_Gl_Window.h>
#include <FL/gl.h>
struct point {
point(){x=0;y=0;}
int x;
int y;
};


class glwin : public Fl_Gl_Window {
public:
glwin(int x,int y,int w,int h,const char *lab=0):Fl_Gl_Window(x,y,w,h,lab){
index=0;
}

int handle(int event){

if(event==FL_PUSH){
return 1;
}
if(event==FL_DRAG){
points[index].x=Fl::event_x();
points[index].y=h()-Fl::event_y();
if(index<99)
index++;
else
index=0;
redraw();
}//drag
return Fl_Gl_Window::handle(event);
}

void draw(void){

glLoadIdentity();
glViewport(0,0,w(),h());
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,w(),0,h(),-1,1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClearColor(1.0,1.0,1.0,1.0);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

glBegin(GL_LINE_STRIP);
gl_color(FL_BLACK);
for(int i=0;i<100;i++)
glVertex2i(points[i].x,points[i].y);

glEnd();

}

int index;
point points[100];

};


int main(void){
glwin g1(0,0,300,300);

g1.show();
return Fl::run();

}//int main

--freedraw11--
CPP / C++ / C Code:
#include <FL/Fl.h>
#include <FL/Fl_Gl_Window.h>
#include <FL/gl.h>
struct point {
point(){x=0;y=0;}
int x;
int y;
};


class glwin : public Fl_Gl_Window {
public:
glwin(int x,int y,int w,int h,const char *lab=0):Fl_Gl_Window(x,y,w,h,lab){
index=0;
for(int i=0;i<300;i++)
for(int j=0;j<300;j++)
points[i][j]=FL_BLACK;

}

int handle(int event){

if(event==FL_PUSH){
return 1;
}
if(event==FL_DRAG){
int x=Fl::event_x();
int y=h()-Fl::event_y();
points[x][y]==FL_BLACK ? points[x][y]=FL_WHITE : points[x][y]=FL_BLACK;
redraw();

}//drag
return Fl_Gl_Window::handle(event);
}

void draw(void){
glLoadIdentity();
glViewport(0,0,w(),h());
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,w(),0,h(),-1,1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClearColor(1.0,1.0,1.0,1.0);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

glBegin(GL_POINTS);
for(int i=0;i<300;i++)
for(int j=0;j<300;j++){
gl_color(points[i][j]);
glVertex2i(i,j);
}

glEnd();
}

int index;
Fl_Color points[300][300];
};


int main(void){
glwin g1(0,0,300,300);
g1.show();
return Fl::run();

}//int main

--freedraw2--
CPP / C++ / C Code:
#include <FL/Fl.h>
#include <Fl/Fl_Window.h>
#include <Fl/fl_draw.h>

struct point {
point(){x=0;y=0;}
int x;
int y;
};

class canvas : public Fl_Window {
public:
canvas(int x,int y,int w,int h,const char *lab=0) : Fl_Window(x,y,w,h,lab){
index=0;
end();
}

int handle(int event){
if(event==FL_PUSH){
return 1;
}
if(event==FL_DRAG){
points[index].x=Fl::event_x();
points[index].y=Fl::event_y();
if(index<99)
index++;
else
index=0;
redraw();
}//drag

}//handle

void draw(void){
Fl_Window::draw();
fl_color(FL_BLACK);
for(int i=0;i<99;i++)
fl_line(points[i].x,points[i].y,points[i+1].x,points[i+1].y);
}//draw

int index;
point points[100];
};


int main(void){

canvas c(0,0,300,300);
c.show();
return Fl::run();
}


--freedraw21--
CPP / C++ / C Code:
#include <FL/Fl.h>
#include <Fl/Fl_Window.h>
#include <Fl/Fl_Double_Window.h>
#include <Fl/fl_draw.h>

struct point {
point(){x=0;y=0;}
int x;
int y;
};


class canvas : public Fl_Double_Window {
public:
canvas(int x,int y,int w,int h,const char *lab=0) : Fl_Double_Window(x,y,w,h,lab){
index=0;
for(int i=0;i<300;i++)
for(int j=0;j<300;j++)
points[i][j]=FL_BLACK;
end();
}

int handle(int event){
if(event==FL_PUSH){
return 1;
}
if(event==FL_DRAG){
int x=Fl::event_x();
int y=Fl::event_y();
points[x][y]==FL_BLACK ? points[x][y]=FL_WHITE : points[x][y]=FL_BLACK;
redraw();
}//drag
return Fl_Double_Window::handle(event);
}

void draw(void){
Fl_Double_Window::draw();
fl_color(FL_BLACK);
for(int i=0;i<300;i++)
for(int j=0;j<300;j++)
fl_color(points[i][j]),fl_point(i,j);


}

Fl_Color points[300][300];

};


int main(void){

canvas c(0,0,300,300);
c.show();
return Fl::run();
}
  #3  
Old 31-Aug-2007, 02:58
nimeesh nimeesh is offline
New Member
 
Join Date: Aug 2007
Posts: 2
nimeesh is on a distinguished road

Re: Free Hand Drawing in FLTK


thanks a lot ..
its same thing what i looking for..
 
 

Recent GIDBlogMeeting the local Iraqis by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Resellers w/FREE BILLING SYSTEM from $2.60! Shared Hosting w/SiteBuilder from $1.25!! my-e-space Web Hosting Advertisements & Offers 0 04-Jun-2006 20:29
Hip Hop and All kinds of New Beats Heard on This Site>>> hiphop2006 Music Forum 0 08-Mar-2006 18:47

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 11:44.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.