summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-01-27 20:19:42 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-01-27 20:19:42 (GMT)
commit07525180c2f8065c61dfd38bb273ff0f0a8abc85 (patch)
tree717389467f699071c7e530713f2c3a3ae7ecb2f5 /src
parent597d11f9f79c1486db4cdc1c0aca215cc4ab6074 (diff)
downloadpowder-07525180c2f8065c61dfd38bb273ff0f0a8abc85.zip
powder-07525180c2f8065c61dfd38bb273ff0f0a8abc85.tar.gz
Icon management, fix element menu order, fix renderer crash
Diffstat (limited to 'src')
-rw-r--r--src/Graphics.cpp58
-rw-r--r--src/Graphics.h56
-rw-r--r--src/elements/bomb.cpp2
-rw-r--r--src/elements/newgraphics.cpp2
-rw-r--r--src/elements/stkm.cpp1
-rw-r--r--src/elements/wire.cpp1
-rw-r--r--src/game/GameView.cpp37
-rw-r--r--src/interface/Button.cpp97
-rw-r--r--src/interface/Button.h9
-rw-r--r--src/preview/PreviewView.cpp4
-rw-r--r--src/preview/PreviewView.h1
-rw-r--r--src/render/RenderModel.cpp4
12 files changed, 149 insertions, 123 deletions
diff --git a/src/Graphics.cpp b/src/Graphics.cpp
index a48f6d6..678e138 100644
--- a/src/Graphics.cpp
+++ b/src/Graphics.cpp
@@ -1141,20 +1141,54 @@ TPT_INLINE void Graphics::blendpixel(int x, int y, int r, int g, int b, int a)
#endif
}
-void Graphics::draw_icon(int x, int y, char ch, int flag)
+void Graphics::draw_icon(int x, int y, Icon icon)
{
- char t[2];
- t[0] = ch;
- t[1] = 0;
- if (flag)
+ switch(icon)
{
- fillrect(x-1, y-1, 17, 17, 255, 255, 255, 255);
- drawtext(x+3, y+2, t, 0, 0, 0, 255);
- }
- else
- {
- drawrect(x, y, 15, 15, 255, 255, 255, 255);
- drawtext(x+3, y+2, t, 255, 255, 255, 255);
+ case IconOpen:
+ drawchar(x, y, 0x81, 255, 255, 255, 255);
+ break;
+ case IconReload:
+ drawchar(x, y, 0x91, 255, 255, 255, 255);
+ break;
+ case IconSave:
+ drawchar(x, y, 0x82, 255, 255, 255, 255);
+ break;
+ case IconVoteUp:
+ drawchar(x, y, 0xCB, 0, 187, 18, 255);
+ break;
+ case IconVoteDown:
+ drawchar(x, y, 0xCA, 187, 40, 0, 255);
+ break;
+ case IconTag:
+ drawchar(x, y, 0x83, 255, 255, 255, 255);
+ break;
+ case IconNew:
+ drawchar(x, y, 0x92, 255, 255, 255, 255);
+ break;
+ case IconLogin:
+ drawchar(x, y, 0x84, 255, 255, 255, 255);
+ break;
+ case IconSimulationSettings:
+ drawchar(x, y, 0xCF, 255, 255, 255, 255);
+ break;
+ case IconRenderSettings:
+ addchar(x, y, 0xD8, 255, 0, 0, 255);
+ addchar(x, y, 0xD9, 0, 255, 0, 255);
+ addchar(x, y, 0xDA, 0, 0, 255, 255);
+ break;
+ case IconPause:
+ drawchar(x, y, 0x90, 255, 255, 255, 255);
+ break;
+ case IconVoteSort:
+ case IconDateSort:
+ case IconFavourite:
+ case IconFolder:
+ case IconSearch:
+ case IconDelete:
+ default:
+ drawchar(x, y, 't', 255, 255, 255, 255);
+ break;
}
}
diff --git a/src/Graphics.h b/src/Graphics.h
index 25cb5d6..d2f9721 100644
--- a/src/Graphics.h
+++ b/src/Graphics.h
@@ -52,38 +52,28 @@ typedef unsigned short pixel;
typedef unsigned int pixel;
#endif
-/*extern int emp_decor;
-
-extern unsigned int *render_modes;
-extern unsigned int render_mode;
-extern unsigned int colour_mode;
-extern unsigned int *display_modes;
-extern unsigned int display_mode;
-
-extern SDL_Surface *sdl_scrn;
-extern int sdl_scale;
-
-extern int sandcolour_r;
-extern int sandcolour_g;
-extern int sandcolour_b;
-extern int sandcolour_frame;
-
-extern unsigned char fire_r[YRES/CELL][XRES/CELL];
-extern unsigned char fire_g[YRES/CELL][XRES/CELL];
-extern unsigned char fire_b[YRES/CELL][XRES/CELL];
-
-extern unsigned int fire_alpha[CELL*3][CELL*3];
-extern pixel *pers_bg;
-
-extern char * flm_data;
-extern int flm_data_points;
-extern pixel flm_data_colours[];
-extern float flm_data_pos[];
-
-extern char * plasma_data;
-extern int plasma_data_points;
-extern pixel plasma_data_colours[];
-extern float plasma_data_pos[];*/
+//Icon names, see Graphics::draw_icon
+enum Icon
+{
+ NoIcon = 0,
+ IconOpen,
+ IconReload,
+ IconSave,
+ IconVoteUp,
+ IconVoteDown,
+ IconTag,
+ IconNew,
+ IconLogin,
+ IconRenderSettings,
+ IconSimulationSettings,
+ IconPause,
+ IconVoteSort,
+ IconDateSort,
+ IconFavourite,
+ IconFolder,
+ IconSearch,
+ IconDelete
+};
class Graphics
{
@@ -126,7 +116,7 @@ public:
static int textposxy(char *s, int width, int w, int h);
static int textwrapheight(char *s, int width);
inline void blendpixel(int x, int y, int r, int g, int b, int a);
- void draw_icon(int x, int y, char ch, int flag);
+ void draw_icon(int x, int y, Icon icon);
//void draw_air();
//void draw_grav_zones(pixel *vid);
//void draw_grav(pixel *vid);
diff --git a/src/elements/bomb.cpp b/src/elements/bomb.cpp
index b696b19..3b6db26 100644
--- a/src/elements/bomb.cpp
+++ b/src/elements/bomb.cpp
@@ -11,7 +11,7 @@ int update_BOMB(UPDATE_FUNC_ARGS) {
r = pmap[y+ry][x+rx];
if (!r)
continue;
- if (sim->ptypes[r&0xFF].properties & (TYPE_SOLID | TYPE_PART | TYPE_LIQUID) && !(sim->ptypes[r&0xFF].properties & PROP_SPARKSETTLE)) {
+ if ((sim->ptypes[r&0xFF].properties & (TYPE_SOLID | TYPE_PART | TYPE_LIQUID)) && !(sim->ptypes[r&0xFF].properties & PROP_SPARKSETTLE)) {
sim->kill_part(i);
return 1;
}
diff --git a/src/elements/newgraphics.cpp b/src/elements/newgraphics.cpp
index 036a6a7..efdf128 100644
--- a/src/elements/newgraphics.cpp
+++ b/src/elements/newgraphics.cpp
@@ -357,7 +357,7 @@ int graphics_GLOW(GRAPHICS_FUNC_ARGS)
}
int graphics_LCRY(GRAPHICS_FUNC_ARGS)
{
- if(ren->decorations_enable && cpart->dcolour && cpart->dcolour&0xFF000000)
+ if(ren->decorations_enable && cpart->dcolour && (cpart->dcolour&0xFF000000))
{
*colr = (cpart->dcolour>>16)&0xFF;
*colg = (cpart->dcolour>>8)&0xFF;
diff --git a/src/elements/stkm.cpp b/src/elements/stkm.cpp
index c457b62..68ef1ed 100644
--- a/src/elements/stkm.cpp
+++ b/src/elements/stkm.cpp
@@ -78,6 +78,7 @@ int run_stickman(playerst* playerp, UPDATE_FUNC_ARGS) {
gvx = ((float)(parts[i].x - XCNTR) / gravd);
gvy = ((float)(parts[i].y - YCNTR) / gravd);
}
+ break;
}
gvx += sim->gravx[((int)parts[i].y/CELL)*(XRES/CELL)+((int)parts[i].x/CELL)];
diff --git a/src/elements/wire.cpp b/src/elements/wire.cpp
index f7202e4..c3c918b 100644
--- a/src/elements/wire.cpp
+++ b/src/elements/wire.cpp
@@ -64,4 +64,5 @@ int graphics_WIRE(GRAPHICS_FUNC_ARGS)
//*pixel_mode |= PMODE_GLOW;
return 0;
}
+ return 0;
}
diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp
index 3f31554..3a20b3e 100644
--- a/src/game/GameView.cpp
+++ b/src/game/GameView.cpp
@@ -25,7 +25,8 @@ GameView::GameView():
v->c->OpenSearch();
}
};
- searchButton = new ui::Button(ui::Point(currentX, Size.Y-18), ui::Point(16, 16), "\x81"); //Open
+ searchButton = new ui::Button(ui::Point(currentX, Size.Y-18), ui::Point(16, 16)); //Open
+ searchButton->SetIcon(IconOpen);
currentX+=18;
searchButton->SetTogglable(false);
searchButton->SetActionCallback(new SearchAction(this));
@@ -41,7 +42,8 @@ GameView::GameView():
v->c->ReloadSim();
}
};
- reloadButton = new ui::Button(ui::Point(currentX, Size.Y-18), ui::Point(16, 16), "\x91");
+ reloadButton = new ui::Button(ui::Point(currentX, Size.Y-18), ui::Point(16, 16));
+ reloadButton->SetIcon(IconReload);
currentX+=18;
reloadButton->SetActionCallback(new ReloadAction(this));
AddComponent(reloadButton);
@@ -56,7 +58,8 @@ GameView::GameView():
v->c->OpenSaveWindow();
}
};
- saveSimulationButton = new ui::Button(ui::Point(currentX, Size.Y-18), ui::Point(Size.X/5, 16), "\x82");
+ saveSimulationButton = new ui::Button(ui::Point(currentX, Size.Y-18), ui::Point(Size.X/5, 16));
+ saveSimulationButton->SetIcon(IconSave);
currentX+=(Size.X/5)+2;
saveSimulationButton->SetActionCallback(new SaveSimulationAction(this));
AddComponent(saveSimulationButton);
@@ -71,7 +74,8 @@ GameView::GameView():
v->c->Vote(1);
}
};
- upVoteButton = new ui::Button(ui::Point(currentX, Size.Y-18), ui::Point(16, 16), "\xCB");
+ upVoteButton = new ui::Button(ui::Point(currentX, Size.Y-18), ui::Point(16, 16));
+ upVoteButton->SetIcon(IconVoteUp);
currentX+=16;
upVoteButton->SetActionCallback(new UpVoteAction(this));
AddComponent(upVoteButton);
@@ -86,7 +90,8 @@ GameView::GameView():
v->c->Vote(-1);
}
};
- downVoteButton = new ui::Button(ui::Point(currentX, Size.Y-18), ui::Point(16, 16), "\xCA");
+ downVoteButton = new ui::Button(ui::Point(currentX, Size.Y-18), ui::Point(16, 16));
+ downVoteButton->SetIcon(IconVoteDown);
currentX+=18;
downVoteButton->SetActionCallback(new DownVoteAction(this));
AddComponent(downVoteButton);
@@ -101,7 +106,8 @@ GameView::GameView():
v->c->OpenTags();
}
};
- tagSimulationButton = new ui::Button(ui::Point(currentX, Size.Y-18), ui::Point(Size.X-(currentX+176), 16), "\x83");
+ tagSimulationButton = new ui::Button(ui::Point(currentX, Size.Y-18), ui::Point(Size.X-(currentX+176), 16));
+ tagSimulationButton->SetIcon(IconTag);
currentX+=Size.X-(currentX+176);
tagSimulationButton->SetActionCallback(new TagSimulationAction(this));
AddComponent(tagSimulationButton);
@@ -116,7 +122,8 @@ GameView::GameView():
v->c->ClearSim();
}
};
- clearSimButton = new ui::Button(ui::Point(Size.X-174, Size.Y-18), ui::Point(16, 16), "C");
+ clearSimButton = new ui::Button(ui::Point(Size.X-174, Size.Y-18), ui::Point(16, 16));
+ clearSimButton->SetIcon(IconNew);
clearSimButton->SetActionCallback(new ClearSimAction(this));
AddComponent(clearSimButton);
@@ -130,7 +137,8 @@ GameView::GameView():
v->c->OpenLogin();
}
};
- loginButton = new ui::Button(ui::Point(Size.X-156, Size.Y-18), ui::Point(100, 16), "\xDA Login");
+ loginButton = new ui::Button(ui::Point(Size.X-156, Size.Y-18), ui::Point(100, 16), "Login");
+ loginButton->SetIcon(IconLogin);
loginButton->SetActionCallback(new LoginAction(this));
AddComponent(loginButton);
@@ -144,7 +152,8 @@ GameView::GameView():
v->c->OpenDisplayOptions();
}
};
- simulationOptionButton = new ui::Button(ui::Point(Size.X-54, Size.Y-18), ui::Point(16, 16), "\xDA");
+ simulationOptionButton = new ui::Button(ui::Point(Size.X-54, Size.Y-18), ui::Point(16, 16));
+ simulationOptionButton->SetIcon(IconSimulationSettings);
simulationOptionButton->SetActionCallback(new SimulationOptionAction(this));
AddComponent(simulationOptionButton);
@@ -158,7 +167,8 @@ GameView::GameView():
v->c->OpenRenderOptions();
}
};
- displayModeButton = new ui::Button(ui::Point(Size.X-36, Size.Y-18), ui::Point(16, 16), "\xDA");
+ displayModeButton = new ui::Button(ui::Point(Size.X-36, Size.Y-18), ui::Point(16, 16));
+ displayModeButton->SetIcon(IconRenderSettings);
displayModeButton->SetActionCallback(new DisplayModeAction(this));
AddComponent(displayModeButton);
@@ -172,7 +182,8 @@ GameView::GameView():
v->c->SetPaused(sender->GetToggleState());
}
};
- pauseButton = new ui::Button(ui::Point(Size.X-18, Size.Y-18), ui::Point(16, 16), "\x90"); //Pause
+ pauseButton = new ui::Button(ui::Point(Size.X-18, Size.Y-18), ui::Point(16, 16)); //Pause
+ pauseButton->SetIcon(IconPause);
pauseButton->SetTogglable(true);
pauseButton->SetActionCallback(new PauseAction(this));
AddComponent(pauseButton);
@@ -204,7 +215,7 @@ public:
void GameView::NotifyMenuListChanged(GameModel * sender)
{
- int currentY = YRES+MENUSIZE-36;
+ int currentY = YRES+MENUSIZE-18-(sender->GetMenuList().size()*18);
for(int i = 0; i < menuButtons.size(); i++)
{
RemoveComponent(menuButtons[i]);
@@ -225,7 +236,7 @@ void GameView::NotifyMenuListChanged(GameModel * sender)
ui::Button * tempButton = new ui::Button(ui::Point(XRES+BARSIZE-18, currentY), ui::Point(16, 16), tempString);
tempButton->SetTogglable(true);
tempButton->SetActionCallback(new MenuAction(this, menuList[i]));
- currentY-=18;
+ currentY+=18;
AddComponent(tempButton);
menuButtons.push_back(tempButton);
}
diff --git a/src/interface/Button.cpp b/src/interface/Button.cpp
index b145b38..b4e32b2 100644
--- a/src/interface/Button.cpp
+++ b/src/interface/Button.cpp
@@ -15,24 +15,6 @@
namespace ui {
-Button::Button(Window* parent_state, std::string buttonText):
- Component(parent_state),
- ButtonText(buttonText),
- isMouseInside(false),
- isButtonDown(false),
- isTogglable(false),
- toggle(false),
- actionCallback(NULL),
- textPosition(ui::Point(0, 0)),
- textVAlign(AlignMiddle),
- textHAlign(AlignCentre),
- Enabled(true)
-{
- activeText = background = Colour(0, 0, 0);
- text = activeBackground = border = activeBorder = Colour(255, 255, 255);
- TextPosition();
-}
-
Button::Button(Point position, Point size, std::string buttonText):
Component(position, size),
ButtonText(buttonText),
@@ -44,25 +26,8 @@ Button::Button(Point position, Point size, std::string buttonText):
textPosition(ui::Point(0, 0)),
textVAlign(AlignMiddle),
textHAlign(AlignCentre),
- Enabled(true)
-{
- activeText = background = Colour(0, 0, 0);
- text = activeBackground = border = activeBorder = Colour(255, 255, 255);
- TextPosition();
-}
-
-Button::Button(std::string buttonText):
- Component(),
- ButtonText(buttonText),
- isMouseInside(false),
- isButtonDown(false),
- isTogglable(false),
- toggle(false),
- actionCallback(NULL),
- textPosition(ui::Point(0, 0)),
- textVAlign(AlignMiddle),
- textHAlign(AlignCentre),
- Enabled(true)
+ Enabled(true),
+ icon(NoIcon)
{
activeText = background = Colour(0, 0, 0);
text = activeBackground = border = activeBorder = Colour(255, 255, 255);
@@ -71,7 +36,6 @@ Button::Button(std::string buttonText):
void Button::TextPosition()
{
- //Position.X+(Size.X-Graphics::textwidth((char *)ButtonText.c_str()))/2, Position.Y+(Size.Y-10)/2
switch(textVAlign)
{
case AlignTop:
@@ -85,20 +49,44 @@ void Button::TextPosition()
break;
}
- switch(textHAlign)
+ if(icon)
{
- case AlignLeft:
- textPosition.X = 3;
- break;
- case AlignCentre:
- textPosition.X = (Size.X-Graphics::textwidth((char *)ButtonText.c_str()))/2;
- break;
- case AlignRight:
- textPosition.X = (Size.X-Graphics::textwidth((char *)ButtonText.c_str()))-2;
- break;
+ switch(textHAlign)
+ {
+ case AlignLeft:
+ textPosition.X = 3+17;
+ break;
+ case AlignCentre:
+ textPosition.X = (((Size.X-14)-Graphics::textwidth((char *)ButtonText.c_str()))/2)+17;
+ break;
+ case AlignRight:
+ textPosition.X = (((Size.X-14)-Graphics::textwidth((char *)ButtonText.c_str()))-2)+17;
+ break;
+ }
+ }
+ else
+ {
+ switch(textHAlign)
+ {
+ case AlignLeft:
+ textPosition.X = 3;
+ break;
+ case AlignCentre:
+ textPosition.X = (Size.X-Graphics::textwidth((char *)ButtonText.c_str()))/2;
+ break;
+ case AlignRight:
+ textPosition.X = (Size.X-Graphics::textwidth((char *)ButtonText.c_str()))-2;
+ break;
+ }
}
}
+void Button::SetIcon(Icon icon)
+{
+ this->icon = icon;
+ TextPosition();
+}
+
void Button::SetText(std::string buttonText)
{
ButtonText = buttonText;
@@ -150,13 +138,15 @@ void Button::Draw(const Point& screenPos)
g->drawrect(Position.X, Position.Y, Size.X, Size.Y, 180, 180, 180, 255);
g->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y, ButtonText, 180, 180, 180, 255);
}
+ if(icon)
+ g->draw_icon(Position.X+3, Position.Y+textPosition.Y, icon);
}
void Button::OnMouseUp(int x, int y, unsigned int button)
{
if(button != 1)
{
- return; //left click only!
+ return;
}
if(isButtonDown)
@@ -167,16 +157,9 @@ void Button::OnMouseUp(int x, int y, unsigned int button)
isButtonDown = false;
}
-//void Button::OnMouseUp(int x, int y, unsigned int button) //mouse unclick is called before this
-//{
- // if(button != 1) return; //left click only!
-
-// isButtonDown = false;
-//}
-
void Button::OnMouseClick(int x, int y, unsigned int button)
{
- if(button != 1) return; //left click only!
+ if(button != 1) return;
if(isTogglable)
{
toggle = !toggle;
diff --git a/src/interface/Button.h b/src/interface/Button.h
index 1075b32..4537e1f 100644
--- a/src/interface/Button.h
+++ b/src/interface/Button.h
@@ -26,13 +26,10 @@ public:
class Button : public Component
{
public:
- Button(Window* parent_state, std::string buttonText);
-
- Button(Point position, Point size, std::string buttonText);
-
- Button(std::string buttonText);
+ Button(Point position = Point(0, 0), Point size = Point(0, 0), std::string buttonText = "");
virtual ~Button();
+ Icon icon;
bool Toggleable;
bool Enabled;
@@ -68,6 +65,8 @@ public:
void SetActiveBorderColour(Colour border) { this->activeBorder = border; }
void SetTextColour(Colour text) { this->text = text; }
void SetActiveTextColour(Colour text) { this->activeText = text; }
+
+ void SetIcon(Icon icon);
protected:
Colour background, activeBackground;
Colour border, activeBorder;
diff --git a/src/preview/PreviewView.cpp b/src/preview/PreviewView.cpp
index 983e730..8c69b7b 100644
--- a/src/preview/PreviewView.cpp
+++ b/src/preview/PreviewView.cpp
@@ -32,6 +32,10 @@ PreviewView::PreviewView():
saveNameLabel = new ui::Label(ui::Point(5, (YRES/2)+5), ui::Point(100, 16), "");
saveNameLabel->SetAlignment(AlignLeft, AlignBottom);
AddComponent(saveNameLabel);
+
+ authorDateLabel = new ui::Label(ui::Point(5, (YRES/2)+5+16), ui::Point(100, 16), "");
+ authorDateLabel->SetAlignment(AlignLeft, AlignBottom);
+ AddComponent(authorDateLabel);
}
void PreviewView::OnDraw()
diff --git a/src/preview/PreviewView.h b/src/preview/PreviewView.h
index ac17df5..e788210 100644
--- a/src/preview/PreviewView.h
+++ b/src/preview/PreviewView.h
@@ -21,6 +21,7 @@ class PreviewView: public ui::Window {
Thumbnail * savePreview;
ui::Button * openButton;
ui::Label * saveNameLabel;
+ ui::Label * authorDateLabel;
public:
void AttachController(PreviewController * controller) { c = controller;}
PreviewView();
diff --git a/src/render/RenderModel.cpp b/src/render/RenderModel.cpp
index 65f4a89..52a32ac 100644
--- a/src/render/RenderModel.cpp
+++ b/src/render/RenderModel.cpp
@@ -7,7 +7,9 @@
#include "RenderModel.h"
-RenderModel::RenderModel() {
+RenderModel::RenderModel():
+ renderer(NULL)
+{
// TODO Auto-generated constructor stub
}