Drafted a basic networking protocol, and hooked a button up to the network broadcast

This commit is contained in:
Kayne Ruse
2013-05-20 04:49:06 +10:00
parent 7866f46ed5
commit d5409d2006
9 changed files with 127 additions and 60 deletions
+14 -7
View File
@@ -33,10 +33,7 @@ Button::Button(Sint16 i, Sint16 j, SDL_Surface* imageSurface, SDL_Surface* fontS
y = j;
state = State::NORMAL;
//graphical stuff
image.SetSurface(imageSurface);
image.SetClipH(image.GetClipH() / 3); //3 phases
font.SetSurface(fontSurface);
SetSurfaces(imageSurface, fontSurface);
SetText(s);
}
@@ -67,14 +64,24 @@ Button::State Button::MouseButtonUp(SDL_MouseButtonEvent const& button) {
void Button::DrawTo(SDL_Surface* const dest) {
image.DrawTo(dest, x, y);
font.DrawStringTo(text, dest, textX, textY);
font.DrawStringTo(text, dest, textX + x, textY + y);
}
void Button::SetSurfaces(SDL_Surface* imageSurface, SDL_Surface* fontSurface) {
//graphical stuff
image.SetSurface(imageSurface);
image.SetClipH(image.GetClipH() / 3); //3 phases
font.SetSurface(fontSurface);
//reset textX & textY
SetText(text);
}
std::string Button::SetText(std::string s) {
//one line
text = s;
textX = (image.GetClipW() / 2 + x) - (font.GetClipW() * text.size() / 2);
textY = (image.GetClipH() / 2 + y) - (font.GetClipH() / 2);
textX = (image.GetClipW() / 2) - (font.GetClipW() * text.size() / 2);
textY = (image.GetClipH() / 2) - (font.GetClipH() / 2);
return text;
}