Flower: Painted Flower Procedure

xiaoxiao2021-03-05  24

Flower: Painted Flower Procedure

Source code:

http://blog.9cbs.net/cxjddd/archive/2005/04/12/344844.aspx

Flower is a program that simulates the gear drawing board that can draw the geometry of the rule. actual

On, the resulting graph is controlled by three parameters: the large circular radius, the small circle radius, and the distance from the brush to the small center.

Alternatively, the small circle can be placed outside the large circle to obtain different results. This program uses GTK 2.0

Write, very simple.

First, the interface consists. The left side of the program window is the output window, that is, the picture drawing is displayed;

Number and control buttons. The above three fine tuning buttons (text boxes) represent the large circular radius, small circle radius and painting

The pen distance; the following is two switch buttons, the first one can make the small circle outside the big circle, the second makes the graphics

Mounted to the appropriate window size.

Second, the window layout. The output window on the left is a "drawing area" Drawing_area (Type:

Gtkdrawingarea). The left side of the three parameter input box "Tag" label (Type:

GTKLABEL), and the input box is "fine tune button" spin_button (Type: gtkspinbutton);

The following two are "switch buttons" Toggle_Button (Type: gtktogglebutton). Host window

The mouth is a window (Type: gtkwindow).

First three spin_button and label should be connected in series with HBox; then with two

TOGGLE_BUTTON is connected in series with a VBox; use this VOBX to "align the control" Alignment

(Type: gtkalignment) is positioned in the upper right corner. Finally, put the left Drawing_Area with the right

The five buttons are connected in series with HBox and add them to the main window Window. Of course, pay attention to Box

Extended, fill the settings such as parameters in Pack, so that the interface is beautiful.

Third, the event handling. The main events of this program have Spin_Button's "Value-Changed",

Toggle_Button's "toggled", Drawing_Area's "Expose_Event", respectively

The value of Spin_Button changes, and the status of Toggle_Button changes and

Drawing_area needs to be re-painted. In addition, you need to handle some messages of the main window Window to make the way

The order can be exited normally.

For five buttons, the processing of messages is simple, just simply

GTK_WINDOW_INVALIDATE_RECT () to make Drawing_Area heavy (ie generated

"eXPOSE_EVENT").

Fourth, drawing. When the graphics are output, first obtain the size of the drawing area, GRAPHICS Contexts

Wait for information, then set black and clear the area, then set the white, and output the graphic in the way. Use

The function has GDK_DRAW_RECTANGLE (), GDK_GC_SET_RGB_FG_COLOR (),

GDK_DRAW_LINE (), etc. The types used include GDKCOLOR, GDKDRAWABLE, GDKGC, etc.

Five, the algorithm of the round cardboard. When the round palm is in the figure, it is a small circle to rotate in the big circle.

The move is moved to make a graphic. When processed by the program, the small circle and the big circle can be kept in each center, then turn the big circle, calculate the angle of small circle rotation; at this time, the large circle and the small circle

Rotate, you can reply to the usual situation.

Six, BOX assembly. The assembly style of three types of BOX is shared in this program.

Label and spin_button. HBOX is (False, 5) style when generating, so that

Label and spin_button can be left or right, and leave a certain interval. Label

Pack_Start (false, false, 0) assembly, aligned with left, and spin_button takes pack_end

(False, False, 0) Assembly, right alignment. This allows three controls.

2. Spin_Button and Toggle_Button. VBOX is generated (True, 5) to make each

There must be a distance between the controls. The first Toggle_Button is in assembly (True, True, 5),

To make two Toggle_Button look a little longer. Other controls (True, True, 0).

In addition, Vbox hangs in the upper right corner in an alignment.

3. Drawing_area and five buttons. HBOX is generated in (False, 5),

Drawing_area generates intervals between the buttons. Drawing_area is assembled (TRUE, TRUE, 0),

Button is assembled (False, False, 0). Such Drawing_Area can change with the window size

Synchronize.

转载请注明原文地址:https://www.9cbs.com/read-35576.html

New Post(0)