Ejemplo n.º 1
0
Archivo: view.cpp Proyecto: kg/ppsspp
void View::PersistData(PersistStatus status, std::string anonId, PersistMap &storage) {
	// Remember if this view was a focused view.
	std::string tag = Tag();
	if (tag.empty()) {
		tag = anonId;
	}

	const std::string focusedKey = "ViewFocused::" + tag;
	switch (status) {
	case UI::PERSIST_SAVE:
		if (HasFocus()) {
			storage[focusedKey].resize(1);
		}
		break;
	case UI::PERSIST_RESTORE:
		if (storage.find(focusedKey) != storage.end()) {
			SetFocus();
		}
		break;
	}
}
Ejemplo n.º 2
0
void DragManipulator::OnMouseButtonPressed(const Mouse::Button& pButton)
{
    if(pButton != Mouse::Button_Left || !HasFocus())
        return;

    Renderer* renderer = GraphicSubsystem::Instance()->GetRenderer();
    GD_ASSERT(renderer);

    // Get the position of the mouse in the screen and widget.
    Int32 x, y;
    InputSubsystem::GetMouse().GetPos(x, y);
    mScreenClickPos = Vector2f(x, y);

    QPoint widgetPos = mEditor->GetMainView()->mapFromGlobal(QPoint(x, y));
    mClickPos = Vector2f(widgetPos.x(), widgetPos.y());

    // Calculate the center position of the manipulated objects.
    mWorldPosition = GetCenterPosition();

    UpdateOriginPositions();
}
Ejemplo n.º 3
0
inline void
TabMenuDisplay::PaintMainMenuItems(Canvas &canvas) const
{
  PaintMainMenuBorder(canvas);

  const bool is_focused = !HasCursorKeys() || HasFocus();

  unsigned main_menu_index = 0;
  for (auto i = main_menu_buttons.begin(),
         end = main_menu_buttons.end(); i != end;
       ++i, ++main_menu_index) {
    const bool isDown = main_menu_index == down_index.main_index &&
      !down_index.IsSub() && !drag_off_button;

    const bool is_selected = isDown ||
      main_menu_index == GetPageMainIndex(cursor);

    main_menu_buttons[main_menu_index].Draw(canvas, look,
                                            is_focused, isDown, is_selected);
  }
}
Ejemplo n.º 4
0
    void ActiveWidget::AcceptInputReset( const InputReset &request)
    {
        Widget *sender = request.Sender();
        _cursor = Pos(-1,-1);
        int i;

        for (i=0; i!=NUM_BUTTONS; ++i)
        {
            if ( _was_touched[i] ) 
            { 
                if (_was_over) OnMoveOut[i].Schedule_1( _cursor );
                OnRelease[i].Schedule_1( _cursor ); 
            }
            _was_touched[i] = false;
            _is_dragging[i] = false;
            _mb_down[i] = false;
        }

        for (i=0; i!=_pressed_keys.Size(); ++i)
        {
            bool likes_this_key = false;
            likes_this_key |= _on_path_key_mask.GetBit( _pressed_keys[i] );
            likes_this_key |= HasFocus() && _key_mask.GetBit( _pressed_keys[i] );
            if ( likes_this_key )
            {
                OnKeyRelease.Schedule_1( _pressed_keys[i]);
            }
        }
        _pressed_keys.Clear();

        if (_was_over || _unsent_outside)
        {
            OnMoveOutside.Schedule_1( _cursor ); HideHint();
        }

        _was_over = false;
        _unsent_outside = false;
        _result = false;
        Widget::Accept( InputReset(this) );
    }
