Some inlines and Checkbox ui component
This commit is contained in:
parent
e84f0fc6e5
commit
ebd80c73de
@ -70,7 +70,7 @@ int plasma_data_points = 5;
|
||||
pixel plasma_data_colours[] = {PIXPACK(0xAFFFFF), PIXPACK(0xAFFFFF), PIXPACK(0x301060), PIXPACK(0x301040), PIXPACK(0x000000)};
|
||||
float plasma_data_pos[] = {1.0f, 0.9f, 0.5f, 0.25, 0.0f};*/
|
||||
|
||||
char * Graphics::generate_gradient(pixel * colours, float * points, int pointcount, int size)
|
||||
char * Graphics::GenerateGradient(pixel * colours, float * points, int pointcount, int size)
|
||||
{
|
||||
int cp, i, j;
|
||||
pixel ptemp;
|
||||
|
@ -91,8 +91,8 @@ public:
|
||||
SDL_Surface * sdl_scrn;
|
||||
pixel *vid;
|
||||
pixel *render_packed_rgb(void *image, int width, int height, int cmp_size);
|
||||
static char * generate_gradient(pixel * colours, float * points, int pointcount, int size);
|
||||
void draw_other();
|
||||
static char * GenerateGradient(pixel * colours, float * points, int pointcount, int size);
|
||||
//void draw_other();
|
||||
void draw_rgba_image(unsigned char *data, int x, int y, float a);
|
||||
static void *ptif_pack(pixel *src, int w, int h, int *result_size);
|
||||
static pixel *ptif_unpack(void *datain, int size, int *w, int *h);
|
||||
@ -103,13 +103,13 @@ public:
|
||||
//void sdl_blit_1(int x, int y, int w, int h, pixel *src, int pitch);
|
||||
//void sdl_blit_2(int x, int y, int w, int h, pixel *src, int pitch);
|
||||
//void sdl_blit(int x, int y, int w, int h, pixel *src, int pitch);
|
||||
void drawblob(int x, int y, unsigned char cr, unsigned char cg, unsigned char cb);
|
||||
inline void drawblob(int x, int y, unsigned char cr, unsigned char cg, unsigned char cb);
|
||||
void draw_tool(int b, int sl, int sr, unsigned pc, unsigned iswall);
|
||||
//int draw_tool_xy(pixel *vid_buf, int x, int y, int b, unsigned pc);
|
||||
//void draw_menu(pixel *vid_buf, int i, int hover);
|
||||
void drawpixel(int x, int y, int r, int g, int b, int a);
|
||||
int addchar(int x, int y, int c, int r, int g, int b, int a);
|
||||
int drawchar(int x, int y, int c, int r, int g, int b, int a);
|
||||
inline int addchar(int x, int y, int c, int r, int g, int b, int a);
|
||||
inline int drawchar(int x, int y, int c, int r, int g, int b, int a);
|
||||
int drawtext(int x, int y, std::string &s, int r, int g, int b, int a);
|
||||
int drawtext(int x, int y, const char *s, int r, int g, int b, int a);
|
||||
int drawtext_outline(int x, int y, const char *s, int r, int g, int b, int a, int olr, int olg, int olb, int ola);
|
||||
@ -125,17 +125,17 @@ public:
|
||||
static int textwidthx(char *s, int w);
|
||||
static int textposxy(char *s, int width, int w, int h);
|
||||
static int textwrapheight(char *s, int width);
|
||||
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_air();
|
||||
//void draw_grav_zones(pixel *vid);
|
||||
//void draw_grav(pixel *vid);
|
||||
void draw_line(int x1, int y1, int x2, int y2, int r, int g, int b, int a);
|
||||
void addpixel(int x, int y, int r, int g, int b, int a);
|
||||
inline void addpixel(int x, int y, int r, int g, int b, int a);
|
||||
void xor_pixel(int x, int y);
|
||||
void xor_line(int x1, int y1, int x2, int y2);
|
||||
void xor_rect(int x, int y, int w, int h);
|
||||
void blend_line(int x1, int y1, int x2, int y2, int r, int g, int b, int a);
|
||||
inline void blend_line(int x1, int y1, int x2, int y2, int r, int g, int b, int a);
|
||||
//void render_parts(pixel *vid);
|
||||
// #ifdef OGLR
|
||||
// void draw_parts_fbo();
|
||||
@ -147,11 +147,11 @@ public:
|
||||
// void line_decorations(int x1, int y1, int x2, int y2, int rx, int ry, int r, int g, int b, int click, int tool);
|
||||
// void box_decorations(int x1, int y1, int x2, int y2, int r, int g, int b, int click, int tool);
|
||||
// void draw_color_menu(pixel *vid_buf, int i, int hover);
|
||||
void draw_wavelengths(int x, int y, int h, int wl);
|
||||
void render_signs();
|
||||
inline void draw_wavelengths(int x, int y, int h, int wl);
|
||||
//void render_signs();
|
||||
// void render_fire(pixel *dst);
|
||||
// void prepare_alpha(int size, float intensity);
|
||||
void draw_image(pixel *img, int x, int y, int w, int h, int a);
|
||||
inline void draw_image(pixel *img, int x, int y, int w, int h, int a);
|
||||
static void dim_copy(pixel *dst, pixel *src);
|
||||
static void dim_copy_pers(pixel *dst, pixel *src);
|
||||
//void render_zoom(pixel *img);
|
||||
|
122
src/Renderer.cpp
122
src/Renderer.cpp
@ -18,7 +18,7 @@ extern "C"
|
||||
#include "hmap.h"
|
||||
}
|
||||
|
||||
void Renderer::draw_walls()
|
||||
void Renderer::DrawWalls()
|
||||
{
|
||||
int x, y, i, j, cr, cg, cb;
|
||||
unsigned char wt;
|
||||
@ -250,7 +250,7 @@ void Renderer::get_sign_pos(int i, int *x0, int *y0, int *w, int *h)
|
||||
*y0 = (signs[i].y > 18) ? signs[i].y - 18 : signs[i].y + 4;
|
||||
}
|
||||
|
||||
void Renderer::render_signs()
|
||||
void Renderer::DrawSigns()
|
||||
{
|
||||
int i, j, x, y, w, h, dx, dy,mx,my,b=1,bq;
|
||||
sign *signs = sim->signs;
|
||||
@ -1429,12 +1429,6 @@ void Renderer::render_parts()
|
||||
#endif
|
||||
}
|
||||
|
||||
void Renderer::prepare_graphicscache()
|
||||
{
|
||||
graphicscache = (gcache_item *)malloc(sizeof(gcache_item)*PT_NUM);
|
||||
memset(graphicscache, 0, sizeof(gcache_item)*PT_NUM);
|
||||
}
|
||||
|
||||
void Renderer::draw_other() // EMP effect
|
||||
{
|
||||
int i, j;
|
||||
@ -1648,33 +1642,6 @@ void Renderer::draw_grav_zones()
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer::init_display_modes()
|
||||
{
|
||||
int i;
|
||||
colour_mode = COLOUR_DEFAULT;
|
||||
display_modes = (unsigned int*)calloc(1, sizeof(unsigned int));
|
||||
render_modes = (unsigned int*)calloc(2, sizeof(unsigned int));
|
||||
|
||||
display_modes[0] = 0;
|
||||
render_modes[0] = RENDER_FIRE;
|
||||
render_modes[1] = 0;
|
||||
|
||||
display_mode = 0;
|
||||
i = 0;
|
||||
while(display_modes[i])
|
||||
{
|
||||
display_mode |= display_modes[i];
|
||||
i++;
|
||||
}
|
||||
render_mode = 0;
|
||||
i = 0;
|
||||
while(render_modes[i])
|
||||
{
|
||||
render_mode |= render_modes[i];
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
Renderer::Renderer(Graphics * g, Simulation * sim):
|
||||
sim(NULL),
|
||||
g(NULL)
|
||||
@ -1686,19 +1653,82 @@ Renderer::Renderer(Graphics * g, Simulation * sim):
|
||||
memset(fire_g, 0, sizeof(fire_g));
|
||||
memset(fire_b, 0, sizeof(fire_b));
|
||||
prepare_alpha(CELL, 1.0f);
|
||||
init_display_modes();
|
||||
prepare_graphicscache();
|
||||
|
||||
int flm_data_points = 4;
|
||||
pixel flm_data_colours[] = {PIXPACK(0xAF9F0F), PIXPACK(0xDFBF6F), PIXPACK(0x60300F), PIXPACK(0x000000)};
|
||||
float flm_data_pos[] = {1.0f, 0.9f, 0.5f, 0.0f};
|
||||
//Set defauly display modes
|
||||
SetColourMode(COLOUR_DEFAULT);
|
||||
AddRenderMode(RENDER_FIRE);
|
||||
|
||||
int plasma_data_points = 5;
|
||||
pixel plasma_data_colours[] = {PIXPACK(0xAFFFFF), PIXPACK(0xAFFFFF), PIXPACK(0x301060), PIXPACK(0x301040), PIXPACK(0x000000)};
|
||||
float plasma_data_pos[] = {1.0f, 0.9f, 0.5f, 0.25, 0.0f};
|
||||
//Prepare the graphics cache
|
||||
graphicscache = (gcache_item *)malloc(sizeof(gcache_item)*PT_NUM);
|
||||
memset(graphicscache, 0, sizeof(gcache_item)*PT_NUM);
|
||||
|
||||
flm_data = Graphics::generate_gradient(flm_data_colours, flm_data_pos, flm_data_points, 200);
|
||||
plasma_data = Graphics::generate_gradient(plasma_data_colours, plasma_data_pos, plasma_data_points, 200);
|
||||
int fireColoursCount = 4;
|
||||
pixel fireColours[] = {PIXPACK(0xAF9F0F), PIXPACK(0xDFBF6F), PIXPACK(0x60300F), PIXPACK(0x000000)};
|
||||
float fireColoursPoints[] = {1.0f, 0.9f, 0.5f, 0.0f};
|
||||
|
||||
int plasmaColoursCount = 5;
|
||||
pixel plasmaColours[] = {PIXPACK(0xAFFFFF), PIXPACK(0xAFFFFF), PIXPACK(0x301060), PIXPACK(0x301040), PIXPACK(0x000000)};
|
||||
float plasmaColoursPoints[] = {1.0f, 0.9f, 0.5f, 0.25, 0.0f};
|
||||
|
||||
flm_data = Graphics::GenerateGradient(fireColours, fireColoursPoints, fireColoursCount, 200);
|
||||
plasma_data = Graphics::GenerateGradient(plasmaColours, plasmaColoursPoints, plasmaColoursCount, 200);
|
||||
}
|
||||
|
||||
void Renderer::CompileRenderMode()
|
||||
{
|
||||
render_mode = 0;
|
||||
for(int i = 0; i < render_modes.size(); i++)
|
||||
render_mode |= render_modes[i];
|
||||
}
|
||||
|
||||
void Renderer::AddRenderMode(unsigned int mode)
|
||||
{
|
||||
render_modes.push_back(mode);
|
||||
CompileRenderMode();
|
||||
}
|
||||
|
||||
void Renderer::RemoveRenderMode(unsigned int mode)
|
||||
{
|
||||
for(int i = 0; i < render_modes.size(); i++)
|
||||
{
|
||||
if(render_modes[i] == mode)
|
||||
{
|
||||
render_modes.erase(render_modes.begin() + i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
CompileRenderMode();
|
||||
}
|
||||
|
||||
void Renderer::CompileDisplayMode()
|
||||
{
|
||||
display_mode = 0;
|
||||
for(int i = 0; i < display_modes.size(); i++)
|
||||
display_mode |= display_modes[i];
|
||||
}
|
||||
|
||||
void Renderer::AddDisplayMode(unsigned int mode)
|
||||
{
|
||||
display_modes.push_back(mode);
|
||||
CompileDisplayMode();
|
||||
}
|
||||
|
||||
void Renderer::RemoveDisplayMode(unsigned int mode)
|
||||
{
|
||||
for(int i = 0; i < display_modes.size(); i++)
|
||||
{
|
||||
if(display_modes[i] == mode)
|
||||
{
|
||||
display_modes.erase(display_modes.begin() + i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
CompileDisplayMode();
|
||||
}
|
||||
|
||||
void Renderer::SetColourMode(unsigned int mode)
|
||||
{
|
||||
colour_mode = mode;
|
||||
}
|
||||
|
||||
Renderer::~Renderer()
|
||||
@ -1706,6 +1736,4 @@ Renderer::~Renderer()
|
||||
free(graphicscache);
|
||||
free(flm_data);
|
||||
free(plasma_data);
|
||||
free(render_modes);
|
||||
free(display_modes);
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
#ifndef RENDERER_H
|
||||
#define RENDERER_H
|
||||
|
||||
#include <vector>
|
||||
#include "Config.h"
|
||||
#include "simulation/Simulation.h"
|
||||
#include "Graphics.h"
|
||||
@ -21,11 +22,10 @@ typedef struct gcache_item gcache_item;
|
||||
class Renderer
|
||||
{
|
||||
public:
|
||||
//TODO: Vectors!
|
||||
unsigned int *render_modes;
|
||||
std::vector<unsigned int> render_modes;
|
||||
unsigned int render_mode;
|
||||
unsigned int colour_mode;
|
||||
unsigned int *display_modes;
|
||||
std::vector<unsigned int> display_modes;
|
||||
unsigned int display_mode;
|
||||
//
|
||||
unsigned char fire_r[YRES/CELL][XRES/CELL];
|
||||
@ -40,9 +40,10 @@ public:
|
||||
Simulation * sim;
|
||||
Graphics * g;
|
||||
gcache_item *graphicscache;
|
||||
//
|
||||
void draw_walls();
|
||||
void render_signs();
|
||||
|
||||
//Renderers
|
||||
void DrawWalls();
|
||||
void DrawSigns();
|
||||
void render_gravlensing();
|
||||
void render_fire();
|
||||
void prepare_alpha(int size, float intensity);
|
||||
@ -51,9 +52,19 @@ public:
|
||||
void draw_air();
|
||||
void draw_grav();
|
||||
void draw_other();
|
||||
void init_display_modes();
|
||||
|
||||
//...
|
||||
void get_sign_pos(int i, int *x0, int *y0, int *w, int *h);
|
||||
void prepare_graphicscache();
|
||||
|
||||
//Display mode modifiers
|
||||
void CompileDisplayMode();
|
||||
void CompileRenderMode();
|
||||
void AddRenderMode(unsigned int mode);
|
||||
void RemoveRenderMode(unsigned int mode);
|
||||
void AddDisplayMode(unsigned int mode);
|
||||
void RemoveDisplayMode(unsigned int mode);
|
||||
void SetColourMode(unsigned int mode);
|
||||
|
||||
Renderer(Graphics * g, Simulation * sim);
|
||||
~Renderer();
|
||||
};
|
||||
|
@ -428,8 +428,8 @@ void GameView::OnDraw()
|
||||
{
|
||||
ren->render_parts();
|
||||
ren->render_fire();
|
||||
ren->render_signs();
|
||||
ren->draw_walls();
|
||||
ren->DrawSigns();
|
||||
ren->DrawWalls();
|
||||
}
|
||||
if(activeBrush && currentMouse.X > 0 && currentMouse.X < XRES && currentMouse.Y > 0 && currentMouse.Y < YRES)
|
||||
{
|
||||
|
@ -204,6 +204,8 @@ void Button::DoAction()
|
||||
|
||||
void Button::SetActionCallback(ButtonAction * action)
|
||||
{
|
||||
if(actionCallback)
|
||||
delete actionCallback;
|
||||
actionCallback = action;
|
||||
}
|
||||
|
||||
|
89
src/interface/Checkbox.cpp
Normal file
89
src/interface/Checkbox.cpp
Normal file
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Checkbox.cpp
|
||||
*
|
||||
* Created on: Jan 26, 2012
|
||||
* Author: Simon
|
||||
*/
|
||||
|
||||
#include "Checkbox.h"
|
||||
|
||||
using namespace ui;
|
||||
|
||||
Checkbox::Checkbox(ui::Point position, ui::Point size, std::string text):
|
||||
Component(position, size),
|
||||
text(text),
|
||||
isMouseOver(false),
|
||||
checked(false),
|
||||
actionCallback(NULL)
|
||||
{
|
||||
// TODO Auto-generated constructor stub
|
||||
|
||||
}
|
||||
|
||||
void Checkbox::SetText(std::string text)
|
||||
{
|
||||
this->text = text;
|
||||
}
|
||||
|
||||
void Checkbox::OnMouseClick(int x, int y, unsigned int button)
|
||||
{
|
||||
if(checked)
|
||||
{
|
||||
checked = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
checked = true;
|
||||
}
|
||||
if(actionCallback)
|
||||
actionCallback->ActionCallback(this);
|
||||
}
|
||||
|
||||
void Checkbox::OnMouseUp(int x, int y, unsigned int button)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Checkbox::OnMouseEnter(int x, int y)
|
||||
{
|
||||
isMouseOver = true;
|
||||
}
|
||||
|
||||
void Checkbox::OnMouseLeave(int x, int y)
|
||||
{
|
||||
isMouseOver = false;
|
||||
}
|
||||
|
||||
void Checkbox::Draw(const Point& screenPos)
|
||||
{
|
||||
Graphics * g = Engine::Ref().g;
|
||||
if(checked)
|
||||
{
|
||||
g->fillrect(screenPos.X+4, screenPos.Y+4, 8, 8, 255, 255, 255, 255);
|
||||
}
|
||||
if(isMouseOver)
|
||||
{
|
||||
g->drawrect(screenPos.X+2, screenPos.Y+2, 12, 12, 255, 255, 255, 255);
|
||||
g->fillrect(screenPos.X+4, screenPos.Y+4, 8, 8, 255, 255, 255, 170);
|
||||
g->drawtext(screenPos.X+18, screenPos.Y+4, text, 255, 255, 255, 255);
|
||||
}
|
||||
else
|
||||
{
|
||||
g->drawrect(screenPos.X+2, screenPos.Y+2, 12, 12, 255, 255, 255, 200);
|
||||
g->drawtext(screenPos.X+18, screenPos.Y+4, text, 255, 255, 255, 200);
|
||||
}
|
||||
}
|
||||
|
||||
void Checkbox::SetActionCallback(CheckboxAction * action)
|
||||
{
|
||||
if(actionCallback)
|
||||
delete actionCallback;
|
||||
actionCallback = action;
|
||||
}
|
||||
|
||||
Checkbox::~Checkbox() {
|
||||
if(actionCallback)
|
||||
delete actionCallback;
|
||||
}
|
||||
|
40
src/interface/Checkbox.h
Normal file
40
src/interface/Checkbox.h
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Checkbox.h
|
||||
*
|
||||
* Created on: Jan 26, 2012
|
||||
* Author: Simon
|
||||
*/
|
||||
|
||||
#ifndef CHECKBOX_H_
|
||||
#define CHECKBOX_H_
|
||||
|
||||
#include <string>
|
||||
#include "Component.h"
|
||||
namespace ui
|
||||
{
|
||||
class Checkbox;
|
||||
class CheckboxAction
|
||||
{
|
||||
public:
|
||||
virtual void ActionCallback(ui::Checkbox * sender) {}
|
||||
virtual ~CheckboxAction() {}
|
||||
};
|
||||
class Checkbox: public ui::Component {
|
||||
std::string text;
|
||||
bool checked;
|
||||
bool isMouseOver;
|
||||
CheckboxAction * actionCallback;
|
||||
public:
|
||||
Checkbox(ui::Point position, ui::Point size, std::string text);
|
||||
void SetText(std::string text);
|
||||
void Draw(const Point& screenPos);
|
||||
virtual void OnMouseEnter(int x, int y);
|
||||
virtual void OnMouseLeave(int x, int y);
|
||||
virtual void OnMouseClick(int x, int y, unsigned int button);
|
||||
virtual void OnMouseUp(int x, int y, unsigned int button);
|
||||
void SetActionCallback(CheckboxAction * action);
|
||||
virtual ~Checkbox();
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* CHECKBOX_H_ */
|
@ -12,7 +12,10 @@ RenderView::RenderView():
|
||||
ui::Window(ui::Point(0, 0), ui::Point(XRES, YRES+MENUSIZE)),
|
||||
ren(NULL)
|
||||
{
|
||||
// TODO Auto-generated constructor stub
|
||||
ui::Checkbox * tCheckbox;
|
||||
tCheckbox = new ui::Checkbox(ui::Point(0, YRES+5), ui::Point(100, 16), "Thing");
|
||||
renderModes.push_back(tCheckbox);
|
||||
AddComponent(tCheckbox);
|
||||
|
||||
}
|
||||
|
||||
|
@ -8,16 +8,20 @@
|
||||
#ifndef RENDERVIEW_H_
|
||||
#define RENDERVIEW_H_
|
||||
|
||||
|
||||
#include <vector>
|
||||
#include "interface/Window.h"
|
||||
#include "RenderController.h"
|
||||
#include "RenderModel.h"
|
||||
#include "Renderer.h"
|
||||
#include "interface/Checkbox.h"
|
||||
|
||||
class RenderController;
|
||||
class RenderModel;
|
||||
class RenderView: public ui::Window {
|
||||
RenderController * c;
|
||||
Renderer * ren;
|
||||
std::vector<ui::Checkbox*> renderModes;
|
||||
public:
|
||||
RenderView();
|
||||
void NotifyRendererChanged(RenderModel * sender);
|
||||
|
Reference in New Issue
Block a user