Laxkit  0.0.7.1
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes
Laxkit::RulerWindow Class Reference

A ruler that tracks the mouse. More...

Inheritance diagram for Laxkit::RulerWindow:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 RulerWindow (anXWindow *parnt, const char *nname, const char *ntitle, unsigned long nstyle, int xx, int yy, int ww, int hh, int brder, anXWindow *prev=NULL, unsigned long nowner=0, const char *nsend=NULL, const char *base_units=NULL, int syncwithscreen=1)
virtual ~RulerWindow ()
 Destructor.
virtual int init ()
 Create a pixmap to hold what's behind the moving bar.
virtual int Event (const EventData *e, const char *mes)
virtual void Refresh ()
 Refresh.
virtual int MoveResize (int nx, int ny, int nw, int nh)
virtual int Resize (int nw, int nh)
virtual int MouseMove (int x, int y, unsigned int state, const LaxMouse *m)
virtual int LBDown (int x, int y, unsigned int state, int count, const LaxMouse *d)
virtual int RBDown (int x, int y, unsigned int state, int count, const LaxMouse *d)
virtual int RBUp (int x, int y, unsigned int state, const LaxMouse *d)
 Call up a menu to choose units from.
virtual int SetBaseUnits (const char *units)
virtual int SetBaseUnits (int units)
 Calls to the various SetPos() and Set() commands are assumed to be in base units, but are displayed in current units.
virtual int SetCurrentUnits (const char *units)
 Calls to the various SetPos() and Set() commands are assumed to be in base units, but are displayed in current units.
virtual int SetCurrentUnits (int units)
virtual int SetDivisions (int sdiv, int ssdiv)
 Set the number of subdivisions and subsubdivions for the current units.
virtual void TrackThisWindow (anXWindow *win)
 Automatically set screenoffset based on win.
virtual void Track ()
 Set pos from where the mouse is semi-manually, by querying the pointer(s).
virtual void SetPos (double crpos)
 Set the ruler position to be real number crpops.
virtual void SetPosFromScreen (int p)
 Set position based on screen coordinate p, rulerwindow coordinates.
virtual void SetPosFromScreenCoord (int x, int y)
 Set position based on whole screen coordinate (x,y).
virtual void SetMag (double nmag)
 Set magnification, (screen) = mag * (real)
virtual void Zoom (double f)
 mag*=f, keeps start at the same position.
virtual void Set (double strt)
 Set start=str, and compute end based on new start and mag.
virtual void Set (double strt, double fin)
 Set start=strt, and end=fin, mag is calculated from that.
virtual void SetOrigin (int o)
 Set the origin with position o, assuming o is in window coordinates of trackwindow.
virtual void AddRange (int id, double start, double end)
 Add a range to indicate within the ruler. UNIMPLEMENTED!!
virtual LaxFiles::Attributedump_out_atts (LaxFiles::Attribute *att, int what, anObject *context)
virtual void dump_in_atts (LaxFiles::Attribute *att, int flag, anObject *context)
- Public Member Functions inherited from Laxkit::anXWindow
 anXWindow (anXWindow *parnt, const char *nname, const char *ntitle, unsigned long nstyle, int xx, int yy, int ww, int hh, int brder, anXWindow *prev, unsigned long nowner, const char *nsend)
 Constructor.
virtual ~anXWindow ()
 anXWindow destructor. Its X window should have been XDestroy'd before here.
virtual const charwhattype ()
virtual const charWindowTitle (int which=0)
 Return basically the name of the window.
virtual void WindowTitle (const char *newtitle)
 Change the title of the window. This text would usually be displayed in the bar provided by a window manager.
virtual const chartooltip (int mouseid=0)
 By default, return win_tooltip.
virtual const chartooltip (const char *newtooltip)
 Replace the current tooltip, return the current tooltip (after replacing).
virtual anXWindowfindChildWindowByTitle (const char *title)
 Find the first immediate child window that has win_title==title.
virtual anXWindowfindChildWindowByName (const char *name)
 Find the first immediate child window that has win_name==name.
virtual int Grayed ()
 Return whether this window is grayed.
virtual int Grayed (int g)
 Set the gray state of this window. Returns Grayed(void).
virtual int preinit ()
virtual int close ()
 Called by anXApp from anXApp::destroywindow() when a window is to be destroyed.
virtual int Idle (int tid=0)
 anXWindow::Idle() is an empty placeholeder. Just returns 1.
virtual DisplayerMakeCurrent ()
virtual int Needtodraw ()
 Default is to return needtodraw.
virtual void Needtodraw (int nntd)
 If 0, then the window does not need refreshing. Otherwise it does.
