Icon management, fix element menu order, fix renderer crash

This commit is contained in:
Simon Robertshaw
2012-01-27 20:19:42 +00:00
parent 597d11f9f7
commit 07525180c2
13 changed files with 150 additions and 124 deletions

View File

@@ -39,7 +39,7 @@ build/powder-release: $(SOURCES)
strip $@ strip $@
build/powder.exe: buildpaths-powder.exe $(patsubst build/obj/%.o,build/obj/powder.exe/%.o,$(OBJS)) build/powder.exe: buildpaths-powder.exe $(patsubst build/obj/%.o,build/obj/powder.exe/%.o,$(OBJS))
$(CPP_WINC) $(CFLAGS) $(OFLAGS) $(LDFLAGS) $(patsubst build/obj/%.o,build/obj/powder.exe/%.o,$(OBJS)) $(LFLAGS) -o $@ -ggdb $(CPPC_WIN) $(CFLAGS) $(OFLAGS) $(LDFLAGS) $(patsubst build/obj/%.o,build/obj/powder.exe/%.o,$(OBJS)) $(LFLAGS) -o $@ -ggdb
build/obj/powder.exe/%.o: src/%.cpp $(HEADERS) build/obj/powder.exe/%.o: src/%.cpp $(HEADERS)
$(CPPC_WIN) -c $(CFLAGS) $(OFLAGS) -o $@ $< -ggdb $(CPPC_WIN) -c $(CFLAGS) $(OFLAGS) -o $@ $< -ggdb
buildpaths-powder.exe: buildpaths-powder.exe:

View File

@@ -1141,20 +1141,54 @@ TPT_INLINE void Graphics::blendpixel(int x, int y, int r, int g, int b, int a)
#endif #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]; switch(icon)
t[0] = ch;
t[1] = 0;
if (flag)
{ {
fillrect(x-1, y-1, 17, 17, 255, 255, 255, 255); case IconOpen:
drawtext(x+3, y+2, t, 0, 0, 0, 255); drawchar(x, y, 0x81, 255, 255, 255, 255);
} break;
else case IconReload:
{ drawchar(x, y, 0x91, 255, 255, 255, 255);
drawrect(x, y, 15, 15, 255, 255, 255, 255); break;
drawtext(x+3, y+2, t, 255, 255, 255, 255); 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;
} }
} }

View File

@@ -52,38 +52,28 @@ typedef unsigned short pixel;
typedef unsigned int pixel; typedef unsigned int pixel;
#endif #endif
/*extern int emp_decor; //Icon names, see Graphics::draw_icon
enum Icon
extern unsigned int *render_modes; {
extern unsigned int render_mode; NoIcon = 0,
extern unsigned int colour_mode; IconOpen,
extern unsigned int *display_modes; IconReload,
extern unsigned int display_mode; IconSave,
IconVoteUp,
extern SDL_Surface *sdl_scrn; IconVoteDown,
extern int sdl_scale; IconTag,
IconNew,
extern int sandcolour_r; IconLogin,
extern int sandcolour_g; IconRenderSettings,
extern int sandcolour_b; IconSimulationSettings,
extern int sandcolour_frame; IconPause,
IconVoteSort,
extern unsigned char fire_r[YRES/CELL][XRES/CELL]; IconDateSort,
extern unsigned char fire_g[YRES/CELL][XRES/CELL]; IconFavourite,
extern unsigned char fire_b[YRES/CELL][XRES/CELL]; IconFolder,
IconSearch,
extern unsigned int fire_alpha[CELL*3][CELL*3]; IconDelete
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[];*/
class Graphics class Graphics
{ {
@@ -126,7 +116,7 @@ public:
static int textposxy(char *s, int width, int w, int h); static int textposxy(char *s, int width, int w, int h);
static int textwrapheight(char *s, int width); static int textwrapheight(char *s, int width);
inline void blendpixel(int x, int y, int r, int g, int b, int a); 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_air();
//void draw_grav_zones(pixel *vid); //void draw_grav_zones(pixel *vid);
//void draw_grav(pixel *vid); //void draw_grav(pixel *vid);

View File

@@ -11,7 +11,7 @@ int update_BOMB(UPDATE_FUNC_ARGS) {
r = pmap[y+ry][x+rx]; r = pmap[y+ry][x+rx];
if (!r) if (!r)
continue; 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); sim->kill_part(i);
return 1; return 1;
} }

View File

