We used igscrollbar, a scroll bar component, when doing igstatic. Now let's talk about its implementation method. Its structure is very simple: struct _ igscrollbar ...{
Const aeevtbl (igscrollbar) * PVT;
Uint32 m_nrefs;
Ishell * m_pishell;
Idisplay * m_pidisplay;
Imodule * m_pimodule;
Boolean m_isactive;
Aeerect m_rect;
Uint32 props;
Int min;
Int Max;
Int Pos;
Int Len;
};
That is, the length of a minimum min, maximum Max, current position POs, and positioning block Len.
What is the interface method? There are several configuration functions: aeeinterface (igscrollbar)
...{
Declare_ibase (igscrollbar)
Declare_icontrol (igscrollbar)
Void (* setrange) (igscrollbar * Po, int min, int max );
Void (* setposition) (igscrollbar * Po, int start, int end );
};
Let's look at the implementation code. Similarly, first look at handleevent processing and simply return false, because I use the scroll bar group as an auxiliary component and it does not process events by itself, it is only used to attach to other components.
In its redraw, all we need to do is display a horizontal or vertical rectangular bar and a small positioning block above: static Boolean igscrollbar_redraw (igscrollbar * PME)
...{
Aeerect R;
Idisplay_eraserect (PME-> m_pidisplay, & PME-> m_rect );
Idisplay_drawrect (PME-> m_pidisplay, & PME-> m_rect, make_rgb (0, 0),-1, idf_rect_frame );
If (PME-> props = gscroll_hor)
...{
Int X, W;
X = PME-> m_rect.x + PME-> m_rect.dx * (PME-> POS * 1000/PME-> MAX)/1000;
W = PME-> m_rect.dx * (PME-> Len * 1000/PME-> MAX)/1000;
Setaeerect (& R, X, PME-> m_rect.y, W, PME-> m_rect.dy );
}
Else
...{
Int y, h;
Y = PME-> m_rect.y + PME-> m_rect.dy * (PME-> POS * 1000/PME-> MAX)/1000;
H = PME-> m_rect.dy * (PME-> Len * 1000/PME-> MAX)/1000;
Setaeerect (& R, PME-> m_rect.x, Y, PME-> m_rect.dx, H );
}
Idisplay_fillrect (PME-> m_pidisplay, & R, make_rgb (0, 0 ));
Idisplay_update (PME-> m_pidisplay );
Return true;
}
The key issue is how to determine the size of the positioning block (that is, the Len value). The height of the horizontal scroll bar is fixed to the height of the bar, and the width is determined by the width of the content (max) the ratio to the mrect width of the scroll bar should be reflected in the width of the positioning block. The same applies to vertical scroll bars.