Basic use of Agg_slider_ctrl in the CTRL directory

Source: Internet
Author: User

Introduction:

In the Agg/examples directory, many examples are provided with scroll bars, and through the scroll bar, you can dynamically see the image color gradient process. So a bit of Agg::slider_ctrl tool class.

Graphics:

/*

* (X2,Y2)

*     *

*             *

*                 *

*                       *

*                           *

*                               *

*                                     *

(x1,y1) ************************************** (x2,y1)

*/

Function:

constructor Function: Slider_ctrl (double x1, double y1, doublex2, double y2, bool flip_y= false)

M_slider1.range (1, +);// Set the value range of the scroll bar

M_slider1.num_steps (x);// Set the width of the scroll bar,

M_slider1.value (1.0);// Set initial value

M_slider1.label ("Pixel size=%1.0f");// Display the value of the current scroll bar

M_slider1.no_transform ();//Do not allow scaling

int Nscalex =m_slider1.value ();// get current value



1) Add header file

#include "Agg/include/ctrl/agg_slider_ctrl.h"

2) Definition:

Agg::slider_ctrl<agg::rgba8> M_slider1;

3) Add to Event response list

Add to the Windows platform example:

Add_ctrl (M_slider1);

/*

Add the control element to the event listener list with the above function, when the mouse or keyboard event occurs

, it is passed to the control, which determines whether it belongs to its own event (whether or not it is sliding the scrollbar).

By annotating the function, the author realizes that the slide progress bar is not reflected.

*/

4) Render Control

Agg::render_ctrl (RAS, SL, RENB, m_slider1);

5) because the code is placed in the On_draw, you need to forcibly refresh

Force_redraw ();


Examples of simple applications are as follows:

#include "Agg/include/agg_basics.h"

#include "agg/include/agg_conv_curve.h"

#include "agg/include/agg_trans_perspective.h"

#include "agg/include/agg_renderer_scanline.h"

#include "Agg/include/agg_rendering_buffer.h"

#include "Agg/include/agg_rasterizer_scanline_aa.h"

#include "Agg/include/agg_scanline_u.h"

#include "Agg/include/agg_pixfmt_rgb.h"

#include "Agg/include/platform/agg_platform_support.h"

#include "agg/include/agg_ellipse.h"

#include "Agg/include/agg_conv_contour.h"

#include "agg/include/agg_conv_stroke.h"

#include "agg/include/agg_renderer_base.h"

#include "agg/include/agg_path_storage.h"

#include "agg/include/ctrl/agg_slider_ctrl.h"


Class The_application:public agg::p latform_support

{

Public


The_application (agg::p ix_format_e format, bool flip_y): agg::p latform_support (format,flip_y), Pix_fmt (Rbuf_window () ), Ren_bas (PIX_FMT),

M_slider1 (600-10, 276,!flip_y),

{

Add_ctrl (M_slider1);


M_slider1.range (1.0, 100.0);

M_slider1.num_steps (10);

M_slider1.value (1.0);

M_slider1.label ("Pixel size=%1.0f");

M_slider1.no_transform ();


}



void Draw_ellipse ()

{

The block of memory rendered by Rendering buffer is the color memory block of the interface that is about to be displayed, where Agg::rendering_buffer

class provides a series of functions that directly manipulate the color of a coordinate point, such as row_ptr ();

Agg::rendering_buffer &rbuf = Rbuf_window ();

Agg::p ixfmt_bgr24 pixf (RBUF);

Agg::rgba8 color (255,0,0);

Agg::rgba c (344,1);



Renderers renderer, we can be seen as paints, pigments,

typedef agg::renderer_base<agg::p ixfmt_bgr24> renderer_base_type;

Renderer_base_type Renb (PIXF);



Scanline Rasterizer Rasterization, said she was the album, describing all we were about to portray patterns, colors, lines,

But it is not true, because she is just a container, a specification that records line segments, signs, detailed parameters,

Not even a sketch, she was more like a cookbook, which recorded the ingredients and recorded the cooking process, that's all.

Agg::rasterizer_scanline_aa<> RAS;

AGG::SCANLINE_U8 SL;

Ren_bas.clear (Agg::rgba8 (255,255,255));



int Nscalex = 0;

int Nscaley = 0;

AGG::p ath_storage PS;

Ps.move_to (300,300);

Ps.line_to (320,300);

Ps.line_to (320,320);

Ps.line_to (300,320);

Ps.line_to (300,300);


Nscalex = Int (M_slider1.value ())/10;

Nscaley = Int (M_slider2.value ())/10;

Agg::trans_affine MTX;

Mtx.scale (Nscalex,nscaley); The x-axis shrinks to half the original.

Mtx.rotate (agg::d Eg2rad (40));//Rotate 30 degrees

Mtx.translate ( -320* (nScaleX-1), -320* (nScaleY-1)), and//x,y coordinates are shifted by 100 respectively.

typedef agg::conv_transform<agg::p ath_storage> ell_ct_type;

Ell_ct_type Ctell (PS,MTX); Matrix transformations


typedef agg::conv_stroke<ell_ct_type> ELL_CC_CS_TYPE;

Ell_cc_cs_type Csccell (Ctell);

Ras.add_path (Csccell);

Agg::render_scanlines_aa_solid (Ras,sl,renb,agg::rgba8 (255,0,0));

Ras.reset ();


Render the controls

Agg::render_ctrl (RAS, SL, RENB, m_slider1);

Return

}


virtual void On_draw ()

{

Draw_ellipse ();

}


virtual void On_mouse_button_down (int x, int y, unsigned flags)

{

if (flags = = Agg::mouse_left)

{

Char str[50];

sprintf (str, "Mouse location: (%d,%d)", X, y);

Message (STR);

}

}


Private


Agg::slider_ctrl<agg::rgba8> M_slider1;

Agg::p ixfmt_rgb24 pix_fmt;

Agg::renderer_base<agg::p ixfmt_rgb24> Ren_bas;

};




int agg_main (int argc, char* argv[])

{

The_application app (agg::p ix_format_bgr24,false);

App.caption ("AGG example.anti_aliasing Demo");


if (App.init (1800, 1800, agg::window_resize))

{

return App.run ();

}


return-1;

}




Basic use of Agg_slider_ctrl in the CTRL directory

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.