@@ -357,7 +357,7 @@ int graphics_GLOW(GRAPHICS_FUNC_ARGS)
} }
int graphics_LCRY(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; *colr = (cpart->dcolour>>16)&0xFF;
*colg = (cpart->dcolour>>8)&0xFF; *colg = (cpart->dcolour>>8)&0xFF;

View File

@@ -78,6 +78,7 @@ int run_stickman(playerst* playerp, UPDATE_FUNC_ARGS) {
gvx = ((float)(parts[i].x - XCNTR) / gravd); gvx = ((float)(parts[i].x - XCNTR) / gravd);
gvy = ((float)(parts[i].y - YCNTR) / gravd); gvy = ((float)(parts[i].y - YCNTR) / gravd);
} }
break;
} }
gvx += sim->gravx[((int)parts[i].y/CELL)*(XRES/CELL)+((int)parts[i].x/CELL)]; gvx += sim->gravx[((int)parts[i].y/CELL)*(XRES/CELL)+((int)parts[i].x/CELL)];

View File

@@ -64,4 +64,5 @@ int graphics_WIRE(GRAPHICS_FUNC_ARGS)
//*pixel_mode |= PMODE_GLOW; //*pixel_mode |= PMODE_GLOW;
return 0; return 0;
} }
return 0;
} }

View File