Ejemplo n.º 5
0
void Choice::Draw(UIContext &dc) {
	if (!IsSticky()) {
		ClickableItem::Draw(dc);
	} else {
		Style style =	dc.theme->itemStyle;
		if (highlighted_) {
			style = dc.theme->itemHighlightedStyle;
		}
		if (down_) {
			style = dc.theme->itemDownStyle;
		}
		if (HasFocus()) {
			style = dc.theme->itemFocusedStyle;
		}
		dc.FillRect(style.background, bounds_);
	}

	Style style = dc.theme->itemStyle;
	if (!IsEnabled())
		style = dc.theme->itemDisabledStyle;

	if (atlasImage_ != -1) {
		dc.Draw()->DrawImage(atlasImage_, bounds_.centerX(), bounds_.centerY(), 1.0f, style.fgColor, ALIGN_CENTER);
	} else {
		int paddingX = 12;
		dc.SetFontStyle(dc.theme->uiFont);
		if (centered_) {
			dc.DrawText(text_.c_str(), bounds_.centerX(), bounds_.centerY(), style.fgColor, ALIGN_CENTER);
		} else {
			if (iconImage_ != -1) {
				dc.Draw()->DrawImage(iconImage_, bounds_.x2() - 32 - paddingX, bounds_.centerY(), 0.5f, style.fgColor, ALIGN_CENTER);
			}
			dc.DrawText(text_.c_str(), bounds_.x + paddingX, bounds_.centerY(), style.fgColor, ALIGN_VCENTER);
		}
	}

	if (selected_) {
		dc.Draw()->DrawImage(dc.theme->checkOn, bounds_.x2() - 40, bounds_.centerY(), 1.0f, style.fgColor, ALIGN_CENTER);
	}
}
Ejemplo n.º 6
0
inline void
TabMenuDisplay::PaintSubMenuItems(Canvas &canvas,
                                  const unsigned CaptionStyle) const
{
  const MainMenuButton &main_button =
    GetMainMenuButton(GetPageMainIndex(cursor));

  PaintSubMenuBorder(canvas, main_button);

  assert(main_button.first_page_index < buttons.size());
  assert(main_button.last_page_index < buttons.size());

  const bool is_focused = !HasCursorKeys() || HasFocus();

  for (unsigned first_page_index = main_button.first_page_index,
         last_page_index = main_button.last_page_index,
         page_index = first_page_index;
       page_index <= last_page_index; ++page_index) {
    const unsigned sub_index = page_index - first_page_index;

    const bool is_pressed = sub_index == down_index.sub_index &&
      !drag_off_button;

    const bool is_cursor = page_index == cursor;
    const bool is_selected = is_pressed || is_cursor;

    canvas.SetTextColor(look.list.GetTextColor(is_selected, is_focused,
                                               is_pressed));
    canvas.SetBackgroundColor(look.list.GetBackgroundColor(is_selected,
                                                           is_focused,
                                                           is_pressed));

    const PixelRect &rc = GetSubMenuButtonSize(page_index);
    TabDisplay::PaintButton(canvas, CaptionStyle,
                            gettext(pages[page_index].menu_caption),
                            rc,
                            nullptr, is_cursor,
                            false);
  }
}
Ejemplo n.º 7
0
void AudioDisplay::OnPaint(wxPaintEvent&)
{
	if (!audio_renderer_provider) return;

	wxAutoBufferedPaintDC dc(this);

	wxRect audio_bounds(0, audio_top, GetClientSize().GetWidth(), audio_height);
	bool redraw_scrollbar = false;
	bool redraw_timeline = false;

	for (wxRegionIterator region(GetUpdateRegion()); region; ++region)
	{
		wxRect updrect = region.GetRect();

		redraw_scrollbar |= scrollbar->GetBounds().Intersects(updrect);
		redraw_timeline |= timeline->GetBounds().Intersects(updrect);

		if (audio_bounds.Intersects(updrect))
		{
			TimeRange updtime(
				std::max(0, TimeFromRelativeX(updrect.x - foot_size)),
				std::max(0, TimeFromRelativeX(updrect.x + updrect.width + foot_size)));

			PaintAudio(dc, updtime, updrect);
			PaintMarkers(dc, updtime);
			PaintLabels(dc, updtime);
		}
	}

	if (track_cursor_pos >= 0)
	{
		PaintTrackCursor(dc);
	}

	if (redraw_scrollbar)
		scrollbar->Paint(dc, HasFocus());
	if (redraw_timeline)
		timeline->Paint(dc);
}
Ejemplo n.º 8
0
bool CGUIControl::OnAction(const CAction &action)
{
  if (HasFocus())
  {
    switch (action.GetID())
    {
    case ACTION_MOVE_DOWN:
      OnDown();
      return true;

    case ACTION_MOVE_UP:
      OnUp();
      return true;

    case ACTION_MOVE_LEFT:
      OnLeft();
      return true;

    case ACTION_MOVE_RIGHT:
      OnRight();
      return true;

    case ACTION_SHOW_INFO:
      return OnInfo();

    case ACTION_NAV_BACK:
      return OnBack();

    case ACTION_NEXT_CONTROL:
      OnNextControl();
      return true;

    case ACTION_PREV_CONTROL:
      OnPrevControl();
      return true;
    }
  }
  return false;
}
Ejemplo n.º 9
0
void CNavigationBar::Draw(void) const {
	CWindow::Draw();
	if (m_pSDLSurface)
	{
		CPainter Painter(m_pSDLSurface, CPainter::PAINT_REPLACE);        
		Painter.Draw3DLoweredRect(m_WindowRect.SizeRect(), DEFAULT_BACKGROUND_COLOR);
        SDL_Rect PictureSourceRect = CRect(CPoint(0, 0), 30, 30).SDLRect();
		for (unsigned int i = 0; i < m_Items.size(); ++i)
		{
			CRect ItemRect(CPoint(m_ClientRect.Left() + i*m_iItemWidth, m_ClientRect.Top()),
				m_iItemWidth , m_iItemHeight);
			if (ItemRect.Overlaps(m_ClientRect))
			{
				ItemRect.ClipTo(m_ClientRect);
				ItemRect.SetBottom(ItemRect.Bottom() - 1);
				ItemRect.SetRight(ItemRect.Right() - 1);
				if (i == m_iSelectedItem)
				{
					Painter.DrawRect(ItemRect, true, CApplication::Instance()->GetDefaultSelectionColor(), CApplication::Instance()->GetDefaultSelectionColor());
				}
				if (i == m_iFocusedItem && HasFocus())
				{
					ItemRect.Grow(1);
					Painter.DrawRect(ItemRect, false, CApplication::Instance()->GetDefaultSelectionColor() * 0.7);
					ItemRect.Grow(-1);
				}
				ItemRect.Grow(-1);
        // '- CPoint(0,1)' is to move the reference point one pixel up (otherwise the lowest pixels of p,g,q,y 
        // etc. are not fully visible.
				m_RenderedStrings.at(i).Draw(m_pSDLSurface, ItemRect, ItemRect.BottomLeft() - CPoint(0, 1) + CPoint(ItemRect.Width()/2, 0), m_Items[i].ItemColor);
        // Draw the picture (if available):
        if (m_Bitmaps.at(i) != nullptr) {
          SDL_Rect DestRect = ItemRect.Move(9, 1).SDLRect();
          SDL_BlitSurface(m_Bitmaps.at(i)->Bitmap(), &PictureSourceRect, m_pSDLSurface, &DestRect);
        }
			}
		}
	}
}
Ejemplo n.º 10
0
void
WndCustomButton::OnPaint(Canvas &canvas)
{
#ifdef HAVE_CLIPPING
  /* background and selector */
  canvas.Clear(look.background_brush);
#endif

  PixelRect rc = GetClientRect();

  // Draw focus rectangle
  if (HasFocus()) {
    canvas.DrawFilledRectangle(rc, look.focused.background_color);
    canvas.SetTextColor(IsEnabled()
                        ? look.focused.text_color : look.button.disabled.color);
  } else {
    canvas.DrawFilledRectangle(rc, look.background_color);
    canvas.SetTextColor(IsEnabled() ? look.text_color : look.button.disabled.color);
  }

  // If button has text on it
  tstring caption = get_text();
  if (caption.empty())
    return;

  // If button is pressed, offset the text for 3D effect
  if (is_down())
    OffsetRect(&rc, 1, 1);

  canvas.SelectNullPen();
  canvas.SetBackgroundTransparent();
#ifndef USE_GDI
  canvas.formatted_text(&rc, caption.c_str(), GetTextStyle());
#else
  unsigned s = DT_CENTER | DT_NOCLIP | DT_WORDBREAK;
  canvas.Select(*(look.button.font));
  canvas.formatted_text(&rc, caption.c_str(), s);
#endif
}
Ejemplo n.º 11
0
void Clickable::Key(const KeyInput &key) {
	if (!HasFocus() && key.deviceId != DEVICE_ID_MOUSE) {
		down_ = false;
		return;
	}
	// TODO: Replace most of Update with this.
	if (key.flags & KEY_DOWN) {
		if (IsAcceptKeyCode(key.keyCode)) {
			down_ = true;
		}
	}
	if (key.flags & KEY_UP) {
		if (IsAcceptKeyCode(key.keyCode)) {
			if (down_) {
				Click();
				down_ = false;
			}
		} else if (IsEscapeKeyCode(key.keyCode)) {
			down_ = false;
		}
	}
}
Ejemplo n.º 12
0
void wxBitmapButton::OnSetBitmap()
{
    wxCHECK_RET( m_widget != NULL, wxT("invalid bitmap button") );

    InvalidateBestSize();

    wxBitmap the_one;
    if (!IsThisEnabled())
        the_one = GetBitmapDisabled();
   else if (m_isSelected)
     the_one = GetBitmapPressed();
   else if (HasFocus())
     the_one = GetBitmapFocus();

   if (!the_one.IsOk())
     {
         the_one = GetBitmapLabel();
         if (!the_one.IsOk())
             return;
     }

    GdkBitmap *mask = NULL;
    if (the_one.GetMask()) mask = the_one.GetMask()->GetBitmap();

    GtkWidget *child = BUTTON_CHILD(m_widget);
    if (child == NULL)
    {
        // initial bitmap
        GtkWidget *pixmap;
        pixmap = gtk_pixmap_new(the_one.GetPixmap(), mask);
        gtk_widget_show(pixmap);
        gtk_container_add(GTK_CONTAINER(m_widget), pixmap);
    }
    else
    {   // subsequent bitmaps
        GtkPixmap *pixmap = GTK_PIXMAP(child);
        gtk_pixmap_set(pixmap, the_one.GetPixmap(), mask);
    }
}
Ejemplo n.º 13
0
void CGUIMoverControl::Process(unsigned int currentTime, CDirtyRegionList &dirtyregions)
{
  if (m_bInvalidated)
  {
    m_imgFocus.SetWidth(m_width);
    m_imgFocus.SetHeight(m_height);

    m_imgNoFocus.SetWidth(m_width);
    m_imgNoFocus.SetHeight(m_height);
  }
  if (HasFocus())
  {
    unsigned int alphaCounter = m_frameCounter + 2;
    unsigned int alphaChannel;
    if ((alphaCounter % 128) >= 64)
      alphaChannel = alphaCounter % 64;
    else
      alphaChannel = 63 - (alphaCounter % 64);

    alphaChannel += 192;
    if (SetAlpha( (unsigned char)alphaChannel ))
      MarkDirtyRegion();
    m_imgFocus.SetVisible(true);
    m_imgNoFocus.SetVisible(false);
    m_frameCounter++;
  }
  else
  {
    if (SetAlpha(0xff))
      MarkDirtyRegion();
    m_imgFocus.SetVisible(false);
    m_imgNoFocus.SetVisible(true);
  }
  m_imgFocus.Process(currentTime);
  m_imgNoFocus.Process(currentTime);

  CGUIControl::Process(currentTime, dirtyregions);
}
Ejemplo n.º 14
0
void ColorPusher::Paint(Draw& w)
{
	Size sz = GetSize();
	w.DrawRect(sz, push ? SColorHighlight : SColorPaper);
	int ty = (sz.cy - StdFont().Info().GetHeight()) / 2;
	if(withtext) {
		w.DrawRect(2, 2, sz.cy - 4, sz.cy - 4, color);
		DrawFrame(w, 1, 1, sz.cy - 2, sz.cy - 2, SColorText);
		w.DrawText(sz.cy + 2, ty, FormatColor(color), StdFont(), SColorText());
	}
	else {
		if(!IsNull(color)) {
			w.DrawRect(2, 2, sz.cx - 4, sz.cy - 4, color);
			DrawFrame(w, 1, 1, sz.cx - 2, sz.cy - 2, SColorText);
		}
		else
		if(!withtext)
			w.DrawText(max(2, (sz.cx - GetTextSize(nulltext, StdFont()).cx) / 2), ty,
			           nulltext, StdFont(), SColorText());
	}
	if(HasFocus())
		DrawFocus(w, GetSize());
}
Ejemplo n.º 15
0
	virtual void PerformLayout()
	{
		TextImage *textImage = GetTextImage();
		if (m_bSelected)
		{
			VPANEL focus = input()->GetFocus();
			// if one of the children of the SectionedListPanel has focus, then 'we have focus' if we're selected
			if (HasFocus() || (focus && ipanel()->HasParent(focus, GetVParent())))
			{
				textImage->SetColor(m_ArmedFgColor2);
			}
			else
			{
				textImage->SetColor(m_FgColor2);
			}
		}
		else
		{
			textImage->SetColor(GetFgColor());					
		}
		BaseClass::PerformLayout();
		Repaint();
	}
