Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site











SourceForge.net Logo

Counter

 

Counter widget used in UscCtrl example

 

 

Counter.h

 

#ifndef _T_Counter_Counter_h_

#define _T_Counter_Counter_h_

 

#include <CtrlLib/CtrlLib.h>

 

using namespace Upp;

 

class CounterCtrl : public Ctrl {

public:

    virtual Value GetData() const;

    virtual void  SetData(const Value& v);

    virtual void  Paint(Draw& w);

    virtual void  LeftDown(Point, dword);

 

private:

    int   number;

    Font  font;

    Color ink, paper;

 

public:

    CounterCtrl& SetFont(Font f)   { font = f; Refresh(); return *this; }

    CounterCtrl& Ink(Color c)      { ink = c; Refresh(); return *this; }

    CounterCtrl& Paper(Color c)    { paper = c; Refresh(); return *this; }

 

    CounterCtrl();

    ~CounterCtrl();

};

 

#endif

 

 

 

Counter.cpp

 

#include "Counter.h"

 

Value CounterCtrl::GetData() const

{

    return number;

}

 

void  CounterCtrl::SetData(const Value& v)

{

    number = v;

    Refresh();

}

 

void  CounterCtrl::Paint(Draw& w)

{

    Size sz = GetSize();

    w.DrawRect(sz, paper);

    String txt = AsString(number);

    sz = (sz - GetTextSize(txt, font)) / 2;

    w.DrawText(sz.cx, sz.cy, txt, font, ink);

}

 

void  CounterCtrl::LeftDown(Point, dword)

{

    number++;

    Refresh();

}

 

CounterCtrl::CounterCtrl()

{

    number = 0;

    ink = SBlack;

    paper = SWhite;

    font = StdFont();

    SetFrame(BlackFrame());

}

 

CounterCtrl::~CounterCtrl() {}

 

 

 

Counter.usc

 

ctrl CounterCtrl {

    group "Example";

 

    GetMinSize() { sz = GetTextSize("X"); sz.cy += 2; return sz; }

    GetStdSize() { sz = GetMinSize(); sz.cx *= 7; return sz; }

 

    Frame  SetFrame = BlackFrame() @2;

    Font   SetFont = StdFont();

    Color  Ink = :SBlack;

    Color  Paper = :SWhite;

 

    Paint(w) {

        r = GetRect();

        DrawCtrlFrame(w, r, .SetFrame);

        w.DrawRect(r, .Paper);

        textsize = GetTextSize("0", .SetFont);

        w.DrawText((r.right + r.left - textsize.cx) / 2,

                   (r.bottom + r.top - textsize.cy) / 2, "0", .SetFont, .Ink);

    }

};

 

 

 

 

Do you want to contribute?