Wt examples  3.7.1
DragExample.C
Go to the documentation of this file.
1 #include "DragExample.h"
2 #include "Character.h"
3 #include <Wt/WEnvironment>
4 #include <Wt/WImage>
5 #include <Wt/WApplication>
6 
7 using namespace Wt;
8 
13 
19 WImage *createDragImage(const char *url, const char *smallurl,
20  const char *mimeType,
22 {
23  WImage *result = new WImage(url, p);
24  WImage *dragImage = new WImage(smallurl, p);
25  dragImage->setMargin(-15, Left | Top);
26 
27  /*
28  * Set the image to be draggable, showing the other image (dragImage)
29  * to be used as the widget that is visually dragged.
30  */
31  result->setDraggable(mimeType, dragImage, true);
32 
33  return result;
34 }
35 
37  WContainerWidget(parent)
38 {
39  new WText("<p>Help these people with their decision by dragging one of "
40  "the pills.</p>", this);
41 
42  if (!wApp->environment().javaScript()) {
43  new WText("<i>This examples requires that javascript support is "
44  "enabled.</i>", this);
45  }
46 
47  WContainerWidget *pills = new WContainerWidget(this);
48  pills->setContentAlignment(AlignCenter);
49 
50  createDragImage("icons/blue-pill.jpg",
51  "icons/blue-pill-small.png",
52  "blue-pill", pills);
53  createDragImage("icons/red-pill.jpg",
54  "icons/red-pill-small.png",
55  "red-pill", pills);
56 
57  WContainerWidget *dropSites = new WContainerWidget(this);
58 
59  new Character("Neo", dropSites);
60  new Character("Morpheus", dropSites);
61  new Character("Trinity", dropSites);
62 
63 }
64 
DragExample(Wt::WContainerWidget *parent)
Definition: DragExample.C:36
void setDraggable(const std::string &mimeType, WWidget *dragWidget=nullptr, bool isDragWidgetOnly=false, WObject *sourceWidget=nullptr)
A Matrix character that takes red and/or blue pills.
Definition: Character.h:24
void setContentAlignment(WFlags< AlignmentFlag > contentAlignment)
virtual void setMargin(const WLength &margin, WFlags< Side > sides=AllSides) override
WImage * createDragImage(const char *url, const char *smallurl, const char *mimeType, WContainerWidget *p)
Create an image which can be dragged.
Definition: DragExample.C:19

Generated on Tue Dec 15 2020 for the C++ Web Toolkit (Wt) by doxygen 1.8.13