Created
October 2, 2011 11:54
-
-
Save torazuka/1257382 to your computer and use it in GitHub Desktop.
Chapter14_exercise5_PPPC++
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* 14章 練習問題5 */ | |
| #include "Simple_window.h" | |
| #include "Graph.h" | |
| struct Striped_rectangle : Shape { | |
| Striped_rectangle(Point xy, int ww, int hh) : w(ww), h(hh) | |
| { | |
| add(xy); | |
| if (h<=0 || w<=0) error("Bad rectangle: non-positive side"); | |
| } | |
| Striped_rectangle(Point x, Point y) : w(y.x-x.x), h(y.y-x.y) | |
| { | |
| add(x); | |
| if (h<=0 || w<=0) error("Bad rectangle: non-positive width or height"); | |
| } | |
| void draw_lines() const; | |
| int height() const { return h; } | |
| int width() const { return w; } | |
| private: | |
| int h; // height | |
| int w; // width | |
| }; | |
| void Striped_rectangle::draw_lines()const | |
| { | |
| if (fill_color().visibility()) { // fill | |
| fl_color(fill_color().as_int()); | |
| int const padding = 3; // 余白 | |
| int const line_height = 5; // ライン間の長さ | |
| int x_begin = point(0).x + padding; | |
| int x_end = x_begin + width() - padding; | |
| int y_begin = point(0).y + padding; | |
| int y_end = y_begin + height() - padding; | |
| for(int y = y_begin; y < y_end; y += line_height){ | |
| fl_line(x_begin, y, x_end, y); | |
| } | |
| fl_color(color().as_int()); // reset color | |
| } | |
| if (color().visibility()) { // lines on top of fill | |
| fl_color(color().as_int()); | |
| fl_rect(point(0).x,point(0).y,w,h); | |
| } | |
| } | |
| int main() | |
| { | |
| Simple_window win1(Point(50, 50), 800, 600, "Chapter14 Ex.5"); | |
| Striped_rectangle sr(Point(50, 50), 200, 100); | |
| sr.set_color(Color::white); // 白枠 | |
| sr.set_fill_color(Color::blue); // 青の縞で塗りつぶし | |
| win1.attach(sr); | |
| win1.wait_for_button(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment