mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-21 06:45:39 -06:00
bazaar: CMeter: a progressbar / meter / slider with some versetile settings Ctrl
git-svn-id: svn://ultimatepp.org/upp/trunk@2625 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
00369e6875
commit
6073d6f89c
10 changed files with 1436 additions and 0 deletions
1029
bazaar/CMeter/CMeter.cpp
Normal file
1029
bazaar/CMeter/CMeter.cpp
Normal file
File diff suppressed because it is too large
Load diff
211
bazaar/CMeter/CMeter.h
Normal file
211
bazaar/CMeter/CMeter.h
Normal file
|
|
@ -0,0 +1,211 @@
|
||||||
|
#ifndef __METER_H
|
||||||
|
#define __METER_H
|
||||||
|
|
||||||
|
#include <CtrlLib/CtrlLib.h>
|
||||||
|
#include <Painter/Painter.h>
|
||||||
|
|
||||||
|
using namespace Upp;
|
||||||
|
|
||||||
|
class CMeter : public Ctrl
|
||||||
|
{
|
||||||
|
typedef CMeter CLASSNAME;
|
||||||
|
|
||||||
|
public:
|
||||||
|
struct Style : public ChStyle<Style>
|
||||||
|
{
|
||||||
|
Color backcol;
|
||||||
|
Color textcol;
|
||||||
|
Color forecol;
|
||||||
|
Color forecol2;
|
||||||
|
|
||||||
|
int cmarksize;
|
||||||
|
|
||||||
|
enum MODES
|
||||||
|
{
|
||||||
|
STATIC = 0, //static rect
|
||||||
|
GRADIENT,
|
||||||
|
LINES,
|
||||||
|
};
|
||||||
|
int mode; //one of the MODES
|
||||||
|
};
|
||||||
|
|
||||||
|
class CVMark
|
||||||
|
: Moveable<CVMark>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef CVMark CLASSNAME;
|
||||||
|
|
||||||
|
CVMark(float v = 0.0f, String name = "", Color col = LtRed() );
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
Color col;
|
||||||
|
String name; //place some name here to display
|
||||||
|
float v;
|
||||||
|
};
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
IMGCACHE = 0,
|
||||||
|
STATIC,
|
||||||
|
GRADIENT,
|
||||||
|
DYNGRADIENT,
|
||||||
|
};
|
||||||
|
|
||||||
|
CMeter(float min = 0.0f, float max = 1.0f, bool vertical = false, bool reverse = false);
|
||||||
|
virtual ~CMeter() {}
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
void CreateBack();
|
||||||
|
|
||||||
|
virtual Value GetData() const { return (double)val; }
|
||||||
|
virtual void SetData(const Value& data) { Set((float)(double)data); }
|
||||||
|
Value GetMin() const { return (double)min; }
|
||||||
|
Value GetMax() const { return (double)max; }
|
||||||
|
CMeter & MinMax(const Value& min = 0.0, const Value& max = 1.0) { return MinMax((float)(double)min, (float)(double)max); }
|
||||||
|
|
||||||
|
CMeter & Set(float val);
|
||||||
|
float Get() const { return val; }
|
||||||
|
|
||||||
|
CMeter & Val(float val) { return Set(val); }
|
||||||
|
float Val() const { return val; }
|
||||||
|
|
||||||
|
CMeter & Percent(float percent) { Set(min + percent * (max-min) / 100.0f); }
|
||||||
|
float Percent() const { return 100.0f * (val-min)/(max-min); }
|
||||||
|
|
||||||
|
CMeter & Min(float min);
|
||||||
|
float Min() const { return min; }
|
||||||
|
|
||||||
|
CMeter & Max(float max);
|
||||||
|
float Max() const { return max; }
|
||||||
|
|
||||||
|
CMeter & MinMax(float min = 0.0f, float max = 1.0f);
|
||||||
|
|
||||||
|
CMeter & Reverse(bool reverse = true);
|
||||||
|
float IsReverse() const { return reverse; }
|
||||||
|
|
||||||
|
CMeter & Vertical(bool vertical = true);
|
||||||
|
bool IsVertical() const { return vertical; }
|
||||||
|
|
||||||
|
CMeter & Stepping(bool stepping = true);
|
||||||
|
bool IsStepping() const { return stepping; }
|
||||||
|
|
||||||
|
CMeter & StepLinear(bool steplin = true);
|
||||||
|
bool IsStepLinear() { return steplin; }
|
||||||
|
|
||||||
|
CMeter & IncDecToStep(bool b = true) { incdectostep = b; return *this; }
|
||||||
|
bool IsIncDecToStep() { return incdectostep; }
|
||||||
|
|
||||||
|
CMeter & Steps(const Vector<float> & vsteps, bool reverse = false);
|
||||||
|
void GetSteps(Vector<float> & vstep) { vsteps <<= this->vsteps; }
|
||||||
|
|
||||||
|
int FindStep(float v) const;
|
||||||
|
|
||||||
|
CMeter & ShowValue(bool showvalue = true);
|
||||||
|
CMeter & HideValue() { return ShowValue(false); }
|
||||||
|
bool IsShowValue() { return showvalue; }
|
||||||
|
|
||||||
|
CMeter & ShowPercent(bool showpercent = true);
|
||||||
|
bool IsShowPercent() { return showpercent; }
|
||||||
|
|
||||||
|
CMeter & SetMode(int mode);
|
||||||
|
int GetMode() const { return drawmode; }
|
||||||
|
|
||||||
|
void Inc();
|
||||||
|
void Dec();
|
||||||
|
|
||||||
|
CMeter& SetInc(float _inc = 0.1) { inc = _inc; return *this; }
|
||||||
|
double GetInc() const { return inc; }
|
||||||
|
|
||||||
|
CMeter& SetStyle(const Style& s);
|
||||||
|
static const Style& StyleDefault();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
const Style *style;
|
||||||
|
|
||||||
|
virtual void Layout();
|
||||||
|
virtual void Paint(Draw& w);
|
||||||
|
virtual void Update();
|
||||||
|
|
||||||
|
virtual void LeftRepeat(Point p, dword keyflags);
|
||||||
|
virtual void LeftDown(Point p, dword keyflags);
|
||||||
|
virtual void LeftUp(Point p, dword keyflags) ;
|
||||||
|
virtual void MouseMove(Point p, dword keyflags);
|
||||||
|
virtual void MouseWheel(Point p, int zdelta, dword keyflags);
|
||||||
|
|
||||||
|
virtual void GotFocus();
|
||||||
|
virtual void LostFocus();
|
||||||
|
|
||||||
|
virtual bool Key(dword key, int rep);
|
||||||
|
bool Key0(dword key, int rep);
|
||||||
|
|
||||||
|
virtual int ValToPix(float _val);
|
||||||
|
virtual float PointToVal(Point & p);
|
||||||
|
|
||||||
|
bool SetFollow(float _val);
|
||||||
|
bool SetFollow(Point p, dword keyflags);
|
||||||
|
bool SetDirect(Point p, dword keyflags);
|
||||||
|
float CalcIncV();
|
||||||
|
|
||||||
|
void PaintBarGradient(Painter & sw, bool staticgradient = true);
|
||||||
|
void PaintBarStatic(Painter & sw);
|
||||||
|
void PaintBarImage(Painter & sw);
|
||||||
|
void PaintCVMarks(Painter & sw);
|
||||||
|
void PaintValue(Painter & sw);
|
||||||
|
|
||||||
|
void DoPaint0(Painter& sw);
|
||||||
|
void DoPaint(Painter& sw);
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
Vector<CVMark> cvmarks; //here we can set some marking
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
//cached data
|
||||||
|
|
||||||
|
int px; //some offsets from top left, used as offset where to start drawinf bar, no matter horz or vert
|
||||||
|
int py;
|
||||||
|
|
||||||
|
int _px; //some helpers to draw cvmarks, are extension of the cvmarks
|
||||||
|
int _py;
|
||||||
|
|
||||||
|
float pp; //cached [0:1] of drawn size
|
||||||
|
int dx, lx, dy, ly; //some cache for painting, d barsize, l emtpy size
|
||||||
|
|
||||||
|
int increment; //a state helper for repeating counts
|
||||||
|
float incv; //for value following if not stepping
|
||||||
|
int inci; //for value following if stepping
|
||||||
|
float __val; //cached desired value for inc compare against oszillation when stepping
|
||||||
|
int __ii; //cached current step index
|
||||||
|
|
||||||
|
String s; //the printed value
|
||||||
|
Size tlen; //text len
|
||||||
|
|
||||||
|
//vital data
|
||||||
|
|
||||||
|
float min;
|
||||||
|
float max;
|
||||||
|
float val;
|
||||||
|
|
||||||
|
float inc; //for keys
|
||||||
|
|
||||||
|
bool vertical:1;
|
||||||
|
bool reverse:1;
|
||||||
|
bool stepping:1;
|
||||||
|
bool steplin:1;
|
||||||
|
bool showvalue:1;
|
||||||
|
bool showpercent:1;
|
||||||
|
bool clickincdec:1;
|
||||||
|
bool incdectostep:1;
|
||||||
|
|
||||||
|
int drawmode;
|
||||||
|
|
||||||
|
|
||||||
|
Font font;
|
||||||
|
Image draw;
|
||||||
|
Vector<float> vsteps;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
11
bazaar/CMeter/CMeter.upp
Normal file
11
bazaar/CMeter/CMeter.upp
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
description "a Meter Drawing control, more versatile than the Upp progress stuff\377";
|
||||||
|
|
||||||
|
uses
|
||||||
|
CtrlLib,
|
||||||
|
Painter;
|
||||||
|
|
||||||
|
file
|
||||||
|
CMeter.h,
|
||||||
|
CMeter.cpp,
|
||||||
|
src.tpp;
|
||||||
|
|
||||||
5
bazaar/CMeter/init
Normal file
5
bazaar/CMeter/init
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
#ifndef _CMeter_icpp_init_stub
|
||||||
|
#define _CMeter_icpp_init_stub
|
||||||
|
#include "CtrlLib/init"
|
||||||
|
#include "Painter/init"
|
||||||
|
#endif
|
||||||
37
bazaar/CMeter/src.tpp/CMeter$en-us.tpp
Normal file
37
bazaar/CMeter/src.tpp/CMeter$en-us.tpp
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
topic "";
|
||||||
|
[ $$0,0#00000000000000000000000000000000:Default]
|
||||||
|
[H6;0 $$1,0#05600065144404261032431302351956:begin]
|
||||||
|
[i448;a25;kKO9;2 $$2,0#37138531426314131252341829483370:codeitem]
|
||||||
|
[l288;2 $$3,0#27521748481378242620020725143825:desc]
|
||||||
|
[0 $$4,0#96390100711032703541132217272105:end]
|
||||||
|
[i448;a25;kKO9; $$5,0#37138531426314131252341829483380:structitem]
|
||||||
|
[{_}
|
||||||
|
[s1; &]
|
||||||
|
[s5;:CMeter`:`:CVMark`:`:class: [@(0.0.255) class]_[* CVMark]_:_[@(0.0.255) private]_[*@3 Move
|
||||||
|
able]<[* CVMark]>_&]
|
||||||
|
[s3;%% markers shown at side of the meter, independant from meter
|
||||||
|
value&]
|
||||||
|
[s4; &]
|
||||||
|
[s2;:CMeter`:`:FindStep`(float`)const: [@(0.0.255) int]_[* FindStep]([@(0.0.255) float]_[*@3 v
|
||||||
|
])_[@(0.0.255) const]&]
|
||||||
|
[s3;%% find value [%-*@3 v].in the steps vector and return index if
|
||||||
|
found&]
|
||||||
|
[s4;%% &]
|
||||||
|
[s1; &]
|
||||||
|
[s2;:CMeter`:`:GRADIENT: [@(0.0.255) enum]_[* GRADIENT]&]
|
||||||
|
[s3;%% a static gradient, a lice of which is displayed&]
|
||||||
|
[s4; &]
|
||||||
|
[s1; &]
|
||||||
|
[s2;:CMeter`:`:STATIC: [@(0.0.255) enum]_[* STATIC]&]
|
||||||
|
[s3;%% static color bar&]
|
||||||
|
[s4; &]
|
||||||
|
[s1; &]
|
||||||
|
[s2;:CMeter`:`:IMGCACHE: [@(0.0.255) enum]_[* IMGCACHE]_`=_[@3 0]&]
|
||||||
|
[s3;%% a fancy bar gradient with 2 colors, actually generated and
|
||||||
|
stored in an Image&]
|
||||||
|
[s4; &]
|
||||||
|
[s1; &]
|
||||||
|
[s2;:CMeter`:`:DYNGRADIENT: [@(0.0.255) enum]_[* DYNGRADIENT]&]
|
||||||
|
[s3;%% a gradient drawn over currently applied bar&]
|
||||||
|
[s4; &]
|
||||||
|
[s0; ]
|
||||||
32
bazaar/CMeterTest/CMeterTest.h
Normal file
32
bazaar/CMeterTest/CMeterTest.h
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
#ifndef _CMeterTest_CMeterTest_h
|
||||||
|
#define _CMeterTest_CMeterTest_h
|
||||||
|
|
||||||
|
#include <CtrlLib/CtrlLib.h>
|
||||||
|
|
||||||
|
using namespace Upp;
|
||||||
|
|
||||||
|
#define LAYOUTFILE <CMeterTest/CMeterTest.lay>
|
||||||
|
#include <CtrlCore/lay.h>
|
||||||
|
|
||||||
|
#include <CMeter/CMeter.h>
|
||||||
|
|
||||||
|
class CMeterTest : public WithCMeterTestLayout<TopWindow> {
|
||||||
|
public:
|
||||||
|
typedef CMeterTest CLASSNAME;
|
||||||
|
CMeterTest();
|
||||||
|
|
||||||
|
void metersl_CB();
|
||||||
|
void meterrev_CB();
|
||||||
|
void metervert_CB();
|
||||||
|
void meterstep_CB();
|
||||||
|
void meterperc_CB();
|
||||||
|
void metersteplin_CB();
|
||||||
|
|
||||||
|
void meterCB();
|
||||||
|
void metermodeCB();
|
||||||
|
|
||||||
|
CMeter meter;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
11
bazaar/CMeterTest/CMeterTest.lay
Normal file
11
bazaar/CMeterTest/CMeterTest.lay
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
LAYOUT(CMeterTestLayout, 596, 352)
|
||||||
|
ITEM(SliderCtrl, metersl, RightPosZ(68, 288).TopPosZ(4, 20))
|
||||||
|
ITEM(Option, PERC, SetLabel(t_("percent")).RightPosZ(4, 64).TopPosZ(72, 16))
|
||||||
|
ITEM(Option, STEPLIN, SetLabel(t_("steplin")).RightPosZ(0, 64).TopPosZ(224, 16))
|
||||||
|
ITEM(Option, STEP, SetLabel(t_("stepping")).RightPosZ(8, 64).TopPosZ(204, 16))
|
||||||
|
ITEM(Option, VERT, SetLabel(t_("vertical")).RightPosZ(4, 64).TopPosZ(40, 16))
|
||||||
|
ITEM(Option, REV, SetLabel(t_("reverse")).RightPosZ(4, 64).TopPosZ(24, 16))
|
||||||
|
ITEM(EditInt, sledit, SetEditable(false).RightPosZ(4, 64).TopPosZ(4, 19))
|
||||||
|
ITEM(Switch, mode, LeftPosZ(520, 72).TopPosZ(92, 108))
|
||||||
|
END_LAYOUT
|
||||||
|
|
||||||
12
bazaar/CMeterTest/CMeterTest.upp
Normal file
12
bazaar/CMeterTest/CMeterTest.upp
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
uses
|
||||||
|
CtrlLib,
|
||||||
|
CMeter;
|
||||||
|
|
||||||
|
file
|
||||||
|
CMeterTest.h,
|
||||||
|
main.cpp,
|
||||||
|
CMeterTest.lay;
|
||||||
|
|
||||||
|
mainconfig
|
||||||
|
"" = "GUI";
|
||||||
|
|
||||||
5
bazaar/CMeterTest/init
Normal file
5
bazaar/CMeterTest/init
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
#ifndef _CMeterTest_icpp_init_stub
|
||||||
|
#define _CMeterTest_icpp_init_stub
|
||||||
|
#include "CtrlLib/init"
|
||||||
|
#include "CMeter/init"
|
||||||
|
#endif
|
||||||
83
bazaar/CMeterTest/main.cpp
Normal file
83
bazaar/CMeterTest/main.cpp
Normal file
|
|
@ -0,0 +1,83 @@
|
||||||
|
#include "CMeterTest.h"
|
||||||
|
|
||||||
|
CMeterTest::CMeterTest()
|
||||||
|
{
|
||||||
|
CtrlLayout(*this, "Window title");
|
||||||
|
|
||||||
|
metersl.MinMax(-100,100).SetData(0);
|
||||||
|
metersl <<= THISBACK(metersl_CB);
|
||||||
|
REV <<= THISBACK(meterrev_CB);
|
||||||
|
VERT <<= THISBACK(metervert_CB);
|
||||||
|
STEP <<= THISBACK(meterstep_CB);
|
||||||
|
STEPLIN <<= THISBACK(metersteplin_CB);
|
||||||
|
PERC <<= THISBACK(meterperc_CB);
|
||||||
|
|
||||||
|
mode.Add(CMeter::IMGCACHE, "IMGCACHE");
|
||||||
|
mode.Add(CMeter::STATIC, "STATIC");
|
||||||
|
mode.Add(CMeter::GRADIENT, "GRADIENT");
|
||||||
|
mode.Add(CMeter::DYNGRADIENT, "DYNGRADIENT");
|
||||||
|
mode <<= THISBACK(metermodeCB);
|
||||||
|
|
||||||
|
float min = (float)metersl.GetMin();
|
||||||
|
float max = (float)metersl.GetMax();
|
||||||
|
|
||||||
|
//setup the marks
|
||||||
|
Vector<float> vmarks;
|
||||||
|
vmarks.Add(max);
|
||||||
|
vmarks.Add(max-(max-min)*0.1f);
|
||||||
|
vmarks.Add(max-(max-min)*0.2f);
|
||||||
|
vmarks.Add(max-(max-min)*0.3f);
|
||||||
|
vmarks.Add(max-(max-min)*0.4f);
|
||||||
|
vmarks.Add(max-(max-min)*0.7f);
|
||||||
|
|
||||||
|
meter <<= THISBACK(meterCB);
|
||||||
|
meter.Min(min).Max(max).Steps(vmarks, true).Set(min); //use reverse order, meter needs starting vector with min
|
||||||
|
Add(meter.LeftPos(10,50).TopPos(10,200));
|
||||||
|
}
|
||||||
|
|
||||||
|
void CMeterTest::meterCB()
|
||||||
|
{
|
||||||
|
double f = meter.GetData();
|
||||||
|
metersl.SetData(f);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CMeterTest::metersl_CB()
|
||||||
|
{
|
||||||
|
sledit.SetData(metersl.GetData());
|
||||||
|
meter.Set((float)(double)metersl.GetData());
|
||||||
|
}
|
||||||
|
|
||||||
|
void CMeterTest::meterrev_CB()
|
||||||
|
{
|
||||||
|
meter.Reverse(REV.GetData()).Refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CMeterTest::metervert_CB()
|
||||||
|
{
|
||||||
|
meter.Vertical(VERT.GetData()).Refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CMeterTest::meterstep_CB()
|
||||||
|
{
|
||||||
|
meter.Stepping(STEP.GetData()).Refresh();
|
||||||
|
}
|
||||||
|
void CMeterTest::metersteplin_CB()
|
||||||
|
{
|
||||||
|
meter.StepLinear(STEPLIN.GetData()).Refresh();
|
||||||
|
}
|
||||||
|
void CMeterTest::meterperc_CB()
|
||||||
|
{
|
||||||
|
meter.ShowPercent(PERC.GetData()).Refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CMeterTest::metermodeCB()
|
||||||
|
{
|
||||||
|
int m = mode.GetData();
|
||||||
|
meter.SetMode(m).Refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
GUI_APP_MAIN
|
||||||
|
{
|
||||||
|
CMeterTest().Run();
|
||||||
|
}
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue