Exemplo n.º 1
0
int  TopMenuItem::GetState()
{
	if(!IsEnabled()) return NORMAL;
	if(HasMouse() && GetMouseLeft() || GetMouseRight()) return PUSH;
	if(HasFocus() || HasMouse()) return HIGHLIGHT;
	return NORMAL;
}
Exemplo n.º 2
0
void MAS::Window::Minimize() {
   if (extraFlags & W_MAXIMIZED) {
      return;
   }

   if (!(extraFlags & W_MINIMIZED)) {
      restoreRect = (*this);

      extraFlags |= W_MINIMIZED;
      Dialog::Remove(*clientArea);
      Rect oldRect = *this;
      //Resize(120, bTop.h() + bGrip.h() + bBottom.h());
      Resize(w(), bTop.h() + bGrip.h() + bBottom.h());
      iconMax.SetSample(Skin::SAMPLE_ACTIVATE, Skin::SAMPLE_ACTIVATE);
      iconMin.SetSample(Skin::SAMPLE_OPEN, Skin::SAMPLE_ACTIVATE);
   }
   else {
      extraFlags &= ~W_MINIMIZED;
      Resize(restoreRect.w(), restoreRect.h());
      Dialog::Add(*clientArea);
      iconMax.SetSample(Skin::SAMPLE_OPEN, Skin::SAMPLE_ACTIVATE);
      iconMin.SetSample(Skin::SAMPLE_CLOSE, Skin::SAMPLE_ACTIVATE);
   }

   if (!HasMouse()) {
      if (Flags() & D_RESIZABLE) {
         iconMin.Disable();
         iconMax.Disable();
      }
      iconExit.Disable();
   }

   MsgShape();
}
Exemplo n.º 3
0
int  TopSubMenuItem::GetState()
{
	if(parentmenu && parentmenu->GetActiveSubmenu() == &menu) return PUSH;
	if(HasMouse() && GetParent() && !GetParent()->HasFocusDeep() &&
	                 (!parentmenu || !parentmenu->GetActiveSubmenu() || parentmenu->GetActiveSubmenu() == &menu)
	   || HasFocus())
		return HIGHLIGHT;
	return NORMAL;
}
Exemplo n.º 4
0
void ColorButton::Paint(Draw& w)
{
	Size sz = GetSize();
	Size isz = image.GetSize();
	Point center = (sz - isz) / 2;
	if(GUI_GlobalStyle() >= GUISTYLE_XP)
		ChPaint(w, sz, style->look[!IsEnabled() ? CTRL_DISABLED : push ? CTRL_PRESSED
		                                        : HasMouse() ? CTRL_HOT : CTRL_NORMAL]);
	else {
		w.DrawRect(sz, SColorFace);
		if(push)
			DrawFrame(w, sz, SColorShadow, SColorLight);
		else
		if(HasMouse())
			DrawFrame(w, sz, SColorLight, SColorShadow);
	}
	if(IsNull(color))
		w.DrawImage(center.x + push, center.y + push, nullimage);
	else
		w.DrawImage(center.x + push, center.y + push, image, color);
	w.DrawImage(center.x + push, center.y + push, staticimage);
}
Exemplo n.º 5
0
bool C4Menu::SetSelection(int32_t iSelection, bool fAdjustPosition, bool fDoCalls)
{
	// Not active
	if (!IsActive()) return false;
	// Outside Limits / Selectable
	C4MenuItem *pNewSel = GetItem(iSelection);
	if ((iSelection==-1 && !ItemCount) || (pNewSel && pNewSel->IsSelectable))
	{
		// Selection change
		if (iSelection!=Selection)
		{
			// calls
			C4MenuItem *pSel = GetSelectedItem();
			if (pSel) pSel->SetSelected(false);
			// Set selection
			Selection=iSelection;
			// Reset time on selection
			TimeOnSelection=0;
		}
		// always recheck selection for internal refill
		C4MenuItem *pSel = GetSelectedItem();
		if (pSel) pSel->SetSelected(true);
		// set main caption by selection
		if (Style == C4MN_Style_Normal)
		{
			if (pSel)
				SetTitle(*(pSel->Caption) ? pSel->Caption : " ", HasMouse());
			else
				SetTitle(*Caption ? Caption : " ", HasMouse());
		}
	}
	// adjust position, if desired
	if (fAdjustPosition) AdjustPosition();
	// do selection callback
	if (fDoCalls) OnSelectionChanged(Selection);
	// Done
	return true;
}
Exemplo n.º 6
0
void MultiButton::SyncInfo()
{
	if((HasMouse() || info.HasMouse()) && display &&
	   (GetMouseFlags() & (K_MOUSELEFT|K_MOUSERIGHT|K_MOUSEMIDDLE)) == 0) {
		Point p = GetMouseViewPos();
		NilDraw nw;
		Rect r = Paint0(nw, true);
		if(r.Contains(p)) {
			Value v = convert->Format(value);
			int cm = DPI(2);
			r.left -= cm;
			r.right += cm;
			info.Set(this, r, value, display, SColorText, SColorPaper, 0, DPI(2));
			return;
		}
	}
	info.Cancel();
}
Exemplo n.º 7
0
bool C4Menu::InitMenu(const char *szEmpty, int32_t iExtra, int32_t iExtraData, int32_t iId, int32_t iStyle)
{
	SCopy(szEmpty,Caption,C4MaxTitle);
	Extra=iExtra; ExtraData=iExtraData;
	Identification=iId;
	if (*Caption || iStyle == C4MN_Style_Dialog) SetTitle(Caption, HasMouse()); else SetTitle(" ", HasMouse());
	if (pTitle) pTitle->SetIcon(Symbol);
	Style=iStyle & C4MN_Style_BaseMask;
	// Menus are synchronous to allow COM_MenuUp/Down to be converted to movements at the clients
	if (Style == C4MN_Style_Normal)
		Columns = 5;
	else
		// in reality, Dialog menus may have two coloumns (first for the portrait)
		// however, they are not uniformly spaced and stuff; so they are better just ignored and handled by the drawing routine
		Columns=1;
	if (iStyle & C4MN_Style_EqualItemHeight) SetEqualItemHeight(true);
	if (Style == C4MN_Style_Dialog) Alignment = C4MN_Align_Top;
	::pGUI->ShowDialog(this, false);
	fTextProgressing = false;
	fActive = true;
	return true;
}
Exemplo n.º 8
0
void  ToolButton::Paint(Draw& w)
{
	LTIMING("ToolButton::Paint");
	paint_checked = checked;
	Size sz = GetSize();
	UPP::Image image = GetImage();
	Size isz = image.GetSize();
//	Ctrl *q = GetParent()->GetParent();
//	if(!q || !q->IsTransparent())
//		w.DrawRect(sz, checked && !HasMouse() ? Blend(SColorFace, SColorLight) : SColorFace);
	int li = IsEnabled() ? HasMouse() ? GetMouseLeft() ? CTRL_PRESSED
						                               : checked ? CTRL_HOTCHECKED : CTRL_HOT
				                       : checked ? CTRL_CHECKED : CTRL_NORMAL
					     : CTRL_DISABLED;
	ChPaint(w, sz, style->look[li]);
	Point off = style->offset[li];
	Point ip = (sz - isz) / 2 + off;
	Size tsz(0, 0);
	if(kind != NOLABEL)
		tsz = GetTextSize(text, style->font);
	if(kind == BOTTOMLABEL) {
		ip.y  -= tsz.cy / 2 + 1;
		w.DrawText((sz.cx - tsz.cx) / 2 + off.x, ip.y + isz.cy + 2 + off.y, text, style->font, style->textcolor[li]);
	}
	if(kind == RIGHTLABEL) {
		ip.x -= tsz.cx / 2 + 2;
		w.DrawText(ip.x + isz.cx + 3 + off.x, (sz.cy - tsz.cy) / 2 + off.y, text, style->font, style->textcolor[li]);
	}
	UPP::Image img = CachedContrast(image, style->contrast[li]);
	if(!IsEnabled())
		img = DisabledImage(img);
	if(IsEnabled() && style->light[li])
		DrawHighlightImage(w, ip.x, ip.y, img, true);
	else
		w.DrawImage(ip.x, ip.y, img);
}
Exemplo n.º 9
0
void C4Menu::UpdateElementPositions()
{
	// only if already shown and made visible by first drawing
	// this will postpone the call of menu initialization until it's really needed
	if (!IsVisible() || !pClientWindow) return;
	// reposition client scrolling window
	pClientWindow->SetBounds(GetContainedClientRect());
	// re-stack all list items
	int xOff, yOff = 0;
	C4MenuItem *pCurr = static_cast<C4MenuItem *>(pClientWindow->GetFirst()), *pPrev = NULL;
	if (HasPortrait() && pCurr)
	{
		// recheck portrait
		xOff = C4MN_DlgPortraitWdt + C4MN_DlgPortraitIndent;
		C4Facet &fctPortrait = pCurr->Symbol;
		C4Rect rcPortraitBounds(0,0, C4MN_DlgPortraitWdt + C4MN_DlgPortraitIndent, fctPortrait.Hgt * C4MN_DlgPortraitWdt / std::max<int>(fctPortrait.Wdt, 1));
		if (pCurr->GetBounds() != rcPortraitBounds)
		{
			pCurr->GetBounds() = rcPortraitBounds;
			pCurr->UpdateOwnPos();
		}
		pCurr = static_cast<C4MenuItem *>(pCurr->GetNext());
	}
	else xOff = 0;
	// recheck list items
	int32_t iMaxDlgOptionHeight = -1;
	int32_t iIndex = 0; C4Rect rcNewBounds(0,0,ItemWidth,ItemHeight);
	C4MenuItem *pFirstStack = pCurr, *pNext = pFirstStack;
	while ((pCurr = pNext))
	{
		pNext = static_cast<C4MenuItem *>(pCurr->GetNext());
		if (Style == C4MN_Style_Dialog)
		{
			// y-margin always, except between options
			if (!pPrev || (!pPrev->IsSelectable || !pCurr->IsSelectable)) yOff += C4MN_DlgLineMargin; else yOff += C4MN_DlgOptionLineMargin;
			// determine item height.
			StdStrBuf sText;
			int32_t iAssumedItemHeight = ::GraphicsResource.FontRegular.GetLineHeight();
			int32_t iWdt, iAvailWdt = ItemWidth, iSymWdt;
			for (;;)
			{
				iSymWdt = std::min<int32_t>(pCurr->GetSymbolWidth(iAssumedItemHeight), iAvailWdt/2);
				iAvailWdt = ItemWidth - iSymWdt;
				::GraphicsResource.FontRegular.BreakMessage(pCurr->Caption, iAvailWdt, &sText, true);
				::GraphicsResource.FontRegular.GetTextExtent(sText.getData(),iWdt,rcNewBounds.Hgt, true);
				if (!iSymWdt || rcNewBounds.Hgt <= iAssumedItemHeight) break;
				// If there is a symbol, the symbol grows as more lines become available
				// Thus, less space is available for the text, and it might become larger
				iAssumedItemHeight = rcNewBounds.Hgt;
			}
			if (fEqualIconItemHeight && iSymWdt)
			{
				// force equal height for all symbol items
				if (iMaxDlgOptionHeight < 0)
				{
					// first selectable item inits field
					iMaxDlgOptionHeight = rcNewBounds.Hgt;
				}
				else if (rcNewBounds.Hgt <= iMaxDlgOptionHeight)
				{
					// following item height smaller or equal: Force equal
					rcNewBounds.Hgt = iMaxDlgOptionHeight;
				}
				else
				{
					// following item larger height: Need to re-stack from beginning
					iMaxDlgOptionHeight = rcNewBounds.Hgt;
					pNext = pFirstStack;
					pPrev = NULL;
					yOff = 0;
					iIndex = 0;
					continue;
				}
			}
			assert(iWdt <= iAvailWdt);
			rcNewBounds.x = 0;
			rcNewBounds.y = yOff;
			yOff += rcNewBounds.Hgt;
		}
		else
		{
			rcNewBounds.x = (iIndex % std::max<int32_t>(Columns, 1)) * ItemWidth;
			rcNewBounds.y = (iIndex / std::max<int32_t>(Columns, 1)) * ItemHeight;
		}
		rcNewBounds.x += xOff;
		if (pCurr->GetBounds() != rcNewBounds)
		{
			pCurr->GetBounds() = rcNewBounds;
			pCurr->UpdateOwnPos();
		}
		++iIndex;
		pPrev = pCurr;
	}
	// update scrolling
	pClientWindow->SetClientHeight(rcNewBounds.y + rcNewBounds.Hgt);
	// re-set caption
	C4MenuItem *pSel = GetSelectedItem();
	const char *szCapt;
	if (pSel && Style == C4MN_Style_Normal)
		szCapt = pSel->Caption;
	else
		szCapt = Caption;
	SetTitle((*szCapt || Style == C4MN_Style_Dialog) ? szCapt : " ", HasMouse());
}
Exemplo n.º 10
0
int MenuItem::GetVisualState()
{
	return HasFocus() ?
	       (HasMouse() && GetMouseLeft() || GetMouseRight()) ? PUSH : HIGHLIGHT : NORMAL;
}