virtual int deletenow ()
 Return whether the window is allowed to be deleted.
virtual int setWinStyle (unsigned int stylebit, int newvalue)
 Control various window related basic styling of win_style.
virtual int getWinStyle (unsigned int stylebit)
 Currently, simply return win_style&stylebit.
virtual void installColors (WindowColors *newcolors)
 Dec_count old and inc_count new.
virtual ShortcutHandlerGetShortcuts ()
 Return a ShortcutHandler that contains stacks of bound shortcuts and possible window actions.
virtual int PerformAction (int action_number)
virtual int ExposeChange (ScreenEventData *e)
 Default behavior on Expose events is to call Needtodraw(1).
virtual int DeviceChange (const DeviceEventData *e)
virtual int CharInput (unsigned int ch, const char *buffer, int len, unsigned int state, const LaxKeyboard *kb)
 Input of character data or control character presses.
virtual int KeyUp (unsigned int ch, unsigned int state, const LaxKeyboard *kb)
 Called when a key is released.
virtual int ButtonDown (int button, int x, int y, unsigned int state, int count, const LaxMouse *m)
virtual int ButtonUp (int button, int x, int y, unsigned int state, const LaxMouse *m)
virtual int LBUp (int x, int y, unsigned int state, const LaxMouse *d)
 Default is just to return 1.
virtual int MBDown (int x, int y, unsigned int state, int count, const LaxMouse *d)
 Default is just to return 1.
virtual int MBUp (int x, int y, unsigned int state, const LaxMouse *d)
 Default is just to return 1.
virtual int WheelUp (int x, int y, unsigned int state, int count, const LaxMouse *d)
 The wheel mouse rolling up. Default is just to return 1.
virtual int WheelDown (int x, int y, unsigned int state, int count, const LaxMouse *d)
 The wheel mouse rolling down. Default is just to return 1.
virtual int FocusOn (const FocusChangeData *e)
 Increment win_active, and highlights the window's border, if the event refers to this window.
virtual int FocusOff (const FocusChangeData *e)
 Decrements win_active, and de-highlights the window's border if win_active==0, if event is a real focus off.
virtual void contentChanged ()
 Windows may call this when their contents change.
virtual void selectionChanged ()
 Windows may call this when their selections change.
virtual anXWindowGetController ()
 Return the window most relevant for tab control loops.
virtual int SelectNextControl (const LaxDevice *d)
 Transfer focus to nextcontrol.
virtual int SelectPrevControl (const LaxDevice *d)
 Transfer the focus to prevcontrol.
virtual void ControlActivation (int on)
 Do special activation or not when controls are activated by tabbing.
virtual int AddPrevControl (anXWindow *prev)
virtual int AddNextControl (anXWindow *next)
virtual int ConnectControl (anXWindow *towhat, int after=1)
 Connect towhat to this. Used for tab loops.
virtual int CloseControlLoop ()
 Close a tab loop.
virtual void SetOwner (anXWindow *nowner, const char *mes=NULL, unsigned int send_mask=0)
 Set the new owner and control message.
virtual void SetOwner (unsigned long nowner_id, const char *mes=NULL, unsigned int send_mask=0)
virtual void dump_out (FILE *f, int indent, int what, anObject *context)
 Simple dumping function.
- Public Member Functions inherited from Laxkit::Tagged
virtual int HasTag (const char *tag, int casematters)
 Return whether the tag exists.
virtual int NumberOfTags ()
 Return the number of tags, strangely enough.
virtual const charGetTag (int i)
 Return const pointer to the tag text for tag number i, where i==0 is the first tag.
virtual charGetAllTags ()
 Return a new char[] with a space separated list of all the tags.
virtual int InsertTags (const char *tags, int casematters)
 Insert tags from a string such as 'tag1 tag2 tag3 "tag with spaces" tag4'.
virtual int InsertTag (const char *tag, int casematters)
 Insert tag if it doesn't exist already.
virtual int RemoveTag (const char *tag)
 The tag must be an exact match.
virtual int RemoveTag (int i)
 Remove tag number i. i must be in range [0..NumberOfTags()-1].
virtual void FlushTags ()
- Public Member Functions inherited from LaxFiles::DumpUtility
virtual void dump_in (FILE *f, int indent, int what, Laxkit::anObject *loadcontext, Attribute **att)
 Read in a file segment as an Attribute, and pass parsing duties to dump_in_atts.
virtual ~DumpUtility ()
 Empty virtual destructor.
- Public Member Functions inherited from Laxkit::aDrawable
 aDrawable (Drawable d=0)
virtual int DrawableType ()
virtual int ValidDrawable ()

Public Attributes

unsigned long bgcolor
unsigned long numcolor
unsigned long tickcolor
unsigned long curposcolor
unsigned long subtickcolor
unsigned long subsubtickcolor
double base
 The base of the numbering. 12 for standard, 10 for metric.
double unit
 The current size of a single unit in real coordinates.
double curpos
 The current position in real coordinates ((real-start)*mag=screen).
int subdiv
 The main subdivision of the current unit.
int subsubdiv
 The divisions of the subdivisions.
int screenoffset
 Distance that the ruler is offset from the trackwindow. (ruler-tracked)
- Public Attributes inherited from Laxkit::anXWindow
WindowColorswin_colors
anXAppapp
charwin_name
 An arbitrary string to be used as an id.
charwin_title
 The title of the window.
anXWindowwin_parent
int win_screen
unsigned long win_style
int win_x
int win_y
int win_w
int win_h
unsigned int win_border
int win_pointer_shape
 Identifier for a stock mouse shape.
char win_on
 Nonzero if the window is mapped.
char win_active
 Should be positive when the window has a keyboard focus, 0 otherwise.
unsigned long win_owner
 Who gets control messages from this window.
unsigned int win_owner_send_mask
charwin_sendthis
 The type of message that gets sent to owner.
anXWindownextcontrol
anXWindowprevcontrol
- Public Attributes inherited from Laxkit::Tagged
int sorttags

Protected Member Functions

virtual void adjustmetrics ()
 Ensures that there are enough whole ticks on the screen.
virtual void drawtext (double n, int pos, int &textpos, int toff)
 Draw the number labels every unit, taking steps to not overlap labels.
virtual int NumberOfUnits ()
 By default use GetUnitManager() to find a units manager.
virtual int UnitInfo (int index, const char **name, int *id, double *scale, int *sdiv, int *ssdiv)
 Return positive for info found, or 0 for not found.
- Protected Member Functions inherited from Laxkit::anXWindow
virtual int deletekid (anXWindow *w)
 Purges child anXWindows from window's child stack.
virtual void SwapBuffers ()
 Swap buffers. This should be called from Refresh() if VIEWPORT_BACK_BUFFER is set in win_style.
virtual void SetupBackBuffer ()
 Initialize the backbuffer.

Protected Attributes

double start
 The real starting point in the window.
double end
 The real ending point in the window.
double mag
 The current magnification (real*mag=screen).
double umag
 Scaling between baseunits and currentunits.
double tf
 The fraction of the window taken up by unit ticks.
double stf
 The fraction of the window taken up by sub-unit ticks.
double sstf
 The fraction of the window taken up by sub-sub-unit ticks.
anXWindowtrackwindow
 The window in which mouse movements are tracked.
LaxFontsmallnumbers
int baseunits
int currentunits
- Protected Attributes inherited from Laxkit::anXWindow
charwin_tooltip
 Convenience variable to hold the window's tooltip, if any.
int needtodraw
RefPtrStack< anXWindow_kids
 Stack of children of the window.
- Protected Attributes inherited from Laxkit::Tagged
PtrStack< charlist_of_tags

Detailed Description

A ruler that tracks the mouse.

You can use a standard ruler, which draws ticks on 12's and halves, or metric which draws ticks by tens and 5's and 1's. The ruler can be vertical or horizontal, with the ticks on the left, center, or right, and top, center or bottom.

This class uses GetUnitManager() to coordinate units.

Ticks are displayed by order of magnitude grouping. That is, say you have ticks every real unit, and base is 10****

Screen Units == mag * (Real Units)
Current Units == umag * (Base Units)
Pixel length of the space between smallest drawn divisions: mag*unit/umag/subdiv/subsubdiv
Pixel length between drawn subdivs: mag*unit/umag/subdiv
Pixel length between drawn units: mag*unit/umag

When magnification makes units grow so much that the subsubdivs have enough space for subdiv*subsubdiv number of ticks, then set unit to that smallest space (==unit/subdiv/subsubdiv).

Todo:

***optionally make vertical writing on the vertical ruler

could make ruler automatically track mouse with mouseposition() every 10ms or so or respond to sent mouse move messages, and mouseposition() to get location...

should be able to move position when mouse is in this window!!!

placeable range indicators

#define RULER_X (1<<16)
#define RULER_Y (1<<17)
#define RULER_TOPTICKS (1<<18)
#define RULER_LEFTTICKS (1<<18)
#define RULER_BOTTOMTICKS (1<<19)
#define RULER_RIGHTTICKS (1<<19)
#define RULER_CENTERTICKS (1<<20)
#define RULER_NONUMBERS (1<<21)
// defaults to standard,
// Standard: one basic unit is 1 inch, divided in halves, base=12,
// Metric is 1 whatever, divided in 10 portions, with a slightly bigger tick for the middle
#define RULER_STANDARD (1<<22)
#define RULER_METRIC (1<<23)
// send message when button down, and mouse leaves ruler
#define RULER_SENDONLBD (1<<24)
#define RULER_SENDONMBD (1<<25)
#define RULER_SENDONRBD (1<<26)
#define RULER_UP_IS_POSITIVE (1<<27)

Constructor & Destructor Documentation

Laxkit::RulerWindow::RulerWindow ( anXWindow parnt,
const char nname,
const char ntitle,
unsigned long  nstyle,
int  xx,
int  yy,
int  ww,
int  hh,
int  brder,
anXWindow prev = NULL,
unsigned long  nowner = 0,
const char nsend = NULL,
const char base_units = NULL,
int  syncwithscreen = 1 
)

If base_units!=NULL, then use those units. By default, known units are "Inches", "Feet", "cm", "mm", "Meters", "Points", "Pixels", and the default is inches.

Todo:
If syncwithscreen, then based on the given units, try to set up so that units make sense on the given screen.

References base, Laxkit::coloravg(), curpos, Laxkit::SimpleUnit::DefaultUnits(), end, Laxkit::GetUnitManager(), Laxkit::anXWindow::installColors(), mag, Laxkit::FontManager::MakeFont(), Laxkit::rgbcolor(), screenoffset, sstf, start, stf, subdiv, subsubdiv, tf, trackwindow, umag, unit, and Laxkit::SimpleUnit::UnitInfo().


Member Function Documentation

void Laxkit::RulerWindow::AddRange ( int  id,
double  start,
double  end 
)
virtual

Add a range to indicate within the ruler. UNIMPLEMENTED!!

Todo:
do me!

AddRange() establishes, RemoveRange() removes.. maybe optionally mouse over to show bounds in ruler... maybe also set range color..

void Laxkit::RulerWindow::drawtext ( double  n,
int  pos,
int textpos,
int  toff 
)
protectedvirtual

Draw the number labels every unit, taking steps to not overlap labels.

textpos is the last screen coordinate drawn to by a drawtext() call.

Todo:
*** this could use some work, particularly, vertical rulers should employ vertical text

References Laxkit::getextent(), and Laxkit::textout().

Referenced by Refresh().

void Laxkit::RulerWindow::dump_in_atts ( LaxFiles::Attribute att,
int  flag,
anObject context 
)
virtual
Attribute * Laxkit::RulerWindow::dump_out_atts ( LaxFiles::Attribute att,
int  what,
anObject context 
)
virtual

Append to att if att!=NULL, else return a new Attribute whose name is whattype().

Default is to add attributes for "text", and whatever anXWindow adds.

Reimplemented from Laxkit::anXWindow.

References base, Laxkit::GetUnitManager(), LaxFiles::Attribute::push(), subdiv, subsubdiv, and Laxkit::SimpleUnit::UnitInfoId().

int Laxkit::RulerWindow::Event ( const EventData e,
const char mes 
)
virtual
void Laxkit::RulerWindow::Refresh ( )
virtual
void Laxkit::RulerWindow::Set ( double  strt)
virtual

Set start=str, and compute end based on new start and mag.

Does not change screenoffset.

References end, mag, screenoffset, and start.

Referenced by LaxInterfaces::ViewportWindow::syncrulers().

void Laxkit::RulerWindow::Set ( double  strt,
double  fin 
)
virtual

Set start=strt, and end=fin, mag is calculated from that.

Does not change screenoffset.

Todo:
*** does not adjust for screenoffset ***needs work

References end, mag, and start.

int Laxkit::RulerWindow::SetBaseUnits ( int  units)
virtual

Calls to the various SetPos() and Set() commands are assumed to be in base units, but are displayed in current units.

Return 0 for success, nonzero for error.

Current units are not changed.

References Laxkit::SimpleUnit::GetFactor(), Laxkit::GetUnitManager(), umag, and Laxkit::SimpleUnit::UnitInfoId().

int Laxkit::RulerWindow::SetCurrentUnits ( const char units)
virtual

Calls to the various SetPos() and Set() commands are assumed to be in base units, but are displayed in current units.

Return 0 for success or nonzero for units not found.

References Laxkit::GetUnitManager(), and Laxkit::SimpleUnit::UnitInfo().

