shithub: tinygl

Download patch

ref: 5a88e8bfa1dca4da516339f409bc35e5df7c824e
parent: ff66214c382e9fec0834eb4282a874f4a31f31f1
author: MHS <gek@katherine>
date: Mon Mar 15 11:33:34 EDT 2021

Automatic commit.

--- a/SDL_Examples/menu.c
+++ b/SDL_Examples/menu.c
@@ -148,8 +148,11 @@
 	return omg_box_retval(x, y, xdim, ydim);
 }
 
-int haveclicked = 0;
+int haveclicked = 0; //For our toggleable movable button.
 vec3 tbcoords = (vec3){{0.4,0.4,0}};
+vec3 slidcoords = (vec3){{0.1,0.8,0}};
+float slidmoffset = 0;
+int slidersliding = 0; //Is the slider being slid?
 void draw() {
 	if(mb2){
 		tbcoords.d[0] = omg_cursorpos[0];
@@ -169,6 +172,33 @@
 	if(
 	omg_textbox(tbcoords.d[0], tbcoords.d[1], "\nClick me and I toggle color!\n", 16, 1, 0.4, 0.3, 0xFFFFFF, haveclicked?0xFF0000:0x00) && omg_cb == 1)
 		{puts("Detected click! EVENT FIRED!\n");haveclicked = !haveclicked; }
+	//A slider element
+	if(
+		omg_textbox(slidcoords.d[0], slidcoords.d[1], "Slider", 16, 1, 0.4, 0.3, 0xFFFFFF, haveclicked?0xFF0000:0x00) 
+		&& omg_cb ==1
+	){
+			slidersliding = 1;
+			slidmoffset = omg_cursorpos[0] - slidcoords.d[0];
+	}
+	if(omg_cb == 2)
+				slidersliding = 0;
+	//Handle the slider sliding behavior.
+	if(slidersliding){
+		if(using_cursorkeys){
+			if(omg_udlr[3]){
+				slidcoords.d[0] = clampf(slidcoords.d[0] + 0.05,0.1,0.7);
+			}
+			if(omg_udlr[2]){
+				slidcoords.d[0] = clampf(slidcoords.d[0] - 0.05,0.1,0.7);
+			}
+			omg_cursorpos[0] = slidcoords.d[0] + slidmoffset;
+			omg_cursorpos[1] = slidcoords.d[1];
+		} else {
+			//Move the element to the cursorposition's x.
+			slidcoords.d[0] = clampf(omg_cursorpos[0]- slidmoffset,0.1,0.7);
+		}
+		printf("Slider's value is %f\n", slidcoords.d[0]);
+	}
 	drawMouse();
 }
 
--- a/include-demo/openimgui.h
+++ b/include-demo/openimgui.h
@@ -71,9 +71,9 @@
 extern int omg_cursor_was_inside;  //Set 
 extern float omg_buttonjump[2]; //Defaults to zero
 // Setting for users using 
-extern int bstate_old;
-extern int udlr_old[4];
-
+extern int omg_bstate_old;
+extern int omg_udlr_old[4];
+extern int omg_udlr[4];
 // cursor button
 extern int omg_cb; //Set to zero every iteration.
 #else
@@ -83,8 +83,9 @@
 int omg_cursor_was_inside;  //Set 
 float omg_buttonjump[2]; //Defaults to zero
 // Setting for users using 
-int bstate_old = 0;
-int udlr_old[4] = {0,0,0,0};
+int omg_bstate_old = 0;
+int omg_udlr_old[4] = {0,0,0,0};
+int omg_udlr[4];
 // cursor button
 int omg_cb; //Set to zero every iteration.
 #endif
@@ -106,14 +107,18 @@
 static inline void omg_update_keycursor(int _up, int _down, int _left, int _right, int bstate){
 	
 	omg_cursor_was_inside = 0;
-	int up = _up && ! udlr_old[0];
-	int down = _down && ! udlr_old[1];
-	int left = _left && ! udlr_old[2];
-	int right = _right && ! udlr_old[3];
-	udlr_old[0] = _up;
-	udlr_old[1] = _down;
-	udlr_old[2] = _left;
-	udlr_old[3] = _right;
+	int up = _up && ! omg_udlr_old[0];
+	int down = _down && ! omg_udlr_old[1];
+	int left = _left && ! omg_udlr_old[2];
+	int right = _right && ! omg_udlr_old[3];
+	omg_udlr[0] = up;
+	omg_udlr[1] = down;
+	omg_udlr[2] = left;
+	omg_udlr[3] = right;
+	omg_udlr_old[0] = _up;
+	omg_udlr_old[1] = _down;
+	omg_udlr_old[2] = _left;
+	omg_udlr_old[3] = _right;
 	omg_cursor_has_been_sucked = 0;
 	omg_cursorpos_presuck[0] = omg_cursorpos[0];
 	omg_cursorpos_presuck[1] = omg_cursorpos[1];
@@ -129,9 +134,9 @@
 	omg_cursorpos_presuck[1] = omg_cursorpos[1];
 	//printf("BEGIN! Cx = %f, Cy = %f\n", omg_cursorpos[0], omg_cursorpos[1]);
 	omg_cb = 0; 
-	if(bstate && !bstate_old) omg_cb = 1;
-	else if (!bstate && bstate_old) omg_cb = 2;
-	bstate_old = bstate;
+	if(bstate && !omg_bstate_old) omg_cb = 1;
+	else if (!bstate && omg_bstate_old) omg_cb = 2;
+	omg_bstate_old = bstate;
 }
 
 //for mouse cursors and touch input.
@@ -147,9 +152,9 @@
 	omg_cursorpos_presuck[1] = -1;
 
 	omg_cb = 0; 
-	if(bstate && !bstate_old) omg_cb = 1;
-	else if (!bstate && bstate_old) omg_cb = 2;
-	bstate_old = bstate;
+	if(bstate && !omg_bstate_old) omg_cb = 1;
+	else if (!bstate && omg_bstate_old) omg_cb = 2;
+	omg_bstate_old = bstate;
 }
 static inline int omg_boxtest(float x, float y, float xdim, float ydim, float cx, float cy){
 	if((x <= cx) &&