xna – Getting Rendered Sprite Size

I need the rendered dimensions of a sprite, I’m calling Draw in the class below:

public class Ship
{
    public Ship(Texture2D texture)
    {
        Width = texture.Width;
        Height = texture.Height;

        Texture = texture;
    }

    public int Width { get; set; }

    public int Height { get; set; }

    public float Scale { get; set; }

    public Vector2 Position { get; set; }
    
    public Texture2D Texture { get; }

    public Rectangle Rectangle => new Rectangle((int)Position.X, (int) Position.Y, Width, Height);

    public void Draw(SpriteBatch batch)
    {
        var origin = new Vector2(Texture.Width / 2, Texture.Height / 2);
        var scale = new Vector2(Scale, Scale);
        var rotation = GetRotationInRadians();

        batch.Draw(Texture, Position, null, Color.White,
            rotation,
            origin,
            scale, 
            SpriteEffects.None, 0f);
    }
}

The problem is Width and Height are based off the source (see the constructor) Texture size, so after drawing they are not actual dimensions. Is there away to determine the scaled sprite size?

Side note: I’m using these dimension to detect if an sprite was clicked on by the mouse. Maybe there is a better way to detect clicks?

8 – How can I add classes to the rendered “body” field on a content type?

Preface: I don’t often work with Drupal, so I may not be using the correct terminology or fully understand the stack. Please bear with me, I’ll do my best to be as clear as possible.

I want to filter the rendered output of the primary “Body” field on a “Basic Page” (or “Article,” any content type really) to add some classes to various elements. This would be the field labeled “Body” at /node/add/page. I’d like to achieve this using DOMDocument in my .theme file, but I’m having trouble figuring out what the correct “hook” is to tie in to.

So ultimately the goal would be a function something like the following (which is partially psuedo code):

function my_theme_body_alter(&$content) {
    $DOM = new DOMDocument();

    $DOM->loadHTML(mb_convert_encoding($content, "HTML-ENTITIES", "UTF-8"), LIBXML_HTML_NODEFDTD);

    $anchors = $DOM->getElementsByTagName("a");

    foreach ($anchors as $anchor) {
        $existing_classes = $anchor->getAttribute("class") ? $anchor->getAttribute("class") : "";

        $anchor->setAttribute("class", "button {$existing_classes}");
    }

    $content = $DOM->saveHTML($content);

    return $content;
}

To be absolutely clear, I want to modify the output (on the front end) of this field:

example

What is the name of the hook I’m looking for, or how can I locate it myself?

Google Street View streets are not rendered correctly in Ubuntu 18.04

I have noticed that every time I try to view some places with Ubuntu through Google Street View, the streets are not displayed correctly. In particular, pretty much everything is out of focus, i.e. H. Not rendered properly. This happens in every browser. No problems on Windows 10. Did someone have the same problem?

Fonts are not rendered correctly in the cloud

There are a number of issues that arise when I try to use my own style sheet and publish it to the cloud. The document looks great on Mathematica running on my desktop. But when I publish to the cloud, a lot of things break down, especially regarding fonts. This currently makes publishing in the cloud unusable for me.

Here is the first problem. This code snippet creates a simple notebook with a MyText-style cell that is then published to the cloud.

myStyle = Notebook({
    Cell(StyleData("MyText"), 
     FontFamily -> "EB Garamond",
     FontSize -> 24
     )
    });
myStyle = Export("mystyle.nb", myStyle);
myNB = CreateDocument(
   Cell(TextData({"Hello! This is a MyText cell. It would be nice if 
it looks the same,  including the inline formula ", 
      Cell(BoxData(
        FormBox(RowBox({SuperscriptBox("x", "2"), "=", 
           RowBox({RowBox({"a", " ", "b"}), " ", "+", " ", "c"})}), 
         TraditionalForm)), FormatType -> "TraditionalForm"), 
      ", in the desktop app as in the cloud."}), "MyText"));
SetOptions(myNB, StyleDefinitions -> Get(myStyle));
CloudDeploy(myNB) // SystemOpen

This is how it looks on my desktop:

Enter the image description here

This is how it looks in the cloud in Google Chrome. Note that the math is rendered differently.

Enter the image description here

When we open Developer Tools in Chrome, we can try to figure out what's going on with the math glyphs:

Enter the image description here

It’s not rendering properly. It appears that in the desktop app, the "a" character in Garamond is rendered in italics, while it is rendered normally in the cloud in Garamond.

By the way, I wish it would be possible to get Mathematica to render all math – including inline math in blocks of text created with Ctrl + (and) – using a fixed special math font like the STIX fonts. Let prose fonts be handled by prose fonts and leave the math to the specialist fonts.

react.js – Material ui Snackbar / Popup is not rendered

Here is my code to display the snack bar once theeterror is detected – I can't figure out why it doesn't work in one of the methods – but it does appear in my component's return statement, which is not exactly what I need. I only have to return the snack bar when theeterror is recognized. I tried to use Material Input InputComponent Prop to call my component. Help please!!

    updateData(value);
    _isValid(value);
    };

    const _isValid = (value: string) => {
    if(isNaN(+value) != false){
    seterror(true);
    return (
    /* eslint-disable */ 
    
    )
    } else {
    seterror(false);
    }
    };

   return (
    <>
    
    
    );
    };````