Referenced by Event(), and LaxInterfaces::ViewportWindow::Event().

int Laxkit::RulerWindow::SetCurrentUnits ( int  id)
virtual

Return 0 for success or nonzero for units not found.

References adjustmetrics(), base, Laxkit::SimpleUnit::GetFactor(), Laxkit::GetUnitManager(), subdiv, subsubdiv, umag, unit, and Laxkit::SimpleUnit::UnitInfoId().

void Laxkit::RulerWindow::SetMag ( double  nmag)
virtual

Set magnification, (screen) = mag * (real)

Start remains the same value after the new magnification.

References end, mag, and start.

Referenced by LaxInterfaces::ViewportWindow::syncrulers().

void Laxkit::RulerWindow::SetPosFromScreen ( int  p)
virtual

Set position based on screen coordinate p, rulerwindow coordinates.

See also screenoffset.

References mag, screenoffset, SetPos(), and start.

Referenced by LaxInterfaces::ViewportWindow::MouseMove().

void Laxkit::RulerWindow::Track ( )
virtual

Set pos from where the mouse is semi-manually, by querying the pointer(s).

Todo:
*** this is unimplemented

References Laxkit::mouseposition(), and trackwindow.

Referenced by LaxInterfaces::ViewportWindow::syncrulers().

void Laxkit::RulerWindow::TrackThisWindow ( anXWindow win)
virtual

Automatically set screenoffset based on win.

Note that this does not set magnification, start or end.

References screenoffset, trackwindow, and Laxkit::translate_window_coordinates().

Referenced by LaxInterfaces::ViewportWindow::UseTheseRulers().


Member Data Documentation

double Laxkit::RulerWindow::base

The base of the numbering. 12 for standard, 10 for metric.

Units are grouped according to base in that there will be one chuck for every

It's usually a good idea for the base to be such that base/subdiv/subsubdiv is an integer.

Referenced by adjustmetrics(), dump_in_atts(), dump_out_atts(), Refresh(), RulerWindow(), and SetCurrentUnits().

int Laxkit::RulerWindow::screenoffset

Distance that the ruler is offset from the trackwindow. (ruler-tracked)

For horizontal rulers: screenoffset = rulerwindow_x - trackwindow_x;
For vertical rulers: screenoffset = rulerwindow_y - trackwindow_y;

Referenced by RulerWindow(), Set(), SetOrigin(), SetPosFromScreen(), SetPosFromScreenCoord(), and TrackThisWindow().

int Laxkit::RulerWindow::sstf
protected

The fraction of the window taken up by sub-sub-unit ticks.

Defaults to .5.

Referenced by Refresh(), and RulerWindow().

int Laxkit::RulerWindow::stf
protected

The fraction of the window taken up by sub-unit ticks.

Defaults to .75.

Referenced by Refresh(), and RulerWindow().

int Laxkit::RulerWindow::subdiv

The main subdivision of the current unit.

When subdiv is 2, for instance, then the base unit gets divided into 2 sections, with a tick of middle size placed in the middle.

Standard and metric both set this to 2.

Referenced by adjustmetrics(), dump_in_atts(), dump_out_atts(), Refresh(), RulerWindow(), SetCurrentUnits(), and SetDivisions().

int Laxkit::RulerWindow::subsubdiv

The divisions of the subdivisions.

Each subdivision is itself divided into this many sections. The smallest ticks demarcate the sections.

Standard has 4 subsubdivs, and metric has 5.

Referenced by adjustmetrics(), dump_in_atts(), dump_out_atts(), Refresh(), RulerWindow(), SetCurrentUnits(), and SetDivisions().

int Laxkit::RulerWindow::tf
protected

The fraction of the window taken up by unit ticks.

Defaults to 1.0.

Referenced by Refresh(), and RulerWindow().

double Laxkit::RulerWindow::umag
protected

Scaling between baseunits and currentunits.

currentunits = umag * baseunits

So to get screen coordinates for a currentunit of p: s=(p/umag-start)*mag;

Referenced by adjustmetrics(), Refresh(), RulerWindow(), SetBaseUnits(), and SetCurrentUnits().

int Laxkit::RulerWindow::unit

The current size of a single unit in real coordinates.

This value can change on magnification. It only specifies what real distance is required between the biggest ticks on the ruler. Say mag==1, then a unit=100 means that every 100 pixels is a unit tick. If mag==2, then a unit=100 means (at least) every 200 pixels is a unit tick

Referenced by adjustmetrics(), Refresh(), RulerWindow(), and SetCurrentUnits().


The documentation for this class was generated from the following files:

Mon Feb 17 2014 11:53:00, Laxkit