-
May 8th, 2014, 09:14 AM
#1
FLTK, creating a rounded box
Hi guys,
The problem says: Draw a box with rounded corners. Define a class Box, consisting of four lines and four arcs.
So I wrote the below code for that exercise:
Code:
#include <Simple_window.h>
Simple_window win(Point(100,100), 600,400, "semi-ellipse");
struct Box: Shape{
Box(Point p, int ww, int hh): w(ww), h(hh)
{ add(Point(p.x-ww,p.y-hh)); }
void d_l() const //creating 4 lines
{
Line hrz1 (Point(150,100), Point(400,100));
Line hrz2 (Point(150,300), Point(400,300));
Line ver1 (Point(507,150), Point(507,250));
Line ver2 (Point(41,150), Point(41,250));
win.attach(hrz1);
win.attach(hrz2);
win.attach(ver1);
win.attach(ver2);
}
void draw_lines() const //creating 4 arcs
{
fl_arc(point(0).x,point(0).y,w,h,30,90);
fl_arc(point(0).x,point(0).y,w,h,270,330);
fl_arc(point(0).x,point(0).y,w,h,90,150);
fl_arc(point(0).x,point(0).y,w,h,210,270);
}
private:
int w;
int h;
};
int main()
{
using namespace Graph_lib;
Box b(Point(100,100),100,50);
win.attach(b);
win.wait_for_button();
}
When I ran it I faced this exception:
Unhandled exception at 0x757FE9D7 (ole32.dll) in test.exe: 0xC0000005: Access violation reading location 0x00000004.
I know this refers to declaring "Simple_window win(Point(100,100), 600,400, "semi-ellipse");" in global state. But I did that because I had to do it. The problem is that how to attach lines and also object (here b) to Simple_window win in either parts (main() function and also Box struct).
-
May 9th, 2014, 02:18 AM
#2
Re: FLTK, creating a rounded box
Have a look here: http://www.stroustrup.com/Programming/12_display.ppt
Apparently there is a "Polygon" class in FLTK. Take a look at the source code of the Polygon class, and try to design your "rounded box" using the same method. Also, as you see in the PPT, there is absolutely no need to declare Simple_window as a global variable.
Nobody cares how it works as long as it works
-
May 10th, 2014, 12:29 AM
#3
Re: FLTK, creating a rounded box
No, I should draw my rounded box using the fl_arc() function. Because the exercise before it had wanted us to work with fl_arc(). There should be a way apart from getting into source codes (of classes).
-
May 12th, 2014, 03:30 AM
#4
Re: FLTK, creating a rounded box
Yes, what I mean is that you should look at how the Polygon class is designed, and then make your own class, very similar to the Polygon class, but of course using fl_arc.
Nobody cares how it works as long as it works
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|