Augmented Reality – Is it possible to recognize a QR code in a rendered 3D object in AR?

My idea here is that when a user arrives at a GPS location in the game, an AR view recognizes the environment and displays a rendered 3D game object.

But I also want this virtual 3D game object to contain a random QR / Pin code that the app can then recognize and read. Trigger other navigation.

Kind of like the beginning.

ajax – I want to add a pagination below the rendered twig table to update the rendered twig table and pagination forms for the next and previous buttons

What I have:

I want to use an external API and display the results on the page.

  1. To that end, I created a custom route that is attached to the controller with a custom twig design.
  2. When you visit this route, load the function in the controller onto the external API, call up the data and pass this data in array form to the custom Twig template.
  3. Since the external API also offers a search function, we created a form and added this form with the Drupal form generator and also sent this form over the data in the array. With Twig this search form is attached to and above the search results table.
  4. Now I want to add a pagination under the Twig results table with the buttons for the next page and the previous page. The pagination functionality is provided by the API itself, and the links to the new and previous page are given in the API response itself. With Ajax callback, I'm trying to update my data and resend to the Twig template, but it doesn't work.

What I created for pagination:

  1. The Controller Form Builder creates a new form without a route and adds it to the Twig template.
  2. I pass the URL of the next page and the URL of the previous page as parameters to the form.
  3. This parameter is used in the build form function.
  4. I appended the URL of the next and previous page with custom arguments to the form elements.

Now when you click the next button, the new data is loaded via an Ajax call attached to the button for the next page in the form, and the twig table is updated with data for page 2. When the next button is clicked again, the same URL is called again even after the field arguments in the Ajax callback have been updated.

If my approach is wrong, please let me know that I am ready to correct my approach.

MyController.php


/**
 * @file
 * Contains Drupaldtn_feedControllerAPFeedListController.
 */

namespace Drupaldtn_feedController;

use DrupalCoreControllerControllerBase;
use DrupalComponentSerializationJson;
use DrupalCoreLoggerLoggerChannelFactory;
use DrupalCoreMessengerMessengerInterface;
use Drupaldtn_feedSearchAndFeedHandler;
use SymfonyComponentDependencyInjectionContainerInterface;

/**
 * Returns responses for Quick Node Clone Node routes.
 */
class APFeedListController extends ControllerBase {

  /**
   * @var searchFeedHandler
   *   Variable used for loading search feed handler service.
   */
  protected $searchFeedHandler;

  /**
   * @var url
   *   Variable used to store $url.
   */
  protected $url;

  /**
   * @var next_page_url
   *  Variable used to hold next page url
   */
  protected $next_page_url;

  /**
   * @var previous_page_url
   *  Variable used to hold previous page url
   */
  protected $previous_page_url;

  /**
   * Constructs a NodeController object.
   *
   * @param DrupalCoreLoggerLoggerChannelFactory $logger_factory
   *   Passing an Instance of logger factory.
   * @param DrupalCoreMessengerMessengerInterface $messenger
   *   The messenger service.
   * @param Drupaldtn_feedSearchAndFeedHandler $search_feed_handler
   *   The search feed handler custom service.
   */
  public function __construct(LoggerChannelFactory $logger_factory, MessengerInterface $messenger, SearchAndFeedHandler $search_feed_handler)
  {
    $this->loggerFactory = $logger_factory;
    $this->messenger = $messenger;
    $this->searchFeedHandler = $search_feed_handler;
  }
  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container)
  {
      return new static(
      $container->get('logger.factory'),
      $container->get('messenger'),
      $container->get('dtn_feed.feed.feed_api_handler')
    );
  }
  /**
   * Create Feed Url.
   *
   * @return string
   */
  private function getFeedUrl() {
    $urlParams = 'search?q=';
    $url = $this->searchFeedHandler->generateUrl($urlParams);
    return $url;
  }
  /**
   * Lists Feeds.
   *
   * @return array
   */

  public function listFeeds() {
    $url = $this->getFeedUrl();
    $jsonFeedData = $this->searchFeedHandler->getApFeeds($url);
    $decodedJsonFeedData = Json::decode($jsonFeedData);
    $searchForm = $this->formBuilder()->getForm('Drupaldtn_feedFormApFeedsSearchForm');

    if (isset($decodedJsonFeedData('data')('next_page'))) {
      $items('next_page') = $decodedJsonFeedData('data')('next_page');
      $this->next_page_url = $decodedJsonFeedData('data')('next_page');
    }

    $items('current_page') = $decodedJsonFeedData('data')('current_page');

    if (isset($decodedJsonFeedData('data')('previous_page'))) {
      $items('previous_page') = $decodedJsonFeedData('data')('previous_page');
      $this->previous_page_url = $decodedJsonFeedData('data')('previous_page');
    }

    $paginationForm = $this->formBuilder()->getForm('Drupaldtn_feedFormApFeedsPaginationForm', $items);

    return (
      '#theme' => 'dtn_feed_apFeeds_list',
      '#search_form' => $searchForm,
      '#feedsList' => $decodedJsonFeedData,
      '#pagination_form' => $paginationForm,
    );
  }

 /**
  * Reads the data from the json file.
  *
  * @return array
  *   jsonData
  */
  public function readJsonData() {
    $currentDirectory = drupal_get_path('module', 'dtn_feed');
    $path = $currentDirectory . '/ApJsonData/ApData.json';
    $data = file_get_contents($path);
    return $data;
  }

}

