Esempio n. 1
0
void pawsLoadWindow::InitAnim(csVector2 start, csVector2 dest, csTicks delay)
{
    //if we lack the picture for the anim we don't render it
    if(!dot)
    {
        Error1("Couldn't find the picture to be used for the movement anim. Animation Aborted.");
        return;
    }

    float length;
    renderAnim = true;
    startFrom = 0;
    lastPos = start;
    destination = dest;

    //adjust the anim to resolution
    lastPos.x = GetActualWidth((int)lastPos.x);
    lastPos.y = GetActualHeight((int)lastPos.y);
    destination.x = GetActualWidth((int)destination.x);
    destination.y = GetActualHeight((int)destination.y);

    positions.DeleteAll();
    
    csVector2 direction = destination - lastPos;
    length = direction.Norm();

    numberDot = (int)ceil(length / 40);

    //we make the dots complete a bit before the end of the delay so it's
    //possible to see the last dot
    delayBetDot = ((delay * 1000)*0.9) / numberDot;
}
Esempio n. 2
0
void pawsExchangeWindow::StartExchange( csString& player, bool withPlayer )
{
    csString text;
    if(!player.IsEmpty())
    {
        text.Format("Trading with %s",player.GetData());
    }

    int width;

    Clear();            
    Show();
            
    pawsTextBox* textBox = dynamic_cast <pawsTextBox*> (FindWidget("other_player"));
    if (textBox != NULL)
        textBox->SetText( text );

    if (withPlayer)
        width = 350;
    else
        width = 175;
    SetRelativeFrameSize(GetActualWidth(width), defaultFrame.Height());

    // Autoshow the inventory
    pawsWidget* widget = PawsManager::GetSingleton().FindWidget("SmallInventoryWindow");
    
    if (widget)
    {
        wasSmallInventoryOpen = widget->IsVisible();
        widget->Show();
    }
}        
Esempio n. 3
0
File: media.cpp Progetto: snorp/moon
Rect
Image::GetCoverageBounds ()
{
	// FIXME: SL3 final only supports PixelFormatPbgra32 which makes this optimization
	// obsolete - unless we keep an "has_alpha" flag with each image ?!?
	return Rect ();
#if FALSE
	ImageSource *source = GetSource ();

	if (!source || source->GetPixelFormat () == PixelFormatPbgra32)
		return Rect ();

	Stretch stretch = GetStretch ();
	if (stretch == StretchFill || stretch == StretchUniformToFill)
		return bounds;

	cairo_matrix_t matrix;
	Rect image = Rect (0, 0, source->GetPixelWidth (), source->GetPixelHeight ());
	Rect paint = Rect (0, 0, GetActualWidth (), GetActualHeight ());

	image_brush_compute_pattern_matrix (&matrix, 
					    paint.width, paint.height,
					    image.width, image.height, stretch, 
					    AlignmentXCenter, AlignmentYCenter, NULL, NULL);

	cairo_matrix_invert (&matrix);
	cairo_matrix_multiply (&matrix, &matrix, &absolute_xform);

	image = image.Transform (&matrix);
	image = image.Intersection (bounds);
	
	return image;
#endif
}
Esempio n. 4
0
void
Grid::PostRender (Context *ctx, Region *region, bool skip_children)
{
	// render our chidren if we need to
	if (!skip_children) {
		VisualTreeWalker walker = VisualTreeWalker (this, ZForward, false);
		while (UIElement *child = walker.Step ())
			child->DoRender (ctx, region);
	}
	
	if (GetShowGridLines () && ctx->IsMutable ()) {
		double offset = 0;
		double dash = 4;
		ColumnDefinitionCollection *cols = GetColumnDefinitionsNoAutoCreate ();
		RowDefinitionCollection *rows = GetRowDefinitionsNoAutoCreate ();
		cairo_t *cr = ctx->Cairo ();
		int col_count = cols ? cols->GetCount () : 0;
		int row_count = rows ? rows->GetCount () : 0;
		
		cairo_save (cr);
		RenderLayoutClip (cr);
		cairo_set_line_width(cr, 1.0);
		// Initially render a blue color
		cairo_set_dash (cr, &dash, 1, offset);
		cairo_set_source_rgb (cr, 0.4, 0.4, 1.0);
		cairo_new_path (cr);

		// Draw gridlines between each pair of columns/rows
		for (int count = 0; count < 2; count++) {
			for (int i = 0, offset = 0; i < col_count - 1; i++) {
				ColumnDefinition *def = cols->GetValueAt (i)->AsColumnDefinition ();
				offset += def->GetActualWidth ();
				cairo_move_to (cr, offset, 0);
				cairo_line_to (cr, offset, GetActualHeight ());
			}
			
			for (int i = 0, offset = 0; i < row_count - 1; i++) {
				RowDefinition *def = rows->GetValueAt (i)->AsRowDefinition ();
				offset += def->GetActualHeight ();
				cairo_move_to (cr, 0, offset);
				cairo_line_to (cr, GetActualWidth (), offset);
			}
			
			cairo_stroke (cr);
			
			// For the second pass render a yellow color in the gaps between the previous dashes
			cairo_set_dash (cr, &dash, 1, dash);
			cairo_set_source_rgb (cr, 1.0, 1.0, 0.3);
		}
		cairo_restore (cr);
	}		

	// Chain up, but skip children since we've already rendered them here.
	UIElement::PostRender (ctx, region, true);
}
Esempio n. 5
0
void
Grid::ComputeBounds ()
{
	Panel::ComputeBounds ();
	
	if (GetShowGridLines ()) {
		extents = Rect (0,0,GetActualWidth (),GetActualHeight ());
		extents_with_children = extents_with_children.Union (extents);
		bounds = IntersectBoundsWithClipPath (extents.GrowBy (effect_padding), false).Transform (&absolute_xform);
		bounds_with_children = bounds_with_children.Union (bounds);

		ComputeGlobalBounds ();
		ComputeSurfaceBounds ();
	}
}
bool pawsSelectorBox::Setup(iDocumentNode* node)
{
    ///////////////////////////////////////////////////////////////////////
    // Create the available list box
    ///////////////////////////////////////////////////////////////////////
    csRef<iDocumentNode> availableNode = node->GetNode("available");
    int width = availableNode->GetAttributeValueAsInt("width");
    int rowHeight = availableNode->GetAttributeValueAsInt("rowheight");

    available = new pawsListBox;
    AddChild(available);

    available->SetRelativeFrame(0 , 0, GetActualWidth(width), defaultFrame.Height());
    available->PostSetup();
    available->Show();
    available->UseTitleRow(false);
    available->SetID(AVAILABLE_BOX);
    //available->UseBorder();

    csString widgetDef("<widget name=\"Text\" factory=\"pawsTextBox\" ></widget>");
    available->SetTotalColumns(1);
    available->SetColumnDef(0,
                            width-20 , rowHeight,
                            widgetDef);

    ///////////////////////////////////////////////////////////////////////
    // Create the selected list box
    ///////////////////////////////////////////////////////////////////////
    csRef<iDocumentNode> selectedNode = node->GetNode("selected");
    width = selectedNode->GetAttributeValueAsInt("width");
    rowHeight = selectedNode->GetAttributeValueAsInt("rowheight");

    selected = new pawsListBox;
    AddChild(selected);

    selected->SetRelativeFrame(defaultFrame.Width()-width , 0, width, defaultFrame.Height());
    selected->PostSetup();
    selected->Show();
    selected->SetName("Selected");
    selected->UseTitleRow(false);
    selected->SetID(SELECTED_BOX);
    //selected->UseBorder();

    csString selectedDef("<widget name=\"Text\" factory=\"pawsTextBox\" ></widget>");

    selected->SetTotalColumns(1);
    selected->SetColumnDef(0,
                           width-20 , rowHeight,
                           selectedDef);

    ///////////////////////////////////////////////////////////////////////
    // Create the addbutton
    ///////////////////////////////////////////////////////////////////////
    csRef<iDocumentNode> addNode = node->GetNode("addbutton");
    if(addNode.IsValid())
    {
        add = new pawsButton;
        AddChild(add);

        // Puts the button at the edge of the text box widget
        add->SetRelativeFrame(GetActualWidth(addNode->GetAttributeValueAsInt("x")),  GetActualHeight(addNode->GetAttributeValueAsInt("y")), 16,16);

        //get some replacement resources for the addbutton up/down
        csString upAddImageName = addNode->GetAttributeValue("buttonup");
        csString downAddImageName = addNode->GetAttributeValue("buttondown");
        if(upAddImageName.IsEmpty())
            upAddImageName = "Right Arrow";
        if(downAddImageName.IsEmpty())
            downAddImageName = "Right Arrow";

        add->SetUpImage(upAddImageName);
        add->SetDownImage(downAddImageName);

        add->SetID(SELECTOR_ADD_BUTTON);

        add->PostSetup();
    }

    ///////////////////////////////////////////////////////////////////////
    // Create the removebutton
    ///////////////////////////////////////////////////////////////////////
    csRef<iDocumentNode> removeNode = node->GetNode("removebutton");
    if(removeNode.IsValid())
    {
        remove = new pawsButton;
        AddChild(remove);

        // Puts the button at the edge of the text box widget
        remove->SetRelativeFrame(GetActualWidth(removeNode->GetAttributeValueAsInt("x")),  GetActualHeight(removeNode->GetAttributeValueAsInt("y")), 16,16);

        //get some replacement resources for the removebutton up/down
        csString upRemoveImageName = removeNode->GetAttributeValue("buttonup");
        csString downRemoveImageName = removeNode->GetAttributeValue("buttondown");
        if(upRemoveImageName.IsEmpty())
            upRemoveImageName = "Left Arrow";
        if(downRemoveImageName.IsEmpty())
            downRemoveImageName = "Left Arrow";

        remove->SetUpImage(upRemoveImageName);
        remove->SetDownImage(downRemoveImageName);

        remove->SetID(SELECTOR_REMOVE_BUTTON);

        remove->PostSetup();
    }

    return true;
}
void EEditShortcutsToolbox::Show()
{
    SetRelativeFramePos(editApp->GetGraphics2D()->GetWidth()/2 - GetActualWidth(screenFrame.Width())/2,
                        editApp->GetGraphics2D()->GetHeight()/2 - GetActualHeight(screenFrame.Height())/2);
    pawsWidget::Show();
}
Esempio n. 8
0
void pawsControlWindow::NextStyle()
{
    // We load it each time to make the user able to change the style without the need to
    // restart the client
    //Increase style
    style++;
    csString filename;
    filename = PawsManager::GetSingleton().GetLocalization()->FindLocalizedFile("control_styles.xml");
    if (!psengine->GetVFS()->Exists(filename.GetData()))
    {
        Error2( "Could not find XML: %s",filename.GetData());
        return;
    }

    csRef<iDocument> doc = ParseFile(psengine->GetObjectRegistry(),filename.GetData());
    if (!doc)
    {
        Error2("Error parsing file %s", filename.GetData());
        return;
    }

    csString topNodestr("style");
    topNodestr += style;

    csRef<iDocumentNode> root = doc->GetRoot();
    if (!root)
    {
        Error2("No XML root in %s", filename.GetData());
        return;
    }
    csRef<iDocumentNode> topNode = root->GetNode(topNodestr.GetData());

    //If "style"+style doesn't exist, jump to start
    if (!topNode)
    {
        if (style == 1) //No styles at all :(
            return;

        style=0;
        NextStyle();
        return;
    }

    csRef<iDocumentNodeIterator> iter = topNode->GetNodes();

    //Loop through the XML
    int bwidth=52, bheight=52, mwidth=16, mheight=16;
    float xscale=1.0f, yscale=1.0f;

    // get the current width and height of the buttons (should be the same for all)
    pawsButton* btn = (pawsButton*)FindWidget("QuitButton");
    int boldwidth = btn->ClipRect().Width();
    int boldheight = btn->ClipRect().Height();

    while ( iter->HasNext() )
    {
        csRef<iDocumentNode> node = iter->Next();
        if (!strcmp(node->GetValue(),"button"))
        {
            int x = GetActualWidth(node->GetAttributeValueAsInt("x"));
            int y = GetActualHeight(node->GetAttributeValueAsInt("y"));
            csString name = node->GetAttributeValue("name");

            pawsWidget* wdg = FindWidget(name.GetData());
            if (!wdg)
            {
                Error2("No such widget as %s!",name.GetData());
                continue;
            }
            wdg->SetSize(bwidth, bheight);
            wdg->SetRelativeFramePos(x, y);
        }
        else if (!strcmp(node->GetValue(),"buttons"))
        {
            bwidth = GetActualWidth(node->GetAttributeValueAsInt("width"));
            bheight = GetActualHeight(node->GetAttributeValueAsInt("height"));
            mwidth = GetActualWidth(node->GetAttributeValueAsInt("hide_width"));
            mheight = GetActualHeight(node->GetAttributeValueAsInt("hide_height"));

            // get the multiplier for the button and the widget size
            if (boldwidth != 0 && boldheight != 0)
            {
                xscale = float(boldwidth) / float(bwidth);
                yscale = float(boldheight) / float(bheight);
            }
        }
        else if (!strcmp(node->GetValue(), "bar"))
        {
            orgw = GetActualWidth(node->GetAttributeValueAsInt("width"));
            orgh = GetActualWidth(node->GetAttributeValueAsInt("height"));
            SetRelativeFrameSize(orgw, orgh);
            min_width = GetActualWidth(node->GetAttributeValueAsInt("min_w"));
            min_height = GetActualWidth(node->GetAttributeValueAsInt("min_h"));

            alwaysResize = node->GetAttributeValueAsBool("always_resize", true);
            SetResizeShow(alwaysResize);
        }
    }

    /* Resize the widget according to the proportions of the previous style.
     *
     * When the new styles dimensions exceeds its max it will be downsized to fit.
     * See: pawsWidget::Resize(int deltaX, int deltaY, int flags)
     */
    Resize( int(xscale*orgw-orgw), int(yscale*orgh-orgh), RESIZE_RIGHT | RESIZE_BOTTOM );

    // Set the minimize buttons size
    pawsButton* minUp = (pawsButton*)FindWidget("ShowButtonUp");
    minUp->SetSize(mwidth,mheight);

    pawsButton* minDown = (pawsButton*)FindWidget("ShowButtonDown");
    minDown->SetSize(mwidth,mheight);
}
Esempio n. 9
0
void pawsConfigKeys::CreateTreeWidgets(pawsTreeNode * subtreeRoot)
{
    pawsTextBox * label, * key;
    pawsButton * button;
    pawsSeqTreeNode * rootAsSeq;
    pawsTreeNode * child;


    rootAsSeq = dynamic_cast<pawsSeqTreeNode*> (subtreeRoot);
    if (rootAsSeq != NULL   &&   rootAsSeq != tree->GetRoot())
    {
        label = new pawsTextBox();
        label->SetRelativeFrameSize(GetActualWidth(COMMAND_WIDTH), 20);
        label->SetColour(0xffffff);
        label->Show();
        label->SetParent( this );
        label->SetRelativeFrame( 0, 0, GetActualWidth(COMMAND_WIDTH), 20 );
        label->VertAdjust(pawsTextBox::vertCENTRE);
        rootAsSeq->AddSeqWidget(label, GetActualWidth(COMMAND_WIDTH) + GetActualWidth(COLUMN_SPACING));

        key = new pawsTextBox();        
        key->SetRelativeFrameSize(GetActualWidth(TRIGGER_WIDTH), 20);
        key->SetColour(0xffffff);
        key->Show();
        key->SetParent( this );
        key->SetRelativeFrame( GetActualWidth(COMMAND_WIDTH)+5, 0, GetActualWidth(TRIGGER_WIDTH), 20 );
        key->VertAdjust(pawsTextBox::vertCENTRE);
        rootAsSeq->AddSeqWidget(key, GetActualWidth(TRIGGER_WIDTH) + GetActualWidth(COLUMN_SPACING));

        button = new pawsButton();
        button->SetParent( this );
        button->SetNotify(this);
        button->SetRelativeFrameSize(30, 20);
        button->SetUpImage("Standard Button");
        button->SetDownImage("Standard Button Down");
        button->SetText("Set");
        button->SetToggle(false);
        button->Show();
        button->SetRelativeFrame( GetActualWidth(COMMAND_WIDTH)+GetActualWidth(TRIGGER_WIDTH)+5, 0, 30, 20 );
        rootAsSeq->AddSeqWidget(button);
    }
    
    child = subtreeRoot->GetFirstChild();
    while (child != NULL)
    {
        CreateTreeWidgets(child);
        child = child->GetNextSibling();
    }
}
bool pawsGMSpawnWindow::PostSetup()
{
    psengine->GetMsgHandler()->Subscribe( this, MSGTYPE_GMSPAWNITEMS );
    psengine->GetMsgHandler()->Subscribe( this, MSGTYPE_GMSPAWNTYPES );
    loaded = true;

    itemName = (pawsTextBox*)FindWidget("ItemName");
    itemCount= (pawsEditTextBox*)FindWidget("Count");
    itemQuality = (pawsEditTextBox*)FindWidget("Quality");
    objView  = (pawsObjectView*)FindWidget("ItemView");

    //wait for the view to complete loading
    while(!objView->ContinueLoad())
    {
        csSleep(100);
    }
    
    itemImage = FindWidget("ItemImage");
    cbForce  = (pawsCheckBox*)FindWidget("Force");
    cbLockable = (pawsCheckBox*)FindWidget("Lockable");
    cbLocked = (pawsCheckBox*)FindWidget("Locked");
    cbPickupable = (pawsCheckBox*)FindWidget("Pickupable");
    cbPickupableWeak = (pawsCheckBox*)FindWidget("PickupableWeak");
    cbCollidable = (pawsCheckBox*)FindWidget("Collidable");
    cbUnpickable = (pawsCheckBox*)FindWidget("Unpickable");
    cbTransient = (pawsCheckBox*)FindWidget("Transient");
    cbSettingItem = (pawsCheckBox*)FindWidget("Settingitem");
    cbNPCOwned = (pawsCheckBox*)FindWidget("Npcowned");
    lockSkill = (pawsEditTextBox*)FindWidget("LockSkill");
    lockStr = (pawsEditTextBox*)FindWidget("LockStr");
    factname = (pawsTextBox*)FindWidget("meshfactname");
    meshname = (pawsTextBox*)FindWidget("meshname");
    imagename = (pawsTextBox*)FindWidget("imagename");
    modname[psGMSpawnMods::ITEM_PREFIX] = (pawsTextBox*)FindWidget("prefix");
    modname[psGMSpawnMods::ITEM_SUFFIX] = (pawsTextBox*)FindWidget("suffix");
    modname[psGMSpawnMods::ITEM_ADJECTIVE] = (pawsTextBox*)FindWidget("adjective");

    // creates tree:
    itemTree = new pawsItemTree;
    if (itemTree == NULL)
    {
        Error1("Could not create widget pawsItemTree");
        return false;
    }

    AddChild(itemTree);
    itemTree->SetDefaultColor( graphics2D->FindRGB( 0,255,0 ) );
    itemTree->SetRelativeFrame(0,0,GetActualWidth(250),GetActualHeight(560));
    itemTree->SetNotify(this);
    itemTree->SetAttachFlags(ATTACH_TOP | ATTACH_BOTTOM | ATTACH_LEFT);
    itemTree->SetScrollBars(false, true);
    itemTree->UseBorder("line");
    itemTree->Resize();

    itemTree->InsertChildL("", "TypesRoot", "", "");

    pawsTreeNode * child = itemTree->GetRoot()->GetFirstChild();
    while (child != NULL)
    {
        child->CollapseAll();
        child = child->GetNextSibling();
    }

    itemTree->SetNotify(this);

    return true;
}
Esempio n. 11
0
File: media.cpp Progetto: snorp/moon
void
Image::Render (cairo_t *cr, Region *region, bool path_only)
{
	ImageSource *source = GetSource ();
	cairo_pattern_t *pattern = NULL;
	cairo_matrix_t matrix;
	
	if (!source)
		return;

	source->Lock ();

	cairo_save (cr);
       
	Size specified (GetActualWidth (), GetActualHeight ());
	Size stretched = ApplySizeConstraints (specified);
	bool adjust = specified != GetRenderSize ();

	if (GetStretch () != StretchUniformToFill)
		specified = specified.Min (stretched);

	Rect paint = Rect (0, 0, specified.width, specified.height);
	
	if (!path_only) {
		Rect image = Rect (0, 0, source->GetPixelWidth (), source->GetPixelHeight ());

		if (GetStretch () == StretchNone)
			paint = paint.Union (image);

		if (image.width == 0.0 && image.height == 0.0)
			goto cleanup;

		pattern = cairo_pattern_create_for_surface (source->GetSurface (cr));
		image_brush_compute_pattern_matrix (&matrix, paint.width, paint.height, 
						    image.width, image.height,
						    GetStretch (), 
						    AlignmentXCenter, AlignmentYCenter, NULL, NULL);
		
		cairo_pattern_set_matrix (pattern, &matrix);
#if MAKE_EVERYTHING_SLOW_AND_BUGGY
		cairo_pattern_set_extend (pattern, CAIRO_EXTEND_PAD);
#endif
		if (cairo_pattern_status (pattern) == CAIRO_STATUS_SUCCESS) {
			cairo_set_source (cr, pattern);
		}
		cairo_pattern_destroy (pattern);
	}

	if (adjust) {
		// FIXME: Propagate error properly
		MoonError error;
		specified = MeasureOverrideWithError (specified, &error);
		paint = Rect ((stretched.width - specified.width) * 0.5, (stretched.height - specified.height) * 0.5, specified.width, specified.height);
	}
	
	if (!path_only)
		RenderLayoutClip (cr);

	paint = paint.Intersection (Rect (0, 0, stretched.width, stretched.height));
	paint.Draw (cr);
	
	if (!path_only)
		cairo_fill (cr);

cleanup:
	cairo_restore (cr);
	source->Unlock ();
}