Skip to content
This repository has been archived by the owner on Aug 23, 2023. It is now read-only.

Commit

Permalink
UI:Button hover: highlight demo
Browse files Browse the repository at this point in the history
  • Loading branch information
corwinn committed Jan 28, 2023
1 parent 8e3bd52 commit c5e4f87
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
23 changes: 20 additions & 3 deletions ui/h3r_button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ Button::Button(const String & res_name, Control * base)
glDisable (GL_MULTISAMPLE);
glShadeModel (GL_FLAT);

glGenTextures (1, &_tex);
glGenTextures (2, _tex);

glBindTexture (GL_TEXTURE_2D, _tex);
glBindTexture (GL_TEXTURE_2D, _tex[0]);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
Expand All @@ -89,6 +89,22 @@ Button::Button(const String & res_name, Control * base)
btn_def_n->Height (),
0, GL_RGBA, GL_UNSIGNED_BYTE, byte_arr_ptr->operator byte * ());

glBindTexture (GL_TEXTURE_2D, _tex[1]);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
n = res_name.ToLower ().Replace (".def", "h.pcx");
btn_def_n = btn_def.Query (n);
byte_arr_ptr = btn_def_n->RGBA ();
glTexImage2D (GL_TEXTURE_2D, 0, /*GL_COMPRESSED_RGBA_S3TC_DXT3_EXT,*/
GL_RGBA,
btn_def_n->Width (), // TODO power of 2 UI atlas
btn_def_n->Height (),
0, GL_RGBA, GL_UNSIGNED_BYTE, byte_arr_ptr->operator byte * ());

float fw = static_cast<float>(btn_def_n->Width ()),
fh = static_cast<float>(btn_def_n->Height ());
GLfloat v[16] {0,0,0,0, 0,fh,0,1, fw,0,1,0, fw,fh,1,1};
Expand Down Expand Up @@ -118,7 +134,8 @@ void Button::OnRender(GC &)
glAlphaFunc (GL_GEQUAL, 1.0f);
// glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

glBindTexture (GL_TEXTURE_2D, _tex);
if (! _mouse_over) glBindTexture (GL_TEXTURE_2D, _tex[0]);
else glBindTexture (GL_TEXTURE_2D, _tex[1]);
glBindBuffer (GL_ARRAY_BUFFER, _vbo);

glTranslatef (Pos ().X, Pos ().Y, 0);
Expand Down
4 changes: 2 additions & 2 deletions ui/h3r_button.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ H3R_NAMESPACE
// Its size is stored at the resource it is created from.
class Button: public Control
{
private: GLuint _tex, _vbo;
private: GLuint _tex[2] {}, _vbo;

public: Button(const String &, Control * = nullptr);
public: virtual ~Button() override
{
glDeleteBuffers (1, &_vbo), glDeleteTextures (1, &_tex);
glDeleteBuffers (1, &_vbo), glDeleteTextures (2, _tex);
}

public: virtual void OnRender(GC &) override;
Expand Down

0 comments on commit c5e4f87

Please sign in to comment.