On 05/25/17 09:24, Osman Zakir wrote:
> > and for the bottom right corner 3 o'clock to 12 o'clock. Right?
> > Or is that completely wrong?
> No, bottom right would be 3 to 6.
>
> You said 9 to 12, so I drew an arc from 45 degrees to 360 degrees (start_deg=45, end_deg=360).
Hmm, where is 45 coming from?
The only angles you want will be 90 degree increments, not 45.
Which is to say 0, 90, 180, 270.
> I'm attaching the updated main.cpp to this message.
I can't actually build your main.cpp; getting too many errors from
the other files it includes, it's too much.. stuff.. to fix
to get it working.
I've reduced the original main.cpp you'd posted to a single file
so that there's no dependence on the book's numerous files.
Here I've simplified the fl_arc() commands to just:
fl_arc(x1, y1, m_radius, 90, 180); // top left (9 -> 12)
fl_arc(x2, y2, m_radius, 0, 90); // top right (12 -> 3)
fl_arc(x3, y3, m_radius, 270, 360); // bottom right (3 -> 6)
fl_arc(x4, y4, m_radius, 180, 270); // bottom left (6 -> 9)
I can't think why those angle values need variables; they'd only
ever be fixed values.
I changed some of the code so that the window can be resizable,
and scales the rectangle to follow the window dimensions. This tests
the rounded corners calculate properly no matter the dimensions of
the rectangle. The size of the rectangle is 66% of the window size,
and I replaced the magic offsets (like +81 and +130+72) with just
the radius (as that's all those arc offsets should ever be).
_____________________________________________________________________________
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/fl_draw.H>
typedef struct { int x, y; } Point;
class MyWindow : public Fl_Window {
public:
MyWindow(int X,int Y,const char *L) : Fl_Window(X,Y,L) { }
void draw() {
int m_height = h() * 0.66;
int m_width = w() * 0.66;
const int space = m_height / 10; // leave space for arcs
double m_radius = space; // ** radius should be same as "space for arcs"
Point m_tl{ m_width / 4, m_height / 4 };
// make the points
Point tr = m_tl;
tr.x += m_width; // top-right corner
Point br = tr;
br.y += m_height; // bottom-right corner
Point bl = br;
bl.x -= m_width; // bottom-left corner
// draw the lines
fl_line(m_tl.x + space, m_tl.y, tr.x - space, tr.y);
fl_line(tr.x, tr.y + space, br.x, br.y - space);
fl_line(br.x - space, br.y, bl.x + space, bl.y);
fl_line(bl.x, bl.y - space, m_tl.x, m_tl.y + space);
// draw the arcs
// TOP LEFT -- 9 o'clock (180deg) to 12 o'clock (90deg)
// fl_arc wants the values in ascending order, so 12-9
//
const double x1 = static_cast<double>(m_tl.x + m_radius);
const double y1 = static_cast<double>(m_tl.y + m_radius);
fl_begin_line();
fl_arc(x1, y1, m_radius, 90, 180);
fl_end_line();
// TOP RIGHT -- 12 o'clock (90deg) to 3 o'clock (0deg)
const double x2 = static_cast<double>(tr.x - m_radius);
const double y2 = static_cast<double>(tr.y + m_radius);
fl_begin_line();
fl_arc(x2, y2, m_radius, 0, 90);
fl_end_line();
// BOTTOM RIGHT -- 3 o'clock (0deg) to 6 o'clock (270deg)
const double x3 = static_cast<double>(br.x - m_radius);
const double y3 = static_cast<double>(br.y - m_radius);
fl_begin_line();
fl_arc(x3, y3, m_radius, 270, 360);
fl_end_line();
// BOTTOM LEFT -- 6 o'clock (270deg) to 9 o'clock (180deg)
const double x4 = static_cast<double>(bl.x + m_radius);
const double y4 = static_cast<double>(bl.y - m_radius);
fl_begin_line();
fl_arc(x4, y4, m_radius, 180, 270);
fl_end_line();
}
};
int main() {
MyWindow *win = new MyWindow(600,400,"Rounded-Corner Boxes");
win->end();
win->resizable(win);
win->show();
return Fl::run();
}
_____________________________________________________________________________