Ejemplo n.º 16
0
void ScatterCtrl::Paint(Draw& w)
{
    GuiLock __;
    if (IsNull(highlight_0) && highlighting) {
        highlighting = false;
        KillTimeCallback();
    }
    if (!IsNull(highlight_0) && !highlighting) {
        highlighting = true;
        SetTimeCallback(-200, THISBACK(TimerCallback));
    }
    TimeStop t;
    lastRefresh0_ms = GetTickCount();
    if (IsEnabled()) {
        if (mode == MD_DRAW) {
            ScatterCtrl::SetDrawing(w, GetSize(), 1);
            PlotTexts(w, GetSize(), 1);
        } else {
            ImageBuffer ib(GetSize());
            BufferPainter bp(ib, mode);
            ScatterCtrl::SetDrawing(bp, GetSize(), 1);
            w.DrawImage(0, 0, ib);
            PlotTexts(w, GetSize(), 1);
        }
        if (HasFocus()) {
            w.DrawLine(0, 0, GetSize().cx, 0, 2, LtGray());
            w.DrawLine(0, 0, 0, GetSize().cy, 2, LtGray());
            int delta = -2;
#ifdef PLATFORM_WIN32
            delta = 0;
#endif
            w.DrawLine(GetSize().cx+delta, 0, GetSize().cx+delta, GetSize().cy, 2, LtGray());
            w.DrawLine(0, GetSize().cy+delta, GetSize().cx, GetSize().cy+delta, 2, LtGray());
        }
    }
    lastRefresh_ms = t.Elapsed();
}
Ejemplo n.º 17
0
	virtual void PaintBackground()	
	{
		int wide, tall;
		GetSize(wide, tall);

		if ( m_bSelected )
		{
            VPANEL focus = input()->GetFocus();
            // if one of the children of the SectionedListPanel has focus, then 'we have focus' if we're selected
            if (HasFocus() || (focus && ipanel()->HasParent(focus, GetVParent())))
            {
			    surface()->DrawSetColor(m_ArmedBgColor);
            }
            else
            {
			    surface()->DrawSetColor(m_SelectionBG2Color);
            }
		}
		else
		{
			surface()->DrawSetColor(GetBgColor());
		}
		surface()->DrawFilledRect(0, 0, wide, tall);
	}
