We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I went to the Examples page on Processing and found this interesting button that I can press and drag it everywhere. I believe it was at MouseFunctions example. And I took the code, modyfied it a bit, and tried to make an object out of it. But it just wouldn't work...
void setup() {
size(640, 360);
}
void draw() {
background(255);
draggableB Note = new draggableB(width/2,height/2,30);
Note.move();
Note.display();
}
class draggableB {
int posX;
int posY;
int xOffset;
int yOffset;
int size;
boolean over;
boolean lock;
draggableB(int tempX, int tempY, int tempSize) {
posX = tempX;
posY = tempY;
size = tempSize;
}
void move() {
rectMode(CENTER);
if (mouseX >= posX - size/2 && mouseX <= posX + size/2 &&
mouseY >= posY - size/2 && mouseY <= posY + size/2) {
over = true;
if (!lock) {
stroke(0);
fill(255, 0, 0);
size = 30;
}
} else {
stroke(0);
fill(0, 255, 0);
size = size - 10;
over = false;
}
}
void display() {
rectMode(CENTER);
rect(posX, posY, size, size);
}
void mousePressed() {
rectMode(CENTER);
if (over) {
lock = true;
fill(0, 0, 255);
} else {
lock = false;
}
xOffset = mouseX - posX;
yOffset = mouseY - posY;
}
void mouseDragged() {
rectMode(CENTER);
if (lock) {
posX = mouseX - xOffset;
posY = mouseY - yOffset;
}
}
void mouseReleased() {
lock = false;
}
}
Somedy help me with this please?
Answers
line 6 belongs in setup()
also the mouse functions must be outside the class (write Note.posX then etc.)
convention: note written small (object)
Thanks, but I thought objects have the first letter uppercase to differenciate them from other variable types. And if I'm going to put the mouse functions outside the class am I not gonna have to make another variable for every object like this? Plus I need to declare all the variables outside the class...so another variables for every object again.. This is what I am trying to avoid, that's why I made the class in the first place. Show me how to do that please and maybe it is better the way you say.
the class name class draggableB should have first letter uppercase
but the object, derived from it, small first letter
the mouse functions won't work in the class anyway (they are called by processing automatically but only outside your class) so you need to take them out of the class anyway
but surely you don't have to have the vas outside the class
this works (for one note)
So, anyway of doing this, but using objects and few variables it is possible?
yes, you can use an array of type draggableB
(or an ArrayList)
;-)
this is a simple array
In Java all variables (except constants) and method names follow the lower camel-case naming convention: https://en.wikipedia.org/wiki/Naming_convention_(programming)#Java
Java has 8 keywords to represent its 8 primitive types:
http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html
Everything else comes from class & interface names.
Class & interface names follow the upper camel-case naming convention instead.
Objects are instantiated from a class. A contiguous block of memory is allocated w/ enough room to clone all non-static fields and other small details from a class into the object.
The 1st memory address of that block is called reference or pointer to the object.
Non-primitive variables store that reference value in order to track an object and access its members
through the dot operator:
http://processing.org/reference/dot.html
So don't mix up variables & objects. Even though non-primitive variables act as an object avatar,
they're not the same!
Variables, constants, methods, classes and interfaces got names.
Objects are nameless! They only got their reference in order to be reached!
here is a new improved version
Thank you a lot Chrisir! And GoToLoop for the convention for the variables! Now a new question rises. How can I use native UI elements like a text box? Cause to write that it would take me a few good days and I don't have the time right now. The deadline for my app is on 13 of July, so I need to make a text box for every single note paper I just made... and after that, I need to modify them all to look like real notes and make the other functions, but I need to do so many and unfortunately, I didn't quite developed the "programmer's thinking method", if you know what I mean... I searched all over google for native windows text boxes to use them in processing but I couldn't find any... nor a library... Can you please help me with this one.. I feel though that I'm asking you to do too much and I don't have a method to repay you back...
Go to main site, to the Libraries page, go to the GUI section, choose a library, there are at least 3 or 4 GUI libraries.
here is a new version
I don't have time to work further on it
you can
delete a note with DEL (the one your mouse is currently over)
new version with 2 local menus - use right mouse
So, basically you just made like 70% of my app :) Thank you so much, but... you are awesome and awesome, a million times awesome. I couldn't make such a great app by my own. I just have no words to thank you! All I need to do know is to understand all the code (or at least 70% of it) and redesign everything (I need a very good design, I and I got some really good ideas), add some features (a big chance not to make them work) and I'm done! Anyway, I kind of feel bad that I'm gonna present myself with an app that most of it I didn't make, but the whole idea of the contest is originality, and it says that the app should be at least partially functionable, so I think I am good at that point. Anyway, thank you again, Chrisir, I am gonna go to work more at the app now. I've already been working at it for like three-four weeks, a few hours every day, but I'm just not a good programmer like you are...sorry for wasting your time. After finishing it, I will post it at Share your Work, is that ok?
wait, I got a new version in stock
wanna see it?
here... this version comes with 3 different menus ...
Yeah, I guess, but...I don't know, let's see it then...
yeah, maybe it's not what you need or what you're planning, don't worry!
;-)
It's basically the same thing, just added that button for more options, now the size is working and a little minor changes to the design. I could use this version, but it's just more complicated than the other...so it's not like I'm not appreciating your work, but I think I will go with the previous version though.
yes, absolutely, do as you like.
btw, now you can
stack all notes
spread all notes
you got 3 different menus:
right click on a note,
right click on a empty space / canvas,
left click on menu symbol ( = )
;-)
Anyway, great work! But just for curiosity, it seems to you like it's an original idea? I mean, it's not like Google Keep or other Note Manager. It has this unique arrangement of notes. Other apps for notes just display notes as a list, but this one lets you see them like you would have them pinned on a wall, you know what I mean?
what are your plans?
I thought of save / load to hard drive
do a slide show of the notes (display each full screen for 5 secs and then go on or display one till mouse click)
having different types of notes (with head line, round ones...)
connecting them with lines
do the stacking and spreading with animation
when displaying one note full screen, there could be buttons on the note to jump to another note
;-)
you wrote
could be, I am not sure...
I don't know so many other note handlers...
I think outlook does its notes that way: in a kind of grid
you can change size of each note with + and - or via the local menu
the length of the text could also change the size
Well I have a lot more ideas than you can imagine. That's what it is wrong. I have a lot of ideas, but can't implement them. So let's see: Wooden background so it would be like a real noteblock, with notes pined on it; Import and export from Excel files (there is a library for that); I also thought at saving and loading from hard drive; Folders for notes; Getting rid of the windows frame and add just a thin bar at the top with a rounded X button for closing the app; No menus, just buttons on the side (I have a very beautiful button with animation, you can see it at my Button Bug disscussion); Larger workspace (like 900x700); Different colors for notes; Every note should have a title that is displayed at the top and a content that is shown when pressing on it. Also thought about different size, but I don't think it is wise; Stack and spread- not very useful, don't you think?;
all very nice, great ideas!
;-)
I don't have the time to do it. And I can do it not for Android or something.
but let's see
ok, easy just find a free image on the net and use with command background()
what should be stored in the file? position, title, text? Color?
ok, easy
not understood, you mean folders on the hard drive?
easy, take
and start with ctrl-shift-r
easy, but how can you tell what button does what? Is there a text under each button?
see above: size(displayWidth, displayHeight);
ok, easy, but randomly color? Or is there a color selector when creating a new note?
ok, easy
ok
Right.
;-)
Thank you, but they value nothing if not implemented. So the windows frame and stuff is already made. I have the buttons and the animations for them, I already have the background and the background wooden image, I think I know how to change the colors of the notes. The rest I have no idea how to make... But don't worry I think it is enough to keep me busy for the next week. Thank you again for all the help!
;-)
What you did there with the code is very hard to understand, but I can get most of it vaguely. I know how to write and read from a file but the save and load function is beyond my power, also the exceel import/export. And yes, there will be some text under the buttons, and I won't use displayWidth and displayHeight for the size parameters. There is another way, just search on google and you will find it.
save and load function:
I just take the text of the note, the position x and y and the size etc. and join it with "#" in one line, for-loop and save it with saveStrings()
then retrieve it with loadStrings and use split() and then build up our ArrayList with a for-loop
not sure though if this works in Android mode or so...
;-)
The app is for windows, not for android. I already made a program that reads from a .txt file and I know how to use split and join and other stuff, but it is all a mess in my head, and I simply don't trust myself that I can do this.
So...
shall I give it a go?
No, thank you, I'm good. But I might have some questions about that color notes thing I am gonna do maybe the day after tomorrow. Until then...
But maybe I could also do that on my own, who knows?
too late, it's done already
this is load and save (part of the menu structure of my sketch)
you want use that with
http://www.processing.org/reference/selectInput_.html
I can't literally understand the code, and why should I use it with selectInput? I don't have more .txt files, it's just one.
when you only have one file, you are fine without selectInput()
The only problem I don't know to solve and I really need to do this is to modify the input window. You know, where you put the text for the note. There I need to have a multiline input box, not just a single long line, that's annoying. I was also wondering if we could get rid of the window, and make that text box right next to the note we make or modify.
the idea of multiple txt files was that you make different sheets with notes save them each in a different txt file and can load each of them when you need them...
one txt file contains all notes of one sheet
different txt files contain different sets of notes
like in word: different files for different texts
I already thinked of different sheets, but it's getting to far away from my knowledge. Maybe for you it is simple, but for me all this code is just mind-blowing.
this is a text box as you mentioned
Wow, you did these just now?
Oh, it's made by someone else, I see.
no, it's by gotoloop, I just looked it up
it's a little hard too read...
;-)
I'm off...
please ask again if you need something