Skip to content
This repository has been archived by the owner on Nov 5, 2020. It is now read-only.

Commit

Permalink
Shortened typedefs. e.g. int8 became i8.
Browse files Browse the repository at this point in the history
  • Loading branch information
Apoorva committed Dec 29, 2016
1 parent e7f036c commit d81810f
Show file tree
Hide file tree
Showing 18 changed files with 214 additions and 219 deletions.
92 changes: 46 additions & 46 deletions src/ui/common_ui.cpp

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions src/ui/components/color_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void color_panel_set_color(Color col, ColorPanel* c, bool set_new_color_only)

// TODO: Remove the last param
void update_color_panel(ColorPanel* c, Color* colors, Mouse& mouse,
uint32 blank_texture, Layout& layout)
u32 blank_texture, Layout& layout)
{
// Picker panel
{
Expand Down Expand Up @@ -137,26 +137,26 @@ void update_color_panel(ColorPanel* c, Color* colors, Mouse& mouse,
{
ImGui::BeginChild("HSV Gradients", Vec2(315, 258));
ImGui::EndChild();
int32 rgbColor[3];
rgbColor[0] = (int32)(c->new_color.r * 255.0f);
rgbColor[1] = (int32)(c->new_color.g * 255.0f);
rgbColor[2] = (int32)(c->new_color.b * 255.0f);
i32 rgbColor[3];
rgbColor[0] = (i32)(c->new_color.r * 255.0f);
rgbColor[1] = (i32)(c->new_color.g * 255.0f);
rgbColor[2] = (i32)(c->new_color.b * 255.0f);
if (ImGui::InputInt3("RGB", rgbColor)) {
int32 r = math::clamp(rgbColor[0], 0, 255);
int32 g = math::clamp(rgbColor[1], 0, 255);
int32 b = math::clamp(rgbColor[2], 0, 255);
i32 r = math::clamp(rgbColor[0], 0, 255);
i32 g = math::clamp(rgbColor[1], 0, 255);
i32 b = math::clamp(rgbColor[2], 0, 255);
c->new_color = Color(r, g, b);
rgb_to_hsv(c->new_color, &c->cursor_h, &c->cursor_sv.x,
&c->cursor_sv.y);
}
char hexColor[6 + 1]; // null-terminated
snprintf(hexColor, sizeof(hexColor), "%02x%02x%02x",
(int32)(c->new_color.r * 255.0f),
(int32)(c->new_color.g * 255.0f),
(int32)(c->new_color.b * 255.0f));
(i32)(c->new_color.r * 255.0f),
(i32)(c->new_color.g * 255.0f),
(i32)(c->new_color.b * 255.0f));
if (ImGui::InputText("Hex", hexColor, sizeof(hexColor),
ImGuiInputTextFlags_CharsHexadecimal)) {
int32 r = 0, g = 0, b = 0;
i32 r = 0, g = 0, b = 0;
switch (strlen(hexColor)) {
case 1: sscanf(hexColor, "%1x", &b); break;
case 2: sscanf(hexColor, "%2x", &b); break;
Expand Down
2 changes: 1 addition & 1 deletion src/ui/components/color_panel.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ void destroy_color_panel(ColorPanel* c);
void color_panel_set_color(Color col, ColorPanel* c,
bool set_new_color_only = false);
void update_color_panel(ColorPanel* c, Color* colors, Mouse& mouse,
uint32 blank_texture, Layout& layout);
u32 blank_texture, Layout& layout);
26 changes: 13 additions & 13 deletions src/ui/components/crop_rotate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void crop_rotate::toolbar(PapayaMemory* mem)

// Swap render texture and document texture handles
if (size_changed) {
int32 temp = mem->cur_doc->width;
i32 temp = mem->cur_doc->width;
mem->cur_doc->width = mem->cur_doc->height;
mem->cur_doc->height = temp;

Expand Down Expand Up @@ -95,23 +95,23 @@ void crop_rotate::toolbar(PapayaMemory* mem)
GLCHK( glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) );
GLCHK( glDrawArrays (GL_TRIANGLES, 0, 6) );

uint32 temp = mem->misc.fbo_sample_tex;
u32 temp = mem->misc.fbo_sample_tex;
mem->misc.fbo_sample_tex = mem->cur_doc->final_node->tex_id;
mem->cur_doc->final_node->tex_id = temp;

if (size_changed) {
core::resize_doc(mem, mem->cur_doc->width, mem->cur_doc->height);

// Reposition canvas to maintain apparent position
int32 delta = math::round_to_int((mem->cur_doc->height - mem->cur_doc->width)
i32 delta = math::round_to_int((mem->cur_doc->height - mem->cur_doc->width)
* 0.5f * mem->cur_doc->canvas_zoom);
mem->cur_doc->canvas_pos.x += delta;
mem->cur_doc->canvas_pos.y -= delta;
}

// Reset stuff
GLCHK( glBindFramebuffer(GL_FRAMEBUFFER, 0) );
GLCHK( glViewport(0, 0, (int32)ImGui::GetIO().DisplaySize.x, (int32)ImGui::GetIO().DisplaySize.y) );
GLCHK( glViewport(0, 0, (i32)ImGui::GetIO().DisplaySize.x, (i32)ImGui::GetIO().DisplaySize.y) );

mem->crop_rotate.slider_angle = 0.f;
mem->crop_rotate.base_rotation = 0;
Expand Down Expand Up @@ -143,9 +143,9 @@ void crop_rotate::crop_outline(PapayaMemory* mem)
// Vertex selection
{
float min_dist = FLT_MAX;
int32 min_index;
i32 min_index;

for (int32 i = 0; i < 4; i++) {
for (i32 i = 0; i < 4; i++) {
float dist = math::distance(p[i], mouse);
if (min_dist > dist) {
min_dist = dist;
Expand All @@ -162,10 +162,10 @@ void crop_rotate::crop_outline(PapayaMemory* mem)
// Edge selecton
{
float min_dist = FLT_MAX;
int32 min_index;
i32 min_index;

for (int32 i = 0; i < 4; i++) {
int32 j = (i + 1) % 4;
for (i32 i = 0; i < 4; i++) {
i32 j = (i + 1) % 4;
vec2 v1 = { p[i].x , p[i].y };
vec2 v2 = { p[j].x , p[j].y };
vec2 m = { mouse.x , mouse.y };
Expand Down Expand Up @@ -277,10 +277,10 @@ void crop_rotate::crop_outline(PapayaMemory* mem)
verts[2].uv = Vec2(1.0f, 1.0f);
verts[3].uv = Vec2(1.0f, 0.0f);

uint32 col1 = 0xffcc7a00;
uint32 col2 = 0xff1189e6;
uint32 col3 = 0xff36bb0a;
uint8 Mode = mem->crop_rotate.crop_mode;
u32 col1 = 0xffcc7a00;
u32 col2 = 0xff1189e6;
u32 col3 = 0xff36bb0a;
u8 Mode = mem->crop_rotate.crop_mode;
if (Mode == 15) {
verts[0].col = verts[1].col = verts[2].col = verts[3].col = col3;
}
Expand Down
4 changes: 2 additions & 2 deletions src/ui/components/crop_rotate.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ struct Mouse;
struct PapayaMemory; // TODO: Remove. Manage struct knowledge on a need-to-know-basis.

struct CropRotate {
int32 base_rotation; // Multiply this by 90 to get the rotation in degrees
i32 base_rotation; // Multiply this by 90 to get the rotation in degrees
float slider_angle;
Vec2 top_left;
Vec2 bot_right;
Expand All @@ -17,7 +17,7 @@ struct CropRotate {
// 1 Vertex active -> Vertex drag
// 2 Vertices active -> Edge drag
// 4 Vertices active -> Full rect drag
uint8 crop_mode;
u8 crop_mode;
Vec2 rect_drag_position;
};

Expand Down
2 changes: 1 addition & 1 deletion src/ui/components/metrics_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void metrics_window::update(PapayaMemory* mem)
ImGui::Text("Millisecs"); ImGui::NextColumn();
ImGui::Separator();

for (int32 i = 0; i < Timer_COUNT; i++) {
for (i32 i = 0; i < Timer_COUNT; i++) {
ImGui::Text("%s", get_timer_name(i)); ImGui::NextColumn();
ImGui::Text("%" PRIu64,
timers[i].elapsed_cycles); ImGui::NextColumn();
Expand Down
2 changes: 1 addition & 1 deletion src/ui/components/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "ui.h"
#include "libs/gl_util.h"

Node* node::init(const char* name, Vec2 pos, uint8* img, PapayaMemory* mem)
Node* node::init(const char* name, Vec2 pos, u8* img, PapayaMemory* mem)
{
Node* n = (Node*)malloc(sizeof(*n));
n->id = mem->cur_doc->next_node_id++;
Expand Down
6 changes: 3 additions & 3 deletions src/ui/components/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ enum NodeType_ {
};

struct Node {
int64 id;
i64 id;
NodeType_ type;
char name[32];
bool is_active;
Expand All @@ -20,7 +20,7 @@ struct Node {
int inputs_count, outputs_count;
Vec2 pos, size;

uint32 tex_id;
u32 tex_id;

// TODO: Change these member functions to C-style functions
Vec2 GetInputSlotPos(int slot_no) const {
Expand Down Expand Up @@ -48,7 +48,7 @@ struct NodeLink {
};

namespace node {
Node* init(const char* name, Vec2 pos, uint8* img, PapayaMemory* mem);
Node* init(const char* name, Vec2 pos, u8* img, PapayaMemory* mem);
void destroy(Node* node);
void connect(Node* from, Node* to, PapayaMemory* mem);
}
8 changes: 4 additions & 4 deletions src/ui/components/prefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ void prefs::show_panel(ColorPanel* color_panel, Color* colors, Layout& layout)
"Image size preview color 2"
};

for (int32 i = PapayaCol_Clear; i <= PapayaCol_ImageSizePreview2; i++) {
for (i32 i = PapayaCol_Clear; i <= PapayaCol_ImageSizePreview2; i++) {
char str[8];
Color col = colors[i];
snprintf(str, 8, "#%02x%02x%02x",
(uint32)(col.r * 255.0),
(uint32)(col.g * 255.0),
(uint32)(col.b * 255.0));
(u32)(col.r * 255.0),
(u32)(col.g * 255.0),
(u32)(col.b * 255.0));

ImGui::PushStyleColor(ImGuiCol_Button, col);
ImGui::PushStyleColor(ImGuiCol_ButtonActive, col);
Expand Down
56 changes: 28 additions & 28 deletions src/ui/components/undo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void undo::init(PapayaMemory* mem)
Vec2i(0,0), Vec2i(mem->cur_doc->width, mem->cur_doc->height),
0, Vec2());

// uint32 temp = mem->misc.fbo_render_tex;
// u32 temp = mem->misc.fbo_render_tex;
// mem->misc.fbo_render_tex = mem->cur_doc->texture_id;
GLCHK( glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
GL_TEXTURE_2D, mem->misc.fbo_render_tex,
Expand All @@ -68,23 +68,23 @@ void undo::destroy(PapayaMemory* mem)
// This function reads from the frame buffer and hence needs the appropriate frame buffer to be
// bound before it is called.
void undo::push(UndoBuffer* undo, Profile* profile, Vec2i pos, Vec2i size,
int8* pre_brush_img, Vec2 line_segment_start_uv)
i8* pre_brush_img, Vec2 line_segment_start_uv)
{
if (undo->top == 0) {
// Buffer is empty
undo->base = (UndoData*)undo->start;
undo->top = undo->start;
} else if (undo->current->next != 0) {
// Not empty and not at end. Reposition for overwrite.
uint64 bytes_to_right =
(int8*)undo->start + undo->size - (int8*)undo->current;
uint64 img_size = (undo->current->IsSubRect ? 8 : 4) *
u64 bytes_to_right =
(i8*)undo->start + undo->size - (i8*)undo->current;
u64 img_size = (undo->current->IsSubRect ? 8 : 4) *
undo->current->size.x * undo->current->size.y;
uint64 block_size = sizeof(UndoData) + img_size;
u64 block_size = sizeof(UndoData) + img_size;
if (bytes_to_right >= block_size) {
undo->top = (int8*)undo->current + block_size;
undo->top = (i8*)undo->current + block_size;
} else {
undo->top = (int8*)undo->start + block_size - bytes_to_right;
undo->top = (i8*)undo->start + block_size - bytes_to_right;
}
undo->last = undo->current;
undo->count = undo->current_index + 1;
Expand All @@ -98,25 +98,25 @@ void undo::push(UndoBuffer* undo, Profile* profile, Vec2i pos, Vec2i size,
data.IsSubRect = (pre_brush_img != 0);
data.line_segment_start_uv = line_segment_start_uv;

uint64 buf_size = sizeof(UndoData) +
u64 buf_size = sizeof(UndoData) +
size.x * size.y * (data.IsSubRect ? 8 : 4);
void* buf = malloc((size_t)buf_size);

timer::start(Timer_GetUndoImage);
memcpy(buf, &data, sizeof(UndoData));
GLCHK( glReadPixels(pos.x, pos.y, size.x, size.y, GL_RGBA, GL_UNSIGNED_BYTE, (int8*)buf + sizeof(UndoData)) );
GLCHK( glReadPixels(pos.x, pos.y, size.x, size.y, GL_RGBA, GL_UNSIGNED_BYTE, (i8*)buf + sizeof(UndoData)) );
timer::stop(Timer_GetUndoImage);

if (data.IsSubRect) {
memcpy((int8*)buf + sizeof(UndoData) + 4 * size.x * size.y, pre_brush_img, 4 * size.x * size.y);
memcpy((i8*)buf + sizeof(UndoData) + 4 * size.x * size.y, pre_brush_img, 4 * size.x * size.y);
}

uint64 bytes_to_right = (int8*)undo->start + undo->size - (int8*)undo->top;
u64 bytes_to_right = (i8*)undo->start + undo->size - (i8*)undo->top;
if (bytes_to_right < sizeof(UndoData)) // Not enough space for UndoData. Go to start.
{
// Reposition the base pointer
while (((int8*)undo->base >= (int8*)undo->top ||
(int8*)undo->base < (int8*)undo->start + buf_size) &&
while (((i8*)undo->base >= (i8*)undo->top ||
(i8*)undo->base < (i8*)undo->start + buf_size) &&
undo->count > 0)
{
undo->base = undo->base->next;
Expand All @@ -130,13 +130,13 @@ void undo::push(UndoBuffer* undo, Profile* profile, Vec2i pos, Vec2i size,

if (undo->last) { undo->last->next = (UndoData*)undo->top; }
undo->last = (UndoData*)undo->top;
undo->top = (int8*)undo->top + buf_size;
undo->top = (i8*)undo->top + buf_size;
}
else if (bytes_to_right < buf_size) // Enough space for UndoData, but not for image. Split image data.
{
// Reposition the base pointer
while (((int8*)undo->base >= (int8*)undo->top ||
(int8*)undo->base < (int8*)undo->start + buf_size - bytes_to_right) &&
while (((i8*)undo->base >= (i8*)undo->top ||
(i8*)undo->base < (i8*)undo->start + buf_size - bytes_to_right) &&
undo->count > 0)
{
undo->base = undo->base->next;
Expand All @@ -146,19 +146,19 @@ void undo::push(UndoBuffer* undo, Profile* profile, Vec2i pos, Vec2i size,
}

memcpy(undo->top, buf, (size_t)bytes_to_right);
memcpy(undo->start, (int8*)buf + bytes_to_right, (size_t)(buf_size - bytes_to_right));
memcpy(undo->start, (i8*)buf + bytes_to_right, (size_t)(buf_size - bytes_to_right));

if (bytes_to_right == 0) { undo->top = undo->start; }

if (undo->last) { undo->last->next = (UndoData*)undo->top; }
undo->last = (UndoData*)undo->top;
undo->top = (int8*)undo->start + buf_size - bytes_to_right;
undo->top = (i8*)undo->start + buf_size - bytes_to_right;
}
else // Enough space for everything. Simply append.
{
// Reposition the base pointer
while ((int8*)undo->base >= (int8*)undo->top &&
(int8*)undo->base < (int8*)undo->top + buf_size &&
while ((i8*)undo->base >= (i8*)undo->top &&
(i8*)undo->base < (i8*)undo->top + buf_size &&
undo->count > 0)
{
undo->base = undo->base->next;
Expand All @@ -171,7 +171,7 @@ void undo::push(UndoBuffer* undo, Profile* profile, Vec2i pos, Vec2i size,

if (undo->last) { undo->last->next = (UndoData*)undo->top; }
undo->last = (UndoData*)undo->top;
undo->top = (int8*)undo->top + buf_size;
undo->top = (i8*)undo->top + buf_size;
}

free(buf);
Expand All @@ -185,25 +185,25 @@ void undo::pop(PapayaMemory* mem, bool load_pre_brush_image)
{
UndoBuffer* undo = &mem->cur_doc->undo;
UndoData data = {};
int8* img = 0;
i8* img = 0;
bool alloc_used = false;

memcpy(&data, undo->current, sizeof(UndoData));

size_t bytes_to_right = (int8*)undo->start + undo->size - (int8*)undo->current;
size_t bytes_to_right = (i8*)undo->start + undo->size - (i8*)undo->current;
size_t img_size =
(undo->current->IsSubRect ? 8 : 4) * data.size.x * data.size.y;
if (bytes_to_right - sizeof(UndoData) >= img_size) {
// Image is contiguously stored
img = (int8*)undo->current + sizeof(UndoData);
img = (i8*)undo->current + sizeof(UndoData);
} else {
// Image is split
alloc_used = true;
img = (int8*)malloc(img_size);
img = (i8*)malloc(img_size);
memcpy(img,
(int8*)undo->current + sizeof(UndoData),
(i8*)undo->current + sizeof(UndoData),
(size_t)bytes_to_right - sizeof(UndoData));
memcpy((int8*)img + bytes_to_right - sizeof(UndoData),
memcpy((i8*)img + bytes_to_right - sizeof(UndoData),
undo->start,
(size_t)(img_size - (bytes_to_right - sizeof(UndoData))));
}
Expand Down
6 changes: 3 additions & 3 deletions src/ui/components/undo.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ enum PapayaUndoOp_ {

struct UndoData {
// TODO: Convert into a union of structs once multiple types of undo ops are required
uint8 op_code; // Stores enum of type PapayaUndoOp_
u8 op_code; // Stores enum of type PapayaUndoOp_
UndoData* prev, *next;
Vec2i pos, size; // Position and size of the suffixed data block
bool IsSubRect; // If true, then the suffixed image data contains two subrects - before and after the brush
Expand All @@ -21,7 +21,7 @@ struct UndoData {
};

struct UndoBuffer {
void* start; // Pointer to beginning of undo buffer memory block // TODO: Change pointer types to int8*?
void* start; // Pointer to beginning of undo buffer memory block // TODO: Change pointer types to i8*?
void* top; // Pointer to the top of the undo stack
UndoData* base; // Pointer to the base of the undo stack
UndoData* current; // Pointer to the current location in the undo stack. Goes back and forth during undo-redo.
Expand All @@ -35,7 +35,7 @@ namespace undo {
void init(PapayaMemory* mem);
void destroy(PapayaMemory* mem);
void push(UndoBuffer* undo, Profile* profile, Vec2i pos, Vec2i size,
int8* pre_brush_img, Vec2 line_segment_start_uv);
i8* pre_brush_img, Vec2 line_segment_start_uv);
void pop(PapayaMemory* mem, bool load_pre_brush_image);
}

Loading

0 comments on commit d81810f

Please sign in to comment.