|
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. |
On November 27 2013 05:45 tofucake wrote: set the name to namegoeshere[] and then they get posted as an array So what you mean is that (if I have 3 checkboxes):
set their names as chkbox[1]. chkbox[2], chkbox[3] and then reference it like this in the POST, but in the script, just get elements by name chkbox?
Further research leads me to: http://stackoverflow.com/questions/4516847/make-array-from-checkbox-form Do they appear in POST array in order of how the boxes appear?
|
Hyrule19167 Posts
You don't even have to index them
<input type="checkbox" name="set[]" id="q1" value="1" /><label for="q1">My question 1</label> <input type="checkbox" name="set[]" id="q2" value="1" /><label for="q2">My question 2</label> <input type="checkbox" name="set[]" id="q3" value="1" /><label for="q3">My question 3</label> <input type="checkbox" name="set[]" id="q4" value="1" /><label for="q4">My question 4</label> <input type="checkbox" name="set[]" id="q5" value="1" /><label for="q5">My question 5</label>
will post as
'_POST["set"]' => array 0 => string 'checked' (length=7) 1 => string 'checked' (length=7) 2 => string '' (length=0) 3 => string '' (length=0) 4 => string '' (length=0)
(this is not a real var_dump, it's just a tributesimple example)
|
Thank you spinesheath that makes a lot of sense. I suspect a disjoint-set data structure could be of help but I'm too lazy to implement it.
|
Don't these algorithms usually involve fancy data structures?
Anyways, this should work assuming you have the right data structures available: Remove w = {a, b}, then first iterate over all edges in the component connected to a (BFS or DFS, only need the edges of the MST), and mark all vertices you come across this way as belonging to part 1. Then do the same for b, mark as part 2. Now you have seperated the vertices of the graph into 2 groups in O(E). Next, iterate over all (unused) edges and find the lightest one that connects part 1 and 2. This again takes O(E), so the total runtime still is O(E).
First part certainly should also work in O(V) since |V| = |F| + 1 if F is the edges in the MST, so O(V) = O(F). Not sure if or how the second part works in O(V).
|
On November 27 2013 06:22 tofucake wrote:You don't even have to index them + Show Spoiler +<input type="checkbox" name="set[]" id="q1" value="1" /><label for="q1">My question 1</label> <input type="checkbox" name="set[]" id="q2" value="1" /><label for="q2">My question 2</label> <input type="checkbox" name="set[]" id="q3" value="1" /><label for="q3">My question 3</label> <input type="checkbox" name="set[]" id="q4" value="1" /><label for="q4">My question 4</label> <input type="checkbox" name="set[]" id="q5" value="1" /><label for="q5">My question 5</label> will post as <pre class='xdebug-var-dump' dir='ltr'> '_POST["set"]' <font color='#888a85'>=></font> <b>array</b> 0 <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'checked'</font> <i>(length=7)</i> 1 <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'checked'</font> <i>(length=7)</i> 2 <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>''</font> <i>(length=0)</i> 3 <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>''</font> <i>(length=0)</i> 4 <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>''</font> <i>(length=0)</i> </pre> (this is not a real var_dump, it's just a tributesimple example)
Could someone take a look at this and see if i am missing something huge, the array thing doesn't seem to be working for me.
echo"<input type='checkbox' name='ai[]' id='ai_acc' ".(!empty($ai_acc)?"checked":"")." />"; echo"<label for='ai_acc'>Accounting / Bookkeeping</label>"; echo"<br/>"; echo"<input type='checkbox' name='ai[]' id='ai_comm' ".(!empty($ai_comm)?"checked":"")." />"; echo"<label for='ai_comm'>Communication / Media Relation</label>"; echo"<br/>";
This is where my checkboxes were created...
$_SESSION['sai_acc'] = isset($_POST['ai'][0])?"true":""; $_SESSION['sai_comm'] = isset($_POST['ai'][1])?"true":""; echo"<b>".(isset($_POST['ai'][0])?"Accounting / Bookkeeping<br/>":"")."</b>"; echo"<b>".(isset($_POST['ai'][1])?"Communication / Media Relations<br/>":"")."</b>";
This was some code I used to redisplay for confirmation and some variable setting. However it seems if any checkbox is clicked, ai[0] will be true, and nothing else.
*edit* hmmm...might have an idea why this happens...if a checkbox isn't checked, it doesn't get added to ai[]...will check when I get home...yup. that's it...hmm...guess I need to figure out if I want to rewrite the printing/displaying or try the div method.
|
I had a pretty specific question pop up today that i dont know how to google so ill ask here: While a window is minimized, does the content still get rendered? Can i get information about the color of a pixel in the minimized window and can i send mouse clicks to specific positions?
|
|
|
Can you give me any hint how to do it in Java? Im using the Robot class currently, that works when the window is maximized and is on top/has focus, but i cant find any help how to do it otherwise.
|
So if someone could help me figure out this problem.
else if(Text[show] == '^') { if(Text[show+1] == '1') { sf::Color BlueColor(0,0,255); FontSprite.setColor(BlueColor); show = (show + 1); } }
Could someone for the love of god, tell me why the letter at [show-1] is getting the blue color as well? I'm at a loss and getting pissed.
I don't get it. How is it even possible???
|
have you tried unsetting the color of show-1 manually?
|
On November 29 2013 15:55 icystorage wrote: have you tried unsetting the color of show-1 manually?
If I do that, all characters after it will get the color as well.
|
I think that would be happening because, when you see ^1, you switch the font to blue and then ignore the "^1" string. I would increment show before setting the colour, as you only want the colour of everything after ^1 to be coloured blue.
|
On November 29 2013 18:43 Gowerly wrote: I think that would be happening because, when you see ^1, you switch the font to blue and then ignore the "^1" string. I would increment show before setting the colour, as you only want the colour of everything after ^1 to be coloured blue.
I don't know how I would do that and why it would matter tbh. "show" is already past the letter before ^. The only forward check being done is for the 1. This is why I can't understand why the character before the ^ would be affected when it is supposed to already have been sent of to the draw call. It makes no sense to me.
|
The code that seems to be setting the color:
sf::Color BlueColor(0,0,255); FontSprite.setColor(BlueColor);
Does not seem to be referencing the variables 'show' or 'Text[]'. How does FontSprite know what letter you are referencing? Is there a line of code missing here?
|
On November 29 2013 22:28 ThatGuy wrote: The code that seems to be setting the color:
sf::Color BlueColor(0,0,255); FontSprite.setColor(BlueColor);
Does not seem to be referencing the variables 'show' or 'Text[]'. How does FontSprite know what letter you are referencing? Is there a line of code missing here?
What it does is setting the color for the sprite. Then the current letter in Text[show] will be drawn and after that show is increased and repeat. This color will then color everything after ^1 with that color until another color is applied at some point.
And in short the problem is: When I write a string like this "Hell^1o" the o should be blue, but the code does something that makes the last l in the text blue as well. Even tho the l should already have been drawn 1 loop ago, and it makes no sense to me how it possible can get a color applied later to the sprite.
oh and the show = show + 1 thing is just to skip over drawing the 1 after ^.
|
On November 29 2013 22:40 Nausea wrote:Show nested quote +On November 29 2013 22:28 ThatGuy wrote: The code that seems to be setting the color:
sf::Color BlueColor(0,0,255); FontSprite.setColor(BlueColor);
Does not seem to be referencing the variables 'show' or 'Text[]'. How does FontSprite know what letter you are referencing? Is there a line of code missing here? What it does is setting the color for the sprite. Then the current letter in Text[show] will be drawn and after that show is increased and repeat. This color will then color everything after ^1 with that color until another color is applied at some point. And in short the problem is: When I write a string like this "Hell^1o" the o should be blue, but the code does something that makes the last l in the text blue as well. Even tho the l should already have been drawn 1 loop ago, and it makes no sense to me how it possible can get a color applied later to the sprite. oh and the show = show + 1 thing is just to skip over drawing the 1 after ^. It would probably help if you provided all the relevant code. It is unclear how you draw anything and how FontSprite interacts with that. What is it, anyways?
Also use the [ code ] tag.
|
Main: + Show Spoiler + window.clear(sf::Color(70,70,70,255)); Text.Print("Test^1ing\nlol",sf::Color(155,50,204), 500, 50, false); Text.Print("Game Over!",sf::Color(28,143,204), WINDOW_WIDTH, WINDOW_HEIGHT_CENTER, true); Text.Print("Sabertooth",sf::Color(167,152,123), 20, 500, false); window.display();
Font drawing: + Show Spoiler +void CBitmapText::Print(char* _text, sf::Color _color, unsigned int _x, unsigned int _y, bool _centered) { //Width = 0;
X = 0; Y = 0;
X = _x; Y = _y;
Text = _text;
if(_centered) {
int TextLenght = 0;
for(int i = 0; i < _text[i]; i++) {
TextLenght = (TextLenght + 1);
}
Width = TextLenght * Font->GetGlyphSize();
X = ((_x / 2) - (Width / 2));
}
FontSprite.setColor(_color);
if(Font != NULL) { for(unsigned int show = 0; Text[show] != '\0'; show++) { if(show < Font->Glyphs.size()) { if(Text[show] == ' ') { X += Font->GetSpace(); } else if(Text[show] == '\n') { Y += Font->GetNewLine() + 2; X = _x; } else if(Text[show] == '^') { if(Text[show+1] == '1') { sf::Color BlueColor(0,0,255); FontSprite.setColor(BlueColor); show = (show + 1); } } else { unsigned int ascii = (unsigned char)Text[show]; FontSprite.setPosition(sf::Vector2f((float)X,(float)Y)); FontSprite.setTextureRect(sf::IntRect(Font->Glyphs[ascii].PosX, Font->Glyphs[ascii].PosY, Font->Glyphs[ascii].Width, Font->Glyphs[ascii].Height)); X += Font->Glyphs[ascii].Width + Font->GetKerning(); } } RenderTarget->draw(FontSprite); } } }
Sorry for my crappy use of indentation.
Oh and the FontSprite is just a sprite linked to a texture with all the letters in a png file. And this is the results: + Show Spoiler +
|
On November 29 2013 22:58 Nausea wrote:Main: + Show Spoiler + window.clear(sf::Color(70,70,70,255)); Text.Print("Test^1ing\nlol",sf::Color(155,50,204), 500, 50, false); Text.Print("Game Over!",sf::Color(28,143,204), WINDOW_WIDTH, WINDOW_HEIGHT_CENTER, true); Text.Print("Sabertooth",sf::Color(167,152,123), 20, 500, false); window.display(); Font drawing: + Show Spoiler +void CBitmapText: rint(char* _text, sf::Color _color, unsigned int _x, unsigned int _y, bool _centered) { //Width = 0;
X = 0; Y = 0;
X = _x; Y = _y;
Text = _text;
if(_centered) {
int TextLenght = 0;
for(int i = 0; i < _text[i]; i++) {
TextLenght = (TextLenght + 1);
}
Width = TextLenght * Font->GetGlyphSize();
X = ((_x / 2) - (Width / 2));
}
FontSprite.setColor(_color);
if(Font != NULL) { for(unsigned int show = 0; Text[show] != '\0'; show++) { if(show < Font->Glyphs.size()) { if(Text[show] == ' ') { X += Font->GetSpace(); } else if(Text[show] == '\n') { Y += Font->GetNewLine() + 2; X = _x; } else if(Text[show] == '^') { if(Text[show+1] == '1') { sf::Color BlueColor(0,0,255); FontSprite.setColor(BlueColor); show = (show + 1); } } else { unsigned int ascii = (unsigned char)Text[show]; FontSprite.setPosition(sf::Vector2f((float)X,(float)Y)); FontSprite.setTextureRect(sf::IntRect(Font->Glyphs[ascii].PosX, Font->Glyphs[ascii].PosY, Font->Glyphs[ascii].Width, Font->Glyphs[ascii].Height)); X += Font->Glyphs[ascii].Width + Font->GetKerning(); } } RenderTarget->draw(FontSprite); } } }
Sorry for my crappy use of indentation. Oh and the FontSprite is just a sprite linked to a texture with all the letters in a png file. And this is the results: + Show Spoiler +
RenderTarget->draw(FontSprite) should probably be inside the else clause. Otherwise it would redraw the previous character with a new color in the cases where you have ' ', '\n' or '^'.
(I don't know C(whatever), but it seems probable)
|
On November 29 2013 23:19 Prillan wrote:Show nested quote +On November 29 2013 22:58 Nausea wrote:Main: + Show Spoiler + window.clear(sf::Color(70,70,70,255)); Text.Print("Test^1ing\nlol",sf::Color(155,50,204), 500, 50, false); Text.Print("Game Over!",sf::Color(28,143,204), WINDOW_WIDTH, WINDOW_HEIGHT_CENTER, true); Text.Print("Sabertooth",sf::Color(167,152,123), 20, 500, false); window.display(); Font drawing: + Show Spoiler +void CBitmapText: rint(char* _text, sf::Color _color, unsigned int _x, unsigned int _y, bool _centered) { //Width = 0;
X = 0; Y = 0;
X = _x; Y = _y;
Text = _text;
if(_centered) {
int TextLenght = 0;
for(int i = 0; i < _text[i]; i++) {
TextLenght = (TextLenght + 1);
}
Width = TextLenght * Font->GetGlyphSize();
X = ((_x / 2) - (Width / 2));
}
FontSprite.setColor(_color);
if(Font != NULL) { for(unsigned int show = 0; Text[show] != '\0'; show++) { if(show < Font->Glyphs.size()) { if(Text[show] == ' ') { X += Font->GetSpace(); } else if(Text[show] == '\n') { Y += Font->GetNewLine() + 2; X = _x; } else if(Text[show] == '^') { if(Text[show+1] == '1') { sf::Color BlueColor(0,0,255); FontSprite.setColor(BlueColor); show = (show + 1); } } else { unsigned int ascii = (unsigned char)Text[show]; FontSprite.setPosition(sf::Vector2f((float)X,(float)Y)); FontSprite.setTextureRect(sf::IntRect(Font->Glyphs[ascii].PosX, Font->Glyphs[ascii].PosY, Font->Glyphs[ascii].Width, Font->Glyphs[ascii].Height)); X += Font->Glyphs[ascii].Width + Font->GetKerning(); } } RenderTarget->draw(FontSprite); } } }
Sorry for my crappy use of indentation. Oh and the FontSprite is just a sprite linked to a texture with all the letters in a png file. And this is the results: + Show Spoiler + RenderTarget->draw(FontSprite) should probably be inside the else clause. Otherwise it would redraw the previous character with a new color in the cases where you have ' ', '\n' or '^'. (I don't know C(whatever), but it seems probable)
Thank you. Får jag gifta mig med dig? <3
|
wth stupid. didn't work before i left for work this morning...got home, tried it again, starts working.
|
|
|
|
|
|