My form.php


namespace Drupaldtn_feedForm;

use DrupalComponentSerializationJson;
use DrupalCoreFormFormBase;
use DrupalCoreFormFormStateInterface;
use Drupaldtn_feedSearchAndFeedHandler;
use SymfonyComponentDependencyInjectionContainerInterface;
use DrupalCoreConfigConfigFactoryInterface;
use DrupalCoreFormFormBuilderInterface;
use DrupalCoreAjaxAjaxResponse;
use DrupalCoreAjaxReplaceCommand;
/**
 * Provide a search form for search AP Feed.
 */
class ApFeedsPaginationForm extends FormBase {

  /**
   * @var SearchAndFeedHandler $feed_api_handler
   */
  protected $feed_api_handler;

  /**
   * @var configFactoryInterface
   */
  protected $config_factory;

  /**
   * @var FormBuilderInterface
   */
  protected $form_builder;


  /**
   * Class constructor.
   * @param SearchAndFeedHandler $feed_api_handler
   */

  public function __construct(SearchAndFeedHandler $feed_api_handler, ConfigFactoryInterface $configFactory, FormBuilderInterface $formBuilder)
  {
    $this->feed_api_handler = $feed_api_handler;
    $this->config_factory = $configFactory;
    $this->form_builder = $formBuilder;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container)
  {
    return new static(
      $container->get('dtn_feed.feed.feed_api_handler'),
      $container->get('config.factory'),
      $container->get('form_builder')
    );
  }

  /**
   * {{ @inheritDoc }}
   */
  public function getFormId()
  {
    return 'dtn_feed_ap_feed_pagination_form';
  }

  /**
   * {{ @inheritDoc }}
   */
  public function buildForm(array $form, FormStateInterface $form_state, $items = ()) {
    $form('#theme') = 'dtn_feed_pagination_form';
    $form('pagination') = (
      '#type' => 'fieldset',
      '#title' => $items('next_page'),
      '#open' => TRUE,
    );
    $form('pagination')('previous') = (
      '#type' => 'button',
      '#value' => t('Previous'),
      '#attributes' => (
        'disabled' => 'disabled'
      ),
    );
    $form('pagination')('next') = (
      '#type' => 'button',
      '#value' => $this->t("Next"),
      '#attributes' => (
        '#args' => $items('next_page'),
        // 'disabled' => 'disabled'
        // 'id' => "next-page"
      ),
      '#ajax' => (
        'callback' => '::getApNewsSearchResult',
        'event' => 'click',
        'wrapper' => 'ap-news-table-list',
        'progress' => (
          'type' => 'throbber',
          'message' => $this->t('Getting news for you...'),
        ),
      ),
    );

    return $form;
  }

  /**
   * {{ @inheritDoc }}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $form_state->setRebuild(TRUE);

    $form_state->setCached(FALSE);
    // @todo Needs to decide what is to be done upon form submission.
  }

  /**
   * Get Search result from Ap News.
   * @param array $form
   * @param FormStateInterface $form_state
   * @return mixed
   */
  public function getApNewsSearchResult(array &$form, FormStateInterface &$form_state) {
    $config = $this->config_factory->getEditable('dtn_feed.ap_feed_conf');

    $api_key = $config->get('ap_feed_key');

    $url = $form('pagination')('next')('#attributes')('#args') . '&apikey=' . $api_key;

    $resultJson = $this->feed_api_handler->getJsonBodyFromAp($url);

    $decodedJsonData = JSON::decode($resultJson);

    if (isset($decodedJsonData('data')('next_page'))) {
      $items('next_page') = $decodedJsonData('data')('next_page');
    }

    $items('current_page') = $decodedJsonData('data')('current_page');

    if (isset($decodedJsonData('data')('previous_page'))) {
      $items('previous_page') = $decodedJsonData('data')('previous_page');
    };

    $form('pagination')('next')('#attributes')('#args') = $items('next_page');
    $url = $form('pagination')('next')('#attributes')('#args');
    $form('pagination')('#title') = $url;

    return (
      "#theme" => 'dtn_feed_apFeeds_list',
      "#feedsList" => $decodedJsonData,
      '#pagination_form' => $form,
    );
  }

}

Theming – How do I change the view of a rendered product?

I am learning Drupal Commerce with a Commerce Kickstart installation. I partially understood how products are displayed, with variation types and content types.

Have you made some changes, e.g. B. visible / hidden product fields and change the order. Product fields are displayed.

I want to change the position of the image on the left and title, description and Add to Cart Button should stay on the right.

How can I do that?

Enter the image description here