mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-08-25 14:22:54 -06:00
VirtualButtons improvements
This commit is contained in:
parent
5a711f77ae
commit
67f810e0f5
12 changed files with 307 additions and 127 deletions
|
|
@ -47,9 +47,11 @@ MultiButton::SubButton::SubButton()
|
|||
|
||||
void MultiButton::SubButton::Refresh()
|
||||
{
|
||||
owner->Refresh();
|
||||
if(owner->Frame() && owner->GetParent())
|
||||
owner->GetParent()->RefreshLayout();
|
||||
if(owner) {
|
||||
owner->Refresh();
|
||||
if(owner->Frame() && owner->GetParent())
|
||||
owner->GetParent()->RefreshLayout();
|
||||
}
|
||||
}
|
||||
|
||||
MultiButton::SubButton& MultiButton::SubButton::SetImage(const Image& m)
|
||||
|
|
@ -111,30 +113,89 @@ MultiButton::SubButton& MultiButton::SubButton::Show(bool b)
|
|||
return *this;
|
||||
}
|
||||
|
||||
void MultiButton::MultiButtons()
|
||||
{
|
||||
if(DropPush) {
|
||||
SubButton& b = buttons.Add();
|
||||
b.owner = this;
|
||||
b.WhenPush = DropPush;
|
||||
b.main = true;
|
||||
DropPush.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
MultiButton::SubButton& MultiButton::AddButton()
|
||||
{
|
||||
SubButton& b = button.Add();
|
||||
MultiButtons();
|
||||
SubButton& b = buttons.Add();
|
||||
b.owner = this;
|
||||
return b;
|
||||
}
|
||||
|
||||
MultiButton::SubButton& MultiButton::InsertButton(int i)
|
||||
{
|
||||
SubButton& b = button.Insert(i);
|
||||
MultiButtons();
|
||||
SubButton& b = buttons.Insert(i);
|
||||
b.owner = this;
|
||||
return b;
|
||||
}
|
||||
|
||||
void MultiButton::RemoveButton(int i)
|
||||
{
|
||||
button.Remove(i);
|
||||
MultiButtons();
|
||||
buttons.Remove(i);
|
||||
}
|
||||
|
||||
void MultiButton::Reset()
|
||||
{
|
||||
MultiButtons();
|
||||
buttons.Clear();
|
||||
}
|
||||
|
||||
int MultiButton::GetButtonCount() const
|
||||
{
|
||||
if(DropPush)
|
||||
return 1;
|
||||
return buttons.GetCount();
|
||||
}
|
||||
|
||||
MultiButton::SubButton& MultiButton::Button(int i) const
|
||||
{
|
||||
if(DropPush) {
|
||||
static SubButton b;
|
||||
b.main = true;
|
||||
return b;
|
||||
}
|
||||
return const_cast<MultiButton *>(this)->buttons[i];
|
||||
}
|
||||
|
||||
const MultiButton::SubButton& MultiButton::GetButton(int i) const
|
||||
{
|
||||
return Button(i);
|
||||
}
|
||||
|
||||
MultiButton::SubButton& MultiButton::GetButton(int i)
|
||||
{
|
||||
MultiButtons();
|
||||
return Button(i);
|
||||
}
|
||||
|
||||
MultiButton::SubButton& MultiButton::MainButton()
|
||||
{
|
||||
for(int i = 0; i < GetButtonCount(); i++) {
|
||||
SubButton& b = GetButton(i);
|
||||
if(b.main)
|
||||
return b;
|
||||
}
|
||||
NEVER();
|
||||
return GetButton(0);
|
||||
}
|
||||
|
||||
MultiButton::SubButton& MultiButton::SubButton::Main(bool b)
|
||||
{
|
||||
if(b)
|
||||
for(int i = 0; i < owner->button.GetCount(); i++)
|
||||
owner->button[i].main = false;
|
||||
if(b && owner)
|
||||
for(int i = 0; i < owner->GetButtonCount(); i++)
|
||||
owner->GetButton(i).main = false;
|
||||
main = b;
|
||||
return *this;
|
||||
}
|
||||
|
|
@ -212,12 +273,12 @@ int MultiButton::FindButton(int px)
|
|||
{
|
||||
if(IsReadOnly())
|
||||
return Null;
|
||||
if(IsTrivial() && !Frame())
|
||||
return button[0].enabled ? 0 : Null;
|
||||
if(IsTrivial() && !Frame() && GetButtonCount())
|
||||
return GetButton(0).enabled ? 0 : Null;
|
||||
int border, lx, rx;
|
||||
Metrics(border, lx, rx);
|
||||
for(int i = 0; i < button.GetCount(); i++) {
|
||||
SubButton& b = button[i];
|
||||
for(int i = 0; i < GetButtonCount(); i++) {
|
||||
SubButton& b = Button(i);
|
||||
int x = 0, cx = 0;
|
||||
if(GetPos(b, lx, rx, x, cx, px))
|
||||
return b.enabled ? i : Null;
|
||||
|
|
@ -225,8 +286,8 @@ int MultiButton::FindButton(int px)
|
|||
if(WhenPush || WhenClick)
|
||||
return MAIN;
|
||||
if(display)
|
||||
for(int i = 0; i < button.GetCount(); i++)
|
||||
if(button[i].main)
|
||||
for(int i = 0; i < GetButtonCount(); i++)
|
||||
if(Button(i).main)
|
||||
return i;
|
||||
return Null;
|
||||
}
|
||||
|
|
@ -262,7 +323,7 @@ void MultiButton::GetPos(int ii, int& x, int& cx)
|
|||
Metrics(border, lx, rx);
|
||||
x = cx = 0;
|
||||
for(int i = 0; i <= ii; i++) {
|
||||
SubButton& b = button[i];
|
||||
SubButton& b = Button(i);
|
||||
GetPos(b, lx, rx, x, cx);
|
||||
}
|
||||
}
|
||||
|
|
@ -273,8 +334,8 @@ void MultiButton::GetLR(int& lx, int& rx)
|
|||
Metrics(border, lx, rx);
|
||||
int x = 0;
|
||||
int cx = 0;
|
||||
for(int i = 0; i < button.GetCount(); i++) {
|
||||
SubButton& b = button[i];
|
||||
for(int i = 0; i < GetButtonCount(); i++) {
|
||||
SubButton& b = Button(i);
|
||||
GetPos(b, lx, rx, x, cx);
|
||||
}
|
||||
}
|
||||
|
|
@ -286,13 +347,13 @@ int MultiButton::ChState(int i)
|
|||
if(i == MAIN && frm && style->activeedge) {
|
||||
int q = 0;
|
||||
if(p)
|
||||
q = !p->IsEnabled() || !IsEnabled() || p->IsReadOnly() || i >= 0 && !button[i].enabled ? CTRL_DISABLED
|
||||
q = !p->IsEnabled() || !IsEnabled() || p->IsReadOnly() ? CTRL_DISABLED
|
||||
: p->HasFocus() || push ? CTRL_PRESSED
|
||||
: p->HasMouse() || hl >= 0 ? CTRL_HOT
|
||||
: CTRL_NORMAL;
|
||||
return q;
|
||||
}
|
||||
if(!IsShowEnabled() || IsReadOnly() || frm && p && p->IsReadOnly() || i >= 0 && !button[i].enabled)
|
||||
if(!IsShowEnabled() || IsReadOnly() || frm && p && p->IsReadOnly() || i >= 0 && !Button(i).enabled)
|
||||
return CTRL_DISABLED;
|
||||
if(IsTrivial() && !frm)
|
||||
i = 0;
|
||||
|
|
@ -317,8 +378,8 @@ void MultiButton::Lay(Rect& r, bool minsize)
|
|||
bool frm = Metrics(border, lx, rx);
|
||||
bool left = false;
|
||||
bool right = false;
|
||||
for(int i = 0; i < button.GetCount(); i++) {
|
||||
SubButton& b = button[i];
|
||||
for(int i = 0; i < GetButtonCount(); i++) {
|
||||
SubButton& b = Button(i);
|
||||
int cx = 0; int x = 0;
|
||||
GetPos(b, lx, rx, x, cx);
|
||||
(b.left ? left : right) = true;
|
||||
|
|
@ -404,8 +465,8 @@ Rect MultiButton::Paint0(Draw& w, bool getcr)
|
|||
}
|
||||
bool left = false;
|
||||
bool right = false;
|
||||
for(int i = 0; i < button.GetCount(); i++) {
|
||||
SubButton& b = button[i];
|
||||
for(int i = 0; i < GetButtonCount(); i++) {
|
||||
SubButton& b = Button(i);
|
||||
int st = ChState(i);
|
||||
int x = 0, cx = 0;
|
||||
GetPos(b, lx, rx, x, cx);
|
||||
|
|
@ -562,7 +623,7 @@ void MultiButton::SyncInfo()
|
|||
void MultiButton::MouseMove(Point p, dword flags)
|
||||
{
|
||||
int h = FindButton(p.x);
|
||||
Ctrl::Tip(h >= 0 && h < button.GetCount() ? Nvl(button[h].tip, tip) : tip);
|
||||
Ctrl::Tip(h >= 0 && h < GetButtonCount() ? Nvl(Button(h).tip, tip) : tip);
|
||||
if(hl != h) {
|
||||
hl = h;
|
||||
Refresh();
|
||||
|
|
@ -575,12 +636,20 @@ void MultiButton::MouseMove(Point p, dword flags)
|
|||
SyncInfo();
|
||||
}
|
||||
|
||||
void MultiButton::DoPush(int i)
|
||||
{
|
||||
if(i == 0 && DropPush)
|
||||
DropPush();
|
||||
else
|
||||
Button(i).WhenPush();
|
||||
}
|
||||
|
||||
void MultiButton::LeftDown(Point p, dword flags)
|
||||
{
|
||||
push = true;
|
||||
Refresh();
|
||||
if(IsNull(hl))
|
||||
pushrect = Null;
|
||||
if(hl == NONE)
|
||||
pushrect.Clear();
|
||||
else {
|
||||
if(hl == MAIN)
|
||||
pushrect = GetScreenRect();
|
||||
|
|
@ -593,7 +662,7 @@ void MultiButton::LeftDown(Point p, dword flags)
|
|||
}
|
||||
Sync();
|
||||
if(hl >= 0)
|
||||
button[hl].WhenPush();
|
||||
DoPush(hl);
|
||||
else
|
||||
WhenPush();
|
||||
}
|
||||
|
|
@ -605,9 +674,9 @@ void MultiButton::LeftUp(Point p, dword flags)
|
|||
push = false;
|
||||
Refresh();
|
||||
Sync();
|
||||
if(!IsNull(hl)) {
|
||||
if(hl != NONE) {
|
||||
if(hl >= 0)
|
||||
button[hl].WhenClick();
|
||||
Button(hl).WhenClick();
|
||||
else
|
||||
WhenClick();
|
||||
}
|
||||
|
|
@ -617,7 +686,7 @@ void MultiButton::LeftUp(Point p, dword flags)
|
|||
void MultiButton::MouseLeave()
|
||||
{
|
||||
if(!info.IsOpen()) {
|
||||
hl = Null;
|
||||
hl = NONE;
|
||||
Refresh();
|
||||
SyncInfo();
|
||||
}
|
||||
|
|
@ -625,7 +694,7 @@ void MultiButton::MouseLeave()
|
|||
|
||||
void MultiButton::CancelMode()
|
||||
{
|
||||
hl = Null;
|
||||
hl = NONE;
|
||||
push = false;
|
||||
Refresh();
|
||||
info.Cancel();
|
||||
|
|
@ -633,21 +702,7 @@ void MultiButton::CancelMode()
|
|||
|
||||
bool MultiButton::IsTrivial() const
|
||||
{
|
||||
return button.GetCount() == 1 && IsNull(button[0].img) && !WhenPush && !WhenClick;
|
||||
}
|
||||
|
||||
MultiButton::SubButton& MultiButton::MainButton()
|
||||
{
|
||||
for(int i = 0; i < button.GetCount(); i++)
|
||||
if(button[i].main)
|
||||
return button[i];
|
||||
NEVER();
|
||||
return button[0];
|
||||
}
|
||||
|
||||
void MultiButton::Reset()
|
||||
{
|
||||
button.Clear();
|
||||
return GetButtonCount() == 1 && IsNull(Button(0).img) && !WhenPush && !WhenClick;
|
||||
}
|
||||
|
||||
MultiButton& MultiButton::SetDisplay(const Display& d)
|
||||
|
|
@ -718,11 +773,11 @@ void MultiButton::PseudoPush(int bi)
|
|||
{
|
||||
hl = bi;
|
||||
push = true;
|
||||
button[bi].WhenPush();
|
||||
DoPush(bi);
|
||||
Sync();
|
||||
Sleep(50);
|
||||
button[bi].WhenClick();
|
||||
hl = Null;
|
||||
Button(bi).WhenClick();
|
||||
hl = NONE;
|
||||
push = false;
|
||||
Sync();
|
||||
}
|
||||
|
|
@ -734,7 +789,7 @@ void MultiButton::PseudoPush()
|
|||
Sync();
|
||||
Sleep(50);
|
||||
WhenClick();
|
||||
hl = Null;
|
||||
hl = NONE;
|
||||
push = false;
|
||||
Sync();
|
||||
}
|
||||
|
|
@ -749,6 +804,7 @@ MultiButton::MultiButton()
|
|||
push = false;
|
||||
SetFrame(sNullFrame());
|
||||
nobg = false;
|
||||
hl = NONE;
|
||||
}
|
||||
|
||||
void MultiButtonFrame::FrameAdd(Ctrl& parent)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue