world_of_cow/ui.c

47 lines
1.5 KiB
C
Raw Normal View History

2023-07-05 08:37:27 +00:00
#include "ui.h"
#include "vec.h"
#include <GL/freeglut_std.h>
#include <GL/freeglut_ext.h>
#include <GL/glut.h>
#include <GL/gl.h>
#include <stdio.h>
void ui_button_draw(ui_button* b) {
printf("drawing button %p\n", b);
int wWidth = glutGet(GLUT_WINDOW_WIDTH);
int wHeight = glutGet(GLUT_WINDOW_HEIGHT);
vec3 pos = vec3_add(b->position.absolute, vec3_new(b->position.relative.x * wWidth, b->position.relative.y * wHeight, 0.0));
vec3 ext = b->size;
glColor3f(1.0, 1.0, 1.0);
glBegin(GL_QUADS);
glVertexVec(pos);
glVertex3f(pos.x + ext.x, pos.y, pos.z);
glVertexVec(vec3_add(pos, ext));
glVertex3f(pos.x, pos.y + ext.y, pos.z);
glEnd();
// Draw text if needed
if(b->text != NULL) {
glColor3f(0.0, 0.0, 0.0);
// Get text size
int textWidth = glutBitmapLength(GLUT_BITMAP_TIMES_ROMAN_24, (unsigned char*)b->text);
int textHeight = glutBitmapHeight(GLUT_BITMAP_TIMES_ROMAN_24);
// set raster position - not gonna take into account multiple line text buttons
vec3 rPos = vec3_add(pos, vec3_mult(ext, 0.5));
rPos.x -= textWidth * 0.5;
rPos.y -= textHeight * 0.25;
glRasterPos3f(rPos.x, rPos.y, rPos.z);
glutBitmapString(GLUT_BITMAP_TIMES_ROMAN_24, (unsigned char*)b->text);
}
}
char ui_button_mouse_over(ui_button* b) {
return 0;
}
void ui_slider_draw(ui_slider* s) {
}
char ui_slider_mouse_over(ui_slider* s) {
return 0;
}