Ejemplo n.º 18
0
void BrowseTileListBox::OnDrawItem(wxDC& dc, const wxRect& rect, size_t n) const
{
	ItemsMap::const_iterator item_iterator = items.find(int(n));
	Item* item = item_iterator->second;

	Sprite* sprite = g_gui.gfx.getSprite(item->getClientID());
	if(sprite)
		sprite->DrawTo(&dc, SPRITE_SIZE_32x32, rect.GetX(), rect.GetY(), rect.GetWidth(), rect.GetHeight());

	if(IsSelected(n)) {
		item->select();
		if(HasFocus())
			dc.SetTextForeground(wxColor(0xFF, 0xFF, 0xFF));
		else
			dc.SetTextForeground(wxColor(0x00, 0x00, 0xFF));
	} else {
		item->deselect();
		dc.SetTextForeground(wxColor(0x00, 0x00, 0x00));
	}

	wxString label;
	label << item->getID() << " - " << item->getName();
	dc.DrawText(label, rect.GetX() + 40, rect.GetY() + 6);
}
Ejemplo n.º 19
0
void CGUIResizeControl::Render()
{
  if (m_bInvalidated)
  {
    m_imgFocus.SetWidth(m_width);
    m_imgFocus.SetHeight(m_height);

    m_imgNoFocus.SetWidth(m_width);
    m_imgNoFocus.SetHeight(m_height);
  }
  if (HasFocus())
  {
    DWORD dwAlphaCounter = m_dwFrameCounter + 2;
    DWORD dwAlphaChannel;
    if ((dwAlphaCounter % 128) >= 64)
      dwAlphaChannel = dwAlphaCounter % 64;
    else
      dwAlphaChannel = 63 - (dwAlphaCounter % 64);

    dwAlphaChannel += 192;
    SetAlpha( (unsigned char)dwAlphaChannel );
    m_imgFocus.SetVisible(true);
    m_imgNoFocus.SetVisible(false);
    m_dwFrameCounter++;
  }
  else
  {
    SetAlpha(0xff);
    m_imgFocus.SetVisible(false);
    m_imgNoFocus.SetVisible(true);
  }
  // render both so the visibility settings cause the frame counter to resetcorrectly
  m_imgFocus.Render();
  m_imgNoFocus.Render();
  CGUIControl::Render();
}
Ejemplo n.º 20
0
void wxSkinWindow::OnPaint(wxPaintEvent& e)
{
	wxBufferedPaintDC dcp(this);

	wxSize size = GetSize();

	if(m_inside && m_imageOver.IsOk())
	{
		dcp.DrawBitmap(m_scaleFill ? wxBitmap(m_imageOver.Scale(size.x, size.y)) : m_imageOver, 0, 0, true);
	}
	else if(IsEnabled() && (m_imageNormal.IsOk() || m_imageFocus.IsOk()))
	{
		if(m_imageFocus.IsOk() && HasFocus())
			dcp.DrawBitmap(m_scaleFill ? wxBitmap(m_imageFocus.Scale(size.x, size.y)) : m_imageFocus, 0, 0, true);
		else
			dcp.DrawBitmap(m_scaleFill ? wxBitmap(m_imageNormal.Scale(size.x, size.y)) : m_imageNormal, 0, 0, true);
	}
	else if(m_imageDisabled.IsOk())
	{
		dcp.DrawBitmap(m_scaleFill ? wxBitmap(m_imageDisabled.Scale(size.x, size.y)) : m_imageDisabled, 0, 0, true);
	}
	
	DrawCustom(dcp);
}
Ejemplo n.º 21
0
// This method is called every time the player moves the mouse
void CGame::MouseMotion(int x, int y)
{
	if (!HasFocus())
	{
		// Swallow the input while the window isn't in focus so the player
		// isn't facing off in a strange direction when they tab back in.
		m_iLastMouseX = x;
		m_iLastMouseY = y;
		return;
	}

	if (m_iLastMouseX == -1 && m_iLastMouseY == -1)
	{
		m_iLastMouseX = x;
		m_iLastMouseY = y;
	}

	int iMouseMovedX = x - m_iLastMouseX;
	int iMouseMovedY = m_iLastMouseY - y; // The data comes in backwards. negative y means the mouse moved up.

	if (!m_hPlayer)
		return;

	float flSensitivity = 0.3f;

	EAngle angView = m_hPlayer->GetLocalView();

	angView.p += iMouseMovedY*flSensitivity;
	angView.y += iMouseMovedX*flSensitivity;
	angView.Normalize();

	m_hPlayer->SetLocalView(angView);

	m_iLastMouseX = x;
	m_iLastMouseY = y;
}
Ejemplo n.º 22
0
void XGPopControl::DoDrawView(XRect)
{
#if OPT_MACOS
	if (fControl) {
		XGDraw draw(this,false);
		if (fFont) {
			fFont->Attach();
			draw.SetFont(fFont);
		}
		
		if (IsEnabled() && IsActive()) {
			/*
			 *	Enabled
			 */
			
			::HiliteControl(fControl, 0);
		} else {
			::HiliteControl(fControl, 255);
		}
		::ShowControl(fControl);
		::Draw1Control(fControl);
		return;
	}
#endif

#if OPT_WINOS
	if (fControl) {
		/*
		 *	The invalidate here may seem a little wierd, but this
		 *	causes the control to redraw itself separately, and after
		 *	this draw view command is issued. The upshot of this is
		 *	that the control is forced to be redrawn.
		 */
		
		::ShowWindow(fControl, SW_SHOW);
		::InvalidateRect(fControl, NULL, false);
	}
	return;
#endif

#if OPT_XWIN || OPT_MACOS
	/*
	 *	(MacOS): if we get here, use simulated popup. Happens when we don't
	 *	have the appearance manager.
	 */
	
	XRect r;
	XRect s;
	XRect t;
	XGDraw draw(this);
	fFont->Attach();
	draw.SetFont(fFont);
	
	r = GetContentRect();
	s = r;
	InsetRect(&s,1,1);
	t = s;
	s.left = s.right - (s.bottom - s.top);
	t.right = s.left;
	
	draw.Draw3DRect(r,KXGEBackground);
	if (IsEnabled() && IsActive()) {
		if (fPop) {
			draw.Draw3DRect(r,KXGEFrame);
			draw.Draw3DRect(s,KXGEInset);
			draw.Draw3DRect(t,KXGEInset);
		} else {
			draw.Draw3DRect(r,KXGEFrame);
			draw.Draw3DRect(s,KXGEOutset);
			draw.Draw3DRect(t,KXGEOutset);
		}
	} else {
		draw.Draw3DRect(r,KXGEGrayFrame);
		draw.SetForeColor(KXGColorBtnShadow);
	}
	InsetRect(&s,5,5);
	
	draw.MoveTo(s.left,(s.top*3+s.bottom)/4);
	draw.LineTo(s.right,(s.top*3+s.bottom)/4);
	draw.LineTo((s.left+s.right)/2,(s.top+3*s.bottom)/4);
	draw.LineTo(s.left,(s.top*3+s.bottom)/4);
	
	s = r;
	s.right -= s.bottom - s.top;
	InsetRect(&s,1,1);
	draw.ClipRect(&s);
	
#if OPT_WINOS || OPT_XWIN
	if (HasFocus() && IsEnabled() && IsActive()) {
		InsetRect(&s,1,1);
		draw.DrawFocusRect(s);
		InsetRect(&s,-1,-1);
	}
#endif

	draw.MoveTo(s.left + 3,
				(s.top + s.bottom - draw.GetFontHeight())/2+draw.GetFontAscent());

	if (fValue < Length()) {
		char buffer[256];
		GetItem(fValue,buffer);
		draw.DrawString(buffer);
	}
#endif
}
Ejemplo n.º 23
0
bool Widget::HasFocus() {
	return HasFocus( shared_from_this() );
}
Ejemplo n.º 24
0
void Widget::HandleEvent( const sf::Event& event ) {
	if( !IsGloballyVisible() ) {
		return;
	}

	// Ignore the event if widget is insensitive
	if ( GetState() == State::INSENSITIVE ) {
		return;
	}

	// Ignore the event if another widget is active.
	if( !IsActiveWidget() && !IsActiveWidget( PtrConst() ) ) {
		return;
	}

	// Ignore the event if another widget is modal.
	if( HasModal() && !IsModal() ) {
		return;
	}

	// Set widget active in context.
	Context::Get().SetActiveWidget( shared_from_this() );

	auto parent = m_parent.lock();

	auto emit_leave = false;
	auto emit_enter = false;
	auto emit_move = false;
	auto emit_left_click = false;
	auto emit_right_click = false;

	try {
		switch( event.type ) {
			case sf::Event::MouseLeft:
				if( IsMouseInWidget() ) {
					SetMouseInWidget( false );

					HandleMouseLeave( std::numeric_limits<int>::min(), std::numeric_limits<int>::min() );

					emit_leave = true;
				}

				HandleMouseMoveEvent( std::numeric_limits<int>::min(), std::numeric_limits<int>::min() );

				SetMouseButtonDown();
				HandleMouseButtonEvent( sf::Mouse::Left, false, std::numeric_limits<int>::min(), std::numeric_limits<int>::min() );
				HandleMouseButtonEvent( sf::Mouse::Right, false, std::numeric_limits<int>::min(), std::numeric_limits<int>::min() );

				if( emit_leave ) {
					GetSignals().Emit( OnMouseLeave );
				}

				break;

			case sf::Event::MouseMoved:
				// Check if pointer inside of widget's allocation.
				if( GetAllocation().contains( static_cast<float>( event.mouseMove.x ), static_cast<float>( event.mouseMove.y ) ) ) {
					// Check for enter event.
					if( !IsMouseInWidget() ) {
						SetMouseInWidget( true );

						emit_enter = true;

						HandleMouseEnter( event.mouseMove.x, event.mouseMove.y );
					}

					emit_move = true;
				}
				else if( IsMouseInWidget() ) { // Check for leave event.
					SetMouseInWidget( false );

					emit_leave = true;

					HandleMouseLeave( event.mouseMove.x, event.mouseMove.y );
				}

				HandleMouseMoveEvent( event.mouseMove.x, event.mouseMove.y );

				if( emit_move ) {
					if( emit_enter ) {
						GetSignals().Emit( OnMouseEnter );
					}

					GetSignals().Emit( OnMouseMove );
				}
				else if( emit_leave ) {
					GetSignals().Emit( OnMouseLeave );
				}

				break;

			case sf::Event::MouseButtonPressed:
				if( !IsMouseButtonDown() && IsMouseInWidget() ) {
					SetMouseButtonDown( event.mouseButton.button );
				}

				HandleMouseButtonEvent( event.mouseButton.button, true, event.mouseButton.x, event.mouseButton.y );

				if( IsMouseInWidget() ) {
					if( event.mouseButton.button == sf::Mouse::Left ) {
						GetSignals().Emit( OnMouseLeftPress );
					}
					else if( event.mouseButton.button == sf::Mouse::Right ) {
						GetSignals().Emit( OnMouseRightPress );
					}
				}

				break;

			case sf::Event::MouseButtonReleased:
				// Only process as a click when mouse button has been pressed inside the widget before.
				if( IsMouseButtonDown( event.mouseButton.button ) ) {
					SetMouseButtonDown();

					// When released inside the widget, the event can be considered a click.
					if( IsMouseInWidget() ) {
						HandleMouseClick( event.mouseButton.button, event.mouseButton.x, event.mouseButton.y );

						if( event.mouseButton.button == sf::Mouse::Left ) {
							emit_left_click = true;
						}
						else if( event.mouseButton.button == sf::Mouse::Right ) {
							emit_right_click = true;
						}
					}
				}

				HandleMouseButtonEvent( event.mouseButton.button, false, event.mouseButton.x, event.mouseButton.y );

				if( emit_left_click ) {
					GetSignals().Emit( OnLeftClick );
				}
				else if( emit_right_click ) {
					GetSignals().Emit( OnRightClick );
				}

				if( IsMouseInWidget() ) {
					if( event.mouseButton.button == sf::Mouse::Left ) {
						GetSignals().Emit( OnMouseLeftRelease );
					}
					else if( event.mouseButton.button == sf::Mouse::Right ) {
						GetSignals().Emit( OnMouseRightRelease );
					}
				}

				break;

			case sf::Event::KeyPressed:
				if( HasFocus() ) {
					// TODO: Delegate event too when widget's not active?
					HandleKeyEvent( event.key.code, true );
					GetSignals().Emit( OnKeyPress );
				}

				break;

			case sf::Event::KeyReleased:
				if( HasFocus() ) {
					// TODO: Delegate event too when widget's not active?
					HandleKeyEvent( event.key.code, false );
					GetSignals().Emit( OnKeyRelease );
				}
				break;

			case sf::Event::TextEntered:
				if( HasFocus() ) {
					// TODO: Delegate event too when widget's not active?
					HandleTextEvent( event.text.unicode );
					GetSignals().Emit( OnText );
				}
				break;

			default:
				break;
		}
	}
	catch( ... ) {
		SetState( State::NORMAL );
		throw;
	}
}
Ejemplo n.º 25
0
// update gui
void NetPlayDialog::OnThread(wxThreadEvent& event)
{
    if (m_is_hosting && m_host_label && g_TraversalClient)
    {
        UpdateHostLabel();
    }

    // player list
    m_playerids.clear();
    std::string tmps;
    netplay_client->GetPlayerList(tmps, m_playerids);

    wxString selection;
    if (m_player_lbox->GetSelection() != wxNOT_FOUND)
        selection = m_player_lbox->GetString(m_player_lbox->GetSelection());

    m_player_lbox->Clear();
    std::istringstream ss(tmps);
    while (std::getline(ss, tmps))
        m_player_lbox->Append(StrToWxStr(tmps));

    // remove ping from selection string, in case it has changed
    selection.erase(selection.rfind('|') + 1);

    if (!selection.empty())
    {
        for (unsigned int i = 0; i < m_player_lbox->GetCount(); ++i)
        {
            if (selection == m_player_lbox->GetString(i).substr(0, selection.length()))
            {
                m_player_lbox->SetSelection(i);
                break;
            }
        }
    }

    // flash window in taskbar when someone joins if window isn't active
    static u8 numPlayers = 1;
    if (netplay_server != nullptr && numPlayers < m_playerids.size() && !HasFocus())
    {
        RequestUserAttention();
    }
    numPlayers = m_playerids.size();

    switch (event.GetId())
    {
    case NP_GUI_EVT_CHANGE_GAME:
        // update selected game :/
    {
        m_selected_game = WxStrToStr(event.GetString());

        wxString button_label = event.GetString();
        m_game_btn->SetLabel(button_label.Prepend(_(" Game : ")));
    }
    break;
    case NP_GUI_EVT_START_GAME:
        // client start game :/
    {
        netplay_client->StartGame(FindGame());
    }
    break;
    case NP_GUI_EVT_STOP_GAME:
        // client stop game
    {
        netplay_client->StopGame();
    }
    break;
    }

    // chat messages
    while (chat_msgs.Size())
    {
        std::string s;
        chat_msgs.Pop(s);
        // PanicAlert("message: %s", s.c_str());
        m_chat_text->AppendText(StrToWxStr(s).Append('\n'));
    }
}
Ejemplo n.º 26
0
void MultiButton::Paint(Draw& w)
{
	Size sz = GetSize();
	int border, lx, rx;
	bool frm = Metrics(border, lx, rx);
	int mst = ChState(MAIN);
	if(frm && !nobg)
		ChPaint(w, sz, style->edge[style->activeedge ? mst : 0]);
	bool left = false;
	bool right = false;
	for(int i = 0; i < button.GetCount(); i++) {
		SubButton& b = button[i];
		int st = ChState(i);
		int x = 0, cx = 0;
		GetPos(b, lx, rx, x, cx);
		bool dopaint = true;
		Value v = b.left ? left ? style->lmiddle[st] : style->left[st]
		                 : right ? style->rmiddle[st] : style->right[st];
		if(!nobg) {
			if(ComplexFrame())
				ChPaint(w, x, border, cx, sz.cy - 2 * border, style->simple[st]);
			else
			if(frm) {
				if(IsTrivial() && style->usetrivial)
					dopaint = false;
				ChPaint(w, x, border, cx, sz.cy - 2 * border,
				        dopaint ? v : style->trivial[st]);
			}
			else {
				w.Clip(x, 0, cx, sz.cy);
				ChPaint(w, sz, style->look[Frame() ? mst : st]);
				if(IsNull(v) || !Frame()) {
					if((!IsTrivial() || style->trivialsep) && IsEnabled()) {
						if(b.left) {
							if(left)
								ChPaint(w, x, style->sepm, 1, sz.cy - 2 * style->sepm, style->sep1);
							ChPaint(w, x + cx - 1, style->sepm, 1, sz.cy - 2 * style->sepm, style->sep2);
						}
						else {
							ChPaint(w, x, style->sepm, 1, sz.cy - 2 * style->sepm, style->sep1);
							if(right)
								ChPaint(w, x + cx - 1, style->sepm, 1, sz.cy - 2 * style->sepm, style->sep2);
						}
					}
				}
				else
					ChPaint(w, x, 0, cx, sz.cy, v);
				w.End();
			}
		}
		if(dopaint) {
			Size tsz = GetTextSize(b.label, StdFont());
			Image m = tsz.cx > 0 ? b.img : (Image)Nvl(b.img, CtrlsImg::DA());
			Size isz = m.GetSize();
			Point p = (st == CTRL_PRESSED) * style->pressoffset;
			p.x += x + (cx - isz.cx - tsz.cx - (tsz.cx > 0 && isz.cx > 0 ? LB_IMAGE : 0)) / 2;
			p.y += (sz.cy - isz.cy) / 2;
			if(b.left) {
				if(!left) p.x += style->loff;
			}
			else
				if(!right) p.x += style->roff;
			if(b.monoimg || IsNull(b.img))
				w.DrawImage(p.x, p.y, m, frm ? style->fmonocolor[st] : style->monocolor[st]);
			else
				w.DrawImage(p.x, p.y, m);

			if(tsz.cx > 0) {
				if(isz.cx > 0)
					p.x += isz.cx + LB_IMAGE;
				w.DrawText(p.x, (sz.cy - tsz.cy) / 2, b.label);
			}
		}
		(b.left ? left : right) = true;
	}
	Rect r, cr;
	cr = GetSize();
	cr.left = lx;
	cr.right = rx;
	Color text = SColorLabel();
	Color paper = Null;
	if(!nobg) {
		if(ComplexFrame()) {
			r = cr;
			paper = HasFocus() ? SColorHighlight() : SColorPaper();
			if(HasFocus())
				text = SColorHighlightText();
			w.DrawRect(r, paper);
		}
		else
		if(frm) {
			Rect m = GetMargin();
			r = Rect(max(lx, m.left), m.top, min(rx, sz.cx - m.right), sz.cy - m.bottom);
			Color paper;
			if(mst == CTRL_HOT && !IsTrivial())
				paper = Blend(SColorHighlight, SColorPaper, 235);
			else
			if(mst == CTRL_PRESSED && !IsTrivial())
				paper = Blend(SColorHighlight, SColorFace, 235);
			else
			if(HasFocus()) {
				paper = SColorHighlight();
				text = SColorHighlightText();
			}
			else
				paper = SColorPaper();
			w.DrawRect(r, paper);
			cr = r;
		}
		else {
			w.Clip(lx, 0, rx - lx, sz.cy);
			ChPaint(w, sz, style->look[mst]);
			Rect m = style->margin;
			r = Rect(max(lx, m.left), m.top, min(rx, sz.cx - m.right), sz.cy - m.bottom);
			if(!IsTrivial() || style->trivialsep) {
				if(left) {
					r.left++;
					if(IsEnabled())
						ChPaint(w, lx, style->sepm, 1, sz.cy - 2 * style->sepm, style->sep1);
				}
				if(right) {
					if(IsEnabled())
						ChPaint(w, rx - 1, style->sepm, 1, sz.cy - 2 * style->sepm, style->sep2);
					r.right--;
				}
			}
			w.End();
			cr = r;
		}
	}
	cr.left++;
	Rect clr = cr;
	if(!IsNull(valuecy)) {
		cr.top += (cr.GetHeight() - valuecy + 1) / 2;
		cr.bottom = cr.top + valuecy;
	}
	Value v = convert->Format(value);
	bool f = HasFocus() && !push && frm;
	if(cr.left < cr.right && display) {
		w.Clip(clr);
		display->Paint(w, cr, v,
		               IsShowEnabled() ? text : SColorDisabled,
		               paper, f ? Display::CURSOR : Display::FOCUS|Display::CURSOR);
		w.End();
	}
	if(!frm && HasFocus())
		DrawFocus(w, r);
}
Ejemplo n.º 27
0
 void    Widget::GiveFocusTo(Widget* widget)
 {
     if (!HasFocus())
         return;
     Widget::mFocusedWidget = widget;
 }
