I have a pattern image that I need to repeat in my Gtk::DrawingArea using cairomm.
I tried using Cairo::ImageSource without luck.
It's easy using Cairo::Pattern class:
bool MyDrawingArea::on_draw(const Cairo::RefPtr<Cairo::Context> &cr) {
Cairo::RefPtr<Cairo::Pattern> image = Cairo::SurfacePattern::create(Cairo::ImageSurface::create_from_png("my_bg_pattern.png"));
image_->set_extend(Cairo::EXTEND_REPEAT); // THIS IS THE IMPORTANT BIT!
cr->set_source(image);
cr->paint();
}
Related
I tried implementing an RTS in unreal engine c++ and currently I can select and deselect units but they won't move though I already have a function for that. Could someone take a look what I am doing wrong? Here's my code:
void ACoba_PlayerController::SetupInputComponent()
{
Super::SetupInputComponent();
InputComponent->BindAction("RightMouseClick", IE_Pressed, this, &ACoba_PlayerController::MoveReleased);
}
void ACoba_PlayerController::MoveReleased()
{
if (SelectedActors.Num() > 0)
{
for (int32 i = 0; i < SelectedActors.Num(); i++)
{
FHitResult Hit;
GetHitResultUnderCursor(ECC_Visibility, false, Hit);
FVector MoveLocation = Hit.Location + FVector(i / 2 * 100, i % 2 * 100, 0);
UAIBlueprintHelperLibrary::SimpleMoveToLocation(SelectedActors[i]->GetController(), MoveLocation);
}
}
}
Note: I've already setup the input for RightMouseClick at the input property.
Could someone help me please. Thank you.
Make sure you have set your PlayerController to receive input:
ACoba_PlayerController::ACoba_PlayerController()
{
AutoReceiveInput = EAutoReceiveInput::Player0;
/* ... */
}
I just tested the right button and it worked.
I'm using Unreal 4.24.2
I had the exact same issue, and after spending a day into it, i found out the problem is not in the code itself (mine is identical than the OP), the problem was that you need to add in your map a NavMeshBoundVolume in UE editor, this will make your map floor surface "walkable" by your actors, without this the SimpleMoveToLocation function won't do anything.
I found it very annoying that there is no warning or error displayed showing that you are missing a NavMeshBoundVolume, that would save a lot of time.
I'm trying to display several lines into a Text area from a string list. But it's only displaying the last one of the list, and i would like to display them all. Thanks for your help !
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class contenuTexte : MonoBehaviour {
public List <string> montexte;
public GameObject zoneAffichage;
// Update is called once per frame
void Start ()
{
foreach ( string lines in montexte)
zoneAffichage.GetComponent<Text>().text = "\n"+lines;
}
}
Your problem is that you are resetting the string on every loop to the last string. At the end of the loop you are going to only have the last string in the text.
First let's join all the strings together as one (using .ToArray() because of .NET 3.5), and then set them all at once:
var completeText = String.Join("\n", montexte.ToArray());
zoneAffichage.GetComponent<Text>().text = completeText;
I am trying to add texts to images in Magick++ by doing so:
Method 1:
Magick::Image image(Magick::Geometry(800,800),Magick::Color("white"));
Magick::Color color(0,0,0,0);
image.font("Waree");
image.fontPointsize(36);
image.strokeColor(color);
image.fillColor(color);
image.annotate("HelloWorld!", NorthWestGravity);
Method 2:
Magick::Image image(Magick::Geometry(800,800),Magick::Color("white"));
Magick::Color color(0,0,0,0);
std::list<Magick::Drawable> text_draw_list;
text_draw_list.push_back(Magick::DrawableViewbox(0,0,image.columns(), image.rows()));
text_draw_list.push_back(Magick::DrawableFont("Waree", (Magick::StyleType)NormalStyle, 400, (Magick::StretchType)NormalStretch ));
text_draw_list.push_back(Magick::DrawablePointSize(36));
//Manual offsets
text_draw_list.push_back(Magick::DrawableText(0, 200, "HelloWorld!"));
text_draw_list.push_back(Magick::DrawableStrokeColor(color));
text_draw_list.push_back(Magick::DrawableFillColor(color));
image.draw(text_draw_list);
Method 1 calculates best offsets given the gravity but does not have any word wrapping if the text is out of bounds of the image.
Method 2 has Method 1's problem plus it assumes that the correct offsets have been calculated so the text is written at the correct position.
How do I add automatic word wrapping to either of the 2 methods but preferably to method 1?
P.S: ImageMagick has automatic word wrapping by using the caption option but I couldn't find caption in Magick++.
Edit: Ugly boundary control based on font size.
Magick::Image image(Magick::Geometry(800,800),Magick::Color("white"));
Magick::Color color(0,0,0,0);
image.font("Waree");
image.fontPointsize(36);
image.strokeColor(color);
image.fillColor(color);
std::string txt = "HelloWorld!";
Magick::TypeMetric typeMetrics;
double fontSize = 36;
image.fontTypeMetrics(txt, &typeMetrics);
while(fontSize > 0)
{
if(typeMetrics.textWidth() >= image.columns() || typeMetrics.textHeight() >= image.rows())
{
fontSize--;
image.fontTypeMetrics(txt, &typeMetrics);
}
}
image.annotate(txt, NorthWestGravity);
The best thing to do is read the caption.c source, and understand how word-wrapping is implemented. This would allow your application to have full control.
Another options would be to use PANGO: protocol. This would allow your content-author to have full control of word-wrapping, format, and many other font-display features.
But for the quickest approach, as you mentioned, caption already does this. But caption is not a method, but a file protocol.
#include <Magick++.h>
using namespace Magick;
int main(int argc, const char * argv[]) {
InitializeMagick(argv[0]);
Image words(Geometry(250,250), Color("white"));
words.backgroundColor(Color("lime")); // might not be needed.
words.font("Avenir-Heavy");
words.fillColor(Color("firebrick"));
words.strokeColor(Color("yellow"));
words.read("CAPTION:Hello World!"); // <---- CAPTION: protocol
words.write("/tmp/words.jpg");
return 0;
}
I'm making a thread software with VTK, where I need to change the model itself in real time, while I need to change his method of rendering. Everything is working fine, but, the problem start with the interactor->start(); , the model data gets updated just fine, but it's only showed on screen when I move The camera. Also I have selected some methods for generating a 3D data from a imagedata file, for that I need to close the vtk window (interactor window) and then the code will reopen it and send the new data generated to it...
I would need something like these:
int force close_window = false; int refresh_interactor = false;
I managed to make the Window close, but only with vtkcommand::Keypressed command, but idk how do I do with a new command :S, I tried the vtkcommand::UserEvent but I didn't found a good information about how to deal with that data (like some way to call it)
the way I'm dealing with VTK is with two threads, the first one, is just about the vtk iren loop, and the second one would manage the models and check if iren requires to be updated.
In my dream code it should be something like this:
=======================================================
bool VTKWindow()
{
...
vtkSmartPointer ator = vtkSmartPointer::New();
iren = vtkSmartPointer::New();
RenWindow = vtkSmartPointer::New();
render->SetBackground(.1, .2, .3);
RenWindow->AddRenderer(renderer);
iren->SetRenderWindow(RenWindow);
if(data_type == voxel_type)
{
Render->AddViewProp(VoxelData);
}
else
{
actor->SetMapper(PolyData);
Render->AddActor(Actor);
}
RenWindow->Render();
iren->Start();
}
void ManageVTK()
{
while true loop...
if(force close_window == true)
do some command to exit the iren loop
if(refresh_interactor == true)
do some command to refresh iren
}
Sorry for the english, it's not my native language, and also sorry about the question format, it's the first time I'm using stackoverflow
It may sounds stupid, but, I found a kind of solution for the problem.
I saw on related links this guy vtkRenderWindowInteractor event loop and threading and, it's almost the same problem...
class VTKNewEvent : public vtkCommand{
public:
vtkTypeMacro(VTKNewEvent , vtkCommand);
static VTKNewEvent * New(){
return new VTKNewEvent ;
}
void Execute(vtkObject * caller, unsigned long vtkNotUsed(eventId), void * vtkNotUsed(callData)){
vtkRenderWindowInteractor *iren = static_cast<vtkRenderWindowInteractor*>(caller);
if (iren_close == true){
iren->GetRenderWindow()->Finalize // Stop the interactor
iren->TerminateApp();
iren_close = false;
}
if (iren_update== true){
renderJanela->Render();
iren_update= false;
}
}
};
bool VTKWindow(){
vtkSmartPointer<VTKNewEvent > IrenRefresh= vtkSmartPointer<VTKNewEvent>::New();
...
iren->CreateRepeatingTimer(1);//this makes that IrenRefresh will be called at every 1ms
iren->AddObserver(vtkCommand::TimerEvent, IrenRefresh);
iren->Start();
...
}
it's simple, but, maybe not the best, but it did Th job, I hope this link will help people that are starting into the VTK world, since threads + rendering loop wasn't a simple job to understand what was going on
Can someone provide an example of how to load a .svg file and display it using C/C++ and any library? I'm wondering if you will use SDL, cairo, or what.
Helltone,
check out http://cairographics.org/cairomm/
Might make things a little easier.
As Pavel put it, QtSvg is the way to go i believe. It is easier to use but in our team we have faced performance issues with QtSvg especially on Linux. So we decided to directly parse the SVG file XML by hand and render it using Qt itself. This turned out to be much faster.
pseudocode:-
// Read the SVG file using XML parser (SAX)
void SvgReader::readFile()
{
QFile file(<some svg filename>);
if (!file.open(QFile::ReadOnly | QFile::Text)) {
qWarning("Cannot open file");
return;
}
QString localName;
QXmlStreamAttributes attributes;
pXml = new QXmlStreamReader(&file);
pXml->setNamespaceProcessing(false);
while (!pXml->atEnd()) {
switch (pXml->readNext()) {
case QXmlStreamReader::StartElement:
localName = pXml->name().toString();
if (localName.compare(<some element path>) == 0) {
attributes = pXml->attributes();
QStringRef data = attributes.value(<some attribute name>);
// parse/use your data;
}
// similarly other case statements
}
}
}
QtSvg module might be helpful.
you may try boost.svg_plot
You can try lunasvg.
#include <lunasvg/document.h>
int main()
{
auto document = Document::loadFromFile("example.svg");
auto bitmap = document->renderToBitmap();
// do something useful with bitmap here.
}