APWidgets clickable image
in
Contributed Library Questions
•
1 year ago
Got some advise from this forum a week or two ago. I was advised the G4P Library does get along with android so my existing TV controller sketch would never get along with android. APWidgets was the next suggested. I wanted to maintain the same look though.
I ended up with the attached image as the look for my android app. (the white box is just there to try and see if the boxes are calling the right function, the off button is under there) It's very similar to my pc interface, just a little different spacing. I added two APButtons to the sketch to try and see if i could add a button, make it 0 alpha and set the button over the top of an image. Therefor the end result would be a "clickable image". I ended up with gray buttons that cover up my image. Any ideas on making the hit boxes transparent?
Code below. Any suggestions as to why the on onClickWidget() function doesn't resize the box or send the UPD code?
Thanks very much for all assistance.
- import apwidgets.*;
- import hypermedia.net.*;
- int rectSize = 100;
- PImage ae;
- PImage discovery;
- PImage nick;
- PImage cartoonnetwork;
- PImage disney;
- PImage history;
- PImage pbs;
- PImage spike;
- PImage usa;
- PImage tnt;
- PImage trutv;
- PImage xbox;
- PImage poweron;
- PImage poweroff;
- PImage downarrow;
- PImage uparrow;
- PImage leftarrow;
- PImage rightarrow;
- PImage mutebutton;
- APWidgetContainer widgetContainer;
- APButton aeButton;
- APButton discoveryButton;
- UDP udp; // define the UDP object
- String ip = "192.168.5.200"; // the remote IP address
- int port = 8888; // the destination port
- void setup()
- {
- size(480, 800);
- orientation(PORTRAIT);
- background(0, 0, 0);
- aeButton = new APButton(68, 206, 100, 80, "words");
- discoveryButton = new APButton(358, 313, 100, 58, "testing");
- widgetContainer = new APWidgetContainer(this);
- widgetContainer.addWidget(aeButton); //place button in container
- widgetContainer.addWidget(discoveryButton); //place button in container
- // Define and create image button
- ae = loadImage("AE.jpg");
- discovery = loadImage("discovery.jpg");
- nick = loadImage("Nick.jpg");
- cartoonnetwork = loadImage("cartoonnetwork.jpg");
- disney = loadImage("Disney.jpg");
- history = loadImage("history.jpg");
- pbs = loadImage("pbs.jpg");
- spike = loadImage("spike.jpg");
- usa = loadImage("usa.jpg");
- tnt = loadImage("TNT.jpg");
- trutv = loadImage("trutv.jpg");
- xbox = loadImage("Xbox.jpg");
- poweron = loadImage("poweron.jpg");
- poweroff = loadImage("poweroff.jpg");
- downarrow = loadImage("greendownarrow.jpg");
- uparrow = loadImage("greenuparrow.jpg");
- leftarrow = loadImage("greenleftarrow.jpg");
- rightarrow = loadImage("greenrightarrow.jpg");
- mutebutton = loadImage("greenmutebutton.jpg");
- }
- void draw()
- {
- image(ae, 68, 206);
- image(discovery, 358, 313);
- image(nick, 20, 315);
- image(cartoonnetwork, 56, 391);
- image(disney, 304, 391);
- image(history, 204, 226);
- image(pbs, 187, 340);
- image(spike, 353, 141);
- image(usa, 199, 139);
- image(tnt, 314, 233);
- image(trutv, 29, 140);
- image(xbox, 210, 25);
- image(poweron, 370, 27);
- image(poweroff, 51, 24);
- image(downarrow, 174, 682);
- image(uparrow, 178, 499);
- image(leftarrow, 104, 573);
- image(rightarrow, 277, 575);
- image(mutebutton, 195, 591);
- rect(50, 20, rectSize, rectSize);
- }
- void onClickWidget(APWidget widget) {
- if (widget == aeButton) {
- udp.send( "DCCH039 ", ip, port );
- rectSize = 100;
- }
- else if (widget == discoveryButton) {
- udp.send( "DCCH046 ", ip, port );
- rectSize = 200;
- }
- }
1