@@ -25,7 +25,8 @@ GameView::GameView():
v->c->OpenSearch(); 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; currentX+=18;
searchButton->SetTogglable(false); searchButton->SetTogglable(false);
searchButton->SetActionCallback(new SearchAction(this)); searchButton->SetActionCallback(new SearchAction(this));
@@ -41,7 +42,8 @@ GameView::GameView():
v->c->ReloadSim(); 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; currentX+=18;
reloadButton->SetActionCallback(new ReloadAction(this)); reloadButton->SetActionCallback(new ReloadAction(this));
AddComponent(reloadButton); AddComponent(reloadButton);
@@ -56,7 +58,8 @@ GameView::GameView():
v->c->OpenSaveWindow(); 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; currentX+=(Size.X/5)+2;
saveSimulationButton->SetActionCallback(new SaveSimulationAction(this)); saveSimulationButton->SetActionCallback(new SaveSimulationAction(this));
AddComponent(saveSimulationButton); AddComponent(saveSimulationButton);
@@ -71,7 +74,8 @@ GameView::GameView():
v->c->Vote(1); 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; currentX+=16;
upVoteButton->SetActionCallback(new UpVoteAction(this)); upVoteButton->SetActionCallback(new UpVoteAction(this));
AddComponent(upVoteButton); AddComponent(upVoteButton);
@@ -86,7 +90,8 @@ GameView::GameView():
v->c->Vote(-1); 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; currentX+=18;
downVoteButton->SetActionCallback(new DownVoteAction(this)); downVoteButton->SetActionCallback(new DownVoteAction(this));
AddComponent(downVoteButton); AddComponent(downVoteButton);
@@ -101,7 +106,8 @@ GameView::GameView():
v->c->OpenTags(); 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); currentX+=Size.X-(currentX+176);
tagSimulationButton->SetActionCallback(new TagSimulationAction(this)); tagSimulationButton->SetActionCallback(new TagSimulationAction(this));
AddComponent(tagSimulationButton); AddComponent(tagSimulationButton);
@@ -116,7 +122,8 @@ GameView::GameView():
v->c->ClearSim(); 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)); clearSimButton->SetActionCallback(new ClearSimAction(this));
AddComponent(clearSimButton); AddComponent(clearSimButton);
@@ -130,7 +137,8 @@ GameView::GameView():
v->c->OpenLogin(); 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)); loginButton->SetActionCallback(new LoginAction(this));
AddComponent(loginButton); AddComponent(loginButton);
@@ -144,7 +152,8 @@ GameView::GameView():
v->c->OpenDisplayOptions(); 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)); simulationOptionButton->SetActionCallback(new SimulationOptionAction(this));
AddComponent(simulationOptionButton); AddComponent(simulationOptionButton);
@@ -158,7 +167,8 @@ GameView::GameView():
v->c->OpenRenderOptions(); 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)); displayModeButton->SetActionCallback(new DisplayModeAction(this));
AddComponent(displayModeButton); AddComponent(displayModeButton);
@@ -172,7 +182,8 @@ GameView::GameView():
v->c->SetPaused(sender->GetToggleState()); 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->SetTogglable(true);
pauseButton->SetActionCallback(new PauseAction(this)); pauseButton->SetActionCallback(new PauseAction(this));
AddComponent(pauseButton); AddComponent(pauseButton);
@@ -204,7 +215,7 @@ public:
void GameView::NotifyMenuListChanged(GameModel * sender) 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++) for(int i = 0; i < menuButtons.size(); i++)
{ {
RemoveComponent(menuButtons[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); ui::Button * tempButton = new ui::Button(ui::Point(XRES+BARSIZE-18, currentY), ui::Point(16, 16), tempString);
tempButton->SetTogglable(true); tempButton->SetTogglable(true);
tempButton->SetActionCallback(new MenuAction(this, menuList[i])); tempButton->SetActionCallback(new MenuAction(this, menuList[i]));
currentY-=18; currentY+=18;
AddComponent(tempButton); AddComponent(tempButton);
menuButtons.push_back(tempButton); menuButtons.push_back(tempButton);
} }

View File

@@ -15,24 +15,6 @@
namespace ui { 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): Button::Button(Point position, Point size, std::string buttonText):
Component(position, size), Component(position, size),
ButtonText(buttonText), ButtonText(buttonText),
@@ -44,25 +26,8 @@ Button::Button(Point position, Point size, std::string buttonText):
textPosition(ui::Point(0, 0)), textPosition(ui::Point(0, 0)),
textVAlign(AlignMiddle), textVAlign(AlignMiddle),
textHAlign(AlignCentre), textHAlign(AlignCentre),
Enabled(true) Enabled(true),
{ icon(NoIcon)
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)
{ {
activeText = background = Colour(0, 0, 0); activeText = background = Colour(0, 0, 0);
text = activeBackground = border = activeBorder = Colour(255, 255, 255); text = activeBackground = border = activeBorder = Colour(255, 255, 255);
@@ -71,7 +36,6 @@ Button::Button(std::string buttonText):
void Button::TextPosition() void Button::TextPosition()
{ {
//Position.X+(Size.X-Graphics::textwidth((char *)ButtonText.c_str()))/2, Position.Y+(Size.Y-10)/2
switch(textVAlign) switch(textVAlign)
{ {
case AlignTop: case AlignTop:
@@ -85,18 +49,42 @@ void Button::TextPosition()
break; break;
} }
switch(textHAlign) if(icon)
{ {
case AlignLeft: switch(textHAlign)
textPosition.X = 3; {
break; case AlignLeft:
case AlignCentre: textPosition.X = 3+17;
textPosition.X = (Size.X-Graphics::textwidth((char *)ButtonText.c_str()))/2; break;
break; case AlignCentre:
case AlignRight: textPosition.X = (((Size.X-14)-Graphics::textwidth((char *)ButtonText.c_str()))/2)+17;
textPosition.X = (Size.X-Graphics::textwidth((char *)ButtonText.c_str()))-2; break;
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) void Button::SetText(std::string 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->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); 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) void Button::OnMouseUp(int x, int y, unsigned int button)
{ {
if(button != 1) if(button != 1)
{ {
return; //left click only! return;
} }
if(isButtonDown) if(isButtonDown)
@@ -167,16 +157,9 @@ void Button::OnMouseUp(int x, int y, unsigned int button)
isButtonDown = false; 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) void Button::OnMouseClick(int x, int y, unsigned int button)
{ {
if(button != 1) return; //left click only! if(button != 1) return;
if(isTogglable) if(isTogglable)
{ {
toggle = !toggle; toggle = !toggle;

View File

@@ -26,13 +26,10 @@ public:
class Button : public Component class Button : public Component
{ {
public: public:
Button(Window* parent_state, std::string buttonText); Button(Point position = Point(0, 0), Point size = Point(0, 0), std::string buttonText = "");
Button(Point position, Point size, std::string buttonText);
Button(std::string buttonText);
virtual ~Button(); virtual ~Button();
Icon icon;
bool Toggleable; bool Toggleable;
bool Enabled; bool Enabled;
@@ -68,6 +65,8 @@ public:
void SetActiveBorderColour(Colour border) { this->activeBorder = border; } void SetActiveBorderColour(Colour border) { this->activeBorder = border; }
void SetTextColour(Colour text) { this->text = text; } void SetTextColour(Colour text) { this->text = text; }
void SetActiveTextColour(Colour text) { this->activeText = text; } void SetActiveTextColour(Colour text) { this->activeText = text; }
void SetIcon(Icon icon);
protected: protected:
Colour background, activeBackground; Colour background, activeBackground;
Colour border, activeBorder; Colour border, activeBorder;

View File

@@ -32,6 +32,10 @@ PreviewView::PreviewView():
saveNameLabel = new ui::Label(ui::Point(5, (YRES/2)+5), ui::Point(100, 16), ""); saveNameLabel = new ui::Label(ui::Point(5, (YRES/2)+5), ui::Point(100, 16), "");
saveNameLabel->SetAlignment(AlignLeft, AlignBottom); saveNameLabel->SetAlignment(AlignLeft, AlignBottom);
AddComponent(saveNameLabel); 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() void PreviewView::OnDraw()

View File

@@ -21,6 +21,7 @@ class PreviewView: public ui::Window {
Thumbnail * savePreview; Thumbnail * savePreview;
ui::Button * openButton; ui::Button * openButton;
ui::Label * saveNameLabel; ui::Label * saveNameLabel;
ui::Label * authorDateLabel;
public: public:
void AttachController(PreviewController * controller) { c = controller;} void AttachController(PreviewController * controller) { c = controller;}
PreviewView(); PreviewView();

View File

@@ -7,7 +7,9 @@
#include "RenderModel.h" #include "RenderModel.h"
RenderModel::RenderModel() { RenderModel::RenderModel():
renderer(NULL)
{
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
} }