Wt examples: dragdrop/DragExample.C Source File

Wt examples 4.10.4

Loading...
Searching...
No Matches
DragExample.C
Go to the documentation of this file.
1#include "DragExample.h"
2#include "Character.h"
3#include <Wt/WEnvironment.h>
4#include <Wt/WImage.h>
5#include <Wt/WApplication.h>
6
11
17WImage *createDragImage(const char *url, const char *smallurl,
18 const char *mimeType,
19 WContainerWidget *p)
20{
21 WImage *result = p->addWidget(std::make_unique<WImage>(url));
22 WImage *dragImage = p->addWidget(std::make_unique<WImage>(smallurl));
23 dragImage->setMargin(-15, Side::Left | Side::Top);
24
25 /*
26 * Set the image to be draggable, showing the other image (dragImage)
27 * to be used as the widget that is visually dragged.
28 */
29 result->setDraggable(mimeType, dragImage, true);
30
31 return result;
32}
33
34DragExample::DragExample():
35 WContainerWidget()
36{
37 this->addWidget(std::make_unique<WText>("<p>Help these people with their decision by dragging one of "
38 "the pills.</p>"));
39
40 if (!wApp->environment().javaScript()) {
41 this->addWidget(std::make_unique<WText>("<i>This examples requires that javascript support is "
42 "enabled.</i>"));
43 }
44
45 WContainerWidget *pills = this->addWidget(std::make_unique<WContainerWidget>());
46 pills->setContentAlignment(AlignmentFlag::Center);
47
48 createDragImage("icons/blue-pill.jpg",
49 "icons/blue-pill-small.png",
50 "blue-pill", pills);
51 createDragImage("icons/red-pill.jpg",
52 "icons/red-pill-small.png",
53 "red-pill", pills);
54
55 WContainerWidget *dropSites = this->addWidget(std::make_unique<WContainerWidget>());
56
57 dropSites->addWidget(std::make_unique<Character>("Neo"));
58 dropSites->addWidget(std::make_unique<Character>("Morpheus"));
59 dropSites->addWidget(std::make_unique<Character>("Trinity"));
60
61}
62
Character.h
createDragImage
WImage * createDragImage(const char *url, const char *smallurl, const char *mimeType, WContainerWidget *p)
Create an image which can be dragged.
Definition DragExample.C:17
DragExample.h
DragExample::DragExample
DragExample()
Definition DragExample.C:34