您好,登錄后才能下訂單哦!
引言:
在agg/examples目錄下,提供的很多例子都攜帶滾動條的,并且通過滾動條,可以動態看到圖像色彩的漸變過程。因此一下agg::slider_ctrl工具類。
圖形:
/*
*(x2,y2)
* *
* *
* *
* *
* *
* *
* *
(x1,y1)**************************************(x2,y1)
*/
函數:
構造函數:slider_ctrl(double x1, double y1, doublex2, double y2, bool flip_y=false)
m_slider1.range(1, 100);//設置滾動條的取值范圍
m_slider1.num_steps(10);//設置滾動條的步寬,
m_slider1.value(1.0);//設置初始值
m_slider1.label("Pixel size=%1.0f");//顯示當前滾動條的值
m_slider1.no_transform();//不允許縮放
int nScaleX =m_slider1.value();//獲取當前值
1)添加頭文件
#include "agg/include/ctrl/agg_slider_ctrl.h"
2)定義:
agg::slider_ctrl<agg::rgba8> m_slider1;
3)添加到事件響應列表
添加到windows platform例子中:
add_ctrl(m_slider1);
/*
通過上面的函數,將控件元素添加到事件監聽列表中,當鼠標或者鍵盤發生事件的時候
,會傳遞給該控件,由該控件判斷是否是屬于自己的事件(是否正在滑動滾動條)。
通過注釋該函數,作者可體會到,滑動進度條,沒有任何的反映。
*/
4)渲染控件
agg::render_ctrl(ras, sl, renb, m_slider1);
5)由于是把代碼放在on_draw,需要強行刷新
force_redraw();
簡單的應用例子如下:
#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::platform_support
{
public:
the_application(agg::pix_format_e format, bool flip_y):agg::platform_support(format,flip_y),pix_fmt(rbuf_window()),ren_bas(pix_fmt),
m_slider1(80, 250, 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()
{
//Rendering Buffer渲染的內存塊,就是即將顯示界面的顏色內存塊,其中agg::rendering_buffer
//類提供了一系列直接操作某一個坐標點顏色的函數,例如row_ptr();
agg::rendering_buffer &rbuf = rbuf_window();
agg::pixfmt_bgr24 pixf(rbuf);
agg::rgba8 color(255,0,0);
agg::rgba c(344,1);
//Renderers渲染器,我們可以看成是油漆,顏料,
typedef agg::renderer_base<agg::pixfmt_bgr24> renderer_base_type;
renderer_base_type renb(pixf);
//Scanline Rasterizer光柵化,說她是畫冊,描述了所有我們即將描繪圖案,顏色,線條,
//但是并不切確,因為她只是一個容器,一個記載線段,標志,詳細參數的規格說明書,
//連草圖都不是,她更像是一張菜譜,里面記錄了食材,記錄了烹飪的過程,僅此而已。
agg::rasterizer_scanline_aa<> ras;
agg::scanline_u8 sl;
ren_bas.clear(agg::rgba8(255,255,255));
int nScaleX = 0;
int nScaleY = 0;
agg::path_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); //x軸縮小到原來的一半
// mtx.rotate(agg::deg2rad(40));//旋轉30度
mtx.translate(-320*(nScaleX-1) ,-320*(nScaleY-1));//X,Y坐標分別平移100
typedef agg::conv_transform<agg::path_storage> ell_ct_type;
ell_ct_type ctell(ps,mtx); //矩陣變換
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::pixfmt_rgb24 pix_fmt;
agg::renderer_base<agg::pixfmt_rgb24> ren_bas;
};
int agg_main(int argc, char* argv[])
{
the_application app(agg::pix_format_bgr24,false);
app.caption("AGG Example.Anti_Aliasing Demo");
if (app.init(1800, 1800, agg::window_resize))
{
return app.run();
}
return -1;
}
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。