Ejemplo n.º 28
0
bool CGUIBaseContainer::OnAction(const CAction &action)
{
  if (action.GetID() >= KEY_ASCII)
  {
    OnJumpLetter((char)(action.GetID() & 0xff));
    return true;
  }
  // stop the timer on any other action
  m_matchTimer.Stop();

  switch (action.GetID())
  {
  case ACTION_MOVE_LEFT:
  case ACTION_MOVE_RIGHT:
  case ACTION_MOVE_DOWN:
  case ACTION_MOVE_UP:
  case ACTION_NAV_BACK:
  case ACTION_PREVIOUS_MENU:
    {
      if (!HasFocus()) return false;

      if (action.GetHoldTime() > HOLD_TIME_START &&
        ((m_orientation == VERTICAL && (action.GetID() == ACTION_MOVE_UP || action.GetID() == ACTION_MOVE_DOWN)) ||
         (m_orientation == HORIZONTAL && (action.GetID() == ACTION_MOVE_LEFT || action.GetID() == ACTION_MOVE_RIGHT))))
      { // action is held down - repeat a number of times
        float speed = std::min(1.0f, (float)(action.GetHoldTime() - HOLD_TIME_START) / (HOLD_TIME_END - HOLD_TIME_START));
        unsigned int frameDuration = std::min(CTimeUtils::GetFrameTime() - m_lastHoldTime, 50u); // max 20fps

        // maximal scroll rate is at least 30 items per second, and at most (item_rows/7) items per second
        //  i.e. timed to take 7 seconds to traverse the list at full speed.
        // minimal scroll rate is at least 10 items per second
        float maxSpeed = std::max(frameDuration * 0.001f * 30, frameDuration * 0.001f * GetRows() / 7);
        float minSpeed = frameDuration * 0.001f * 10;
        m_scrollItemsPerFrame += std::max(minSpeed, speed*maxSpeed); // accelerate to max speed
        m_lastHoldTime = CTimeUtils::GetFrameTime();

        if(m_scrollItemsPerFrame < 1.0f)//not enough hold time accumulated for one step
          return true;

        while (m_scrollItemsPerFrame >= 1)
        {
          if (action.GetID() == ACTION_MOVE_LEFT || action.GetID() == ACTION_MOVE_UP)
            MoveUp(false);
          else
            MoveDown(false);
          m_scrollItemsPerFrame--;
        }
        return true;
      }
      else
      {
        //if HOLD_TIME_START is reached we need
        //a sane initial value for calculating m_scrollItemsPerPage
        m_lastHoldTime = CTimeUtils::GetFrameTime();
        m_scrollItemsPerFrame = 0.0f;
        return CGUIControl::OnAction(action);
      }
    }
  case ACTION_CONTEXT_MENU:
    if (OnContextMenu())
      return true;
    break;
  case ACTION_SHOW_INFO:
    if (m_listProvider)
    {
      int selected = GetSelectedItem();
      if (selected >= 0 && selected < static_cast<int>(m_items.size()))
      {
        m_listProvider->OnInfo(m_items[selected]);
        return true;
      }
    }
    else if (OnInfo())
      return true;
    else if (action.GetID())
      return OnClick(action.GetID());
    else
      return false;

  case ACTION_FIRST_PAGE:
    SelectItem(0);
    return true;

  case ACTION_LAST_PAGE:
    if (m_items.size())
      SelectItem(m_items.size() - 1);
    return true;

  case ACTION_NEXT_LETTER:
    OnNextLetter();
    return true;
  case ACTION_PREV_LETTER:
    OnPrevLetter();
    return true;
  case ACTION_JUMP_SMS2:
  case ACTION_JUMP_SMS3:
  case ACTION_JUMP_SMS4:
  case ACTION_JUMP_SMS5:
  case ACTION_JUMP_SMS6:
  case ACTION_JUMP_SMS7:
  case ACTION_JUMP_SMS8:
  case ACTION_JUMP_SMS9:
    OnJumpSMS(action.GetID() - ACTION_JUMP_SMS2 + 2);
    return true;

  default:
    break;
  }
  return action.GetID() && OnClick(action.GetID());
}
Ejemplo n.º 29
0
bool FindReplace::FindInAllFiles( Searchable::Direction direction )
{
    Searchable *searchable = 0;

    bool found = false;
    if ( IsCurrentFileInHTMLSelection() )
    {
        searchable = GetAvailableSearchable();
        if ( searchable )
        {
            found = searchable->FindNext( GetSearchRegex(), direction, m_SpellCheck, false, false);
        }
    }

    if ( !found )
    {
        // TODO: make this handle all types of files
        Resource *containing_resource = GetNextContainingHTMLResource( direction );

        if ( containing_resource )
        {
            // Save if editor or F&R has focus
            bool has_focus = HasFocus();

            // Save selected resources since opening tabs changes selection
            QList<Resource *>selected_resources = GetHTMLFiles();

            m_MainWindow.OpenResource( *containing_resource);

            while ( !m_MainWindow.GetCurrentContentTab().IsLoadingFinished() )
            {
                // Make sure Qt processes events, signals and calls slots
                qApp->processEvents();
                SleepFunctions::msleep( 100 );
            }

            // Restore selection since opening tabs changes selection 
            if ( GetLookWhere() == FindReplace::LookWhere_SelectedHTMLFiles && !m_SpellCheck)
            {
                m_MainWindow.SelectResources(selected_resources);
            }

            // Reset focus to F&R if it had it
            if (has_focus) {
                SetFocus();
            }

            searchable = GetAvailableSearchable();
            if ( searchable )
            {
                found = searchable->FindNext( GetSearchRegex(), direction, m_SpellCheck, true, false );
            }
        }
        else
        {
            if ( searchable )
            {
                // Check the part of the original file above the cursor
                found = searchable->FindNext( GetSearchRegex(), direction, m_SpellCheck, false, false );
            }
        }
    }

    return found;
}
Ejemplo n.º 30
0
void LineEdit::MouseMove(Point p, dword flags) {
	if((flags & K_MOUSELEFT) && HasFocus() && HasCapture()) {
		int c = GetMousePos(p);
		PlaceCaret(c, mpos != c || HasCapture());
	}
}