Mir
tooltip.c

A simple orange client surface with a simple grey tooltip

/*
*
* Copyright © 2015 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Author: Alan Griffiths <alan@octopull.co.uk>
*/
#include "eglapp.h"
#include <stdio.h>
#include <unistd.h>
#include <GLES2/gl2.h>
static MirPixelFormat select_pixel_format(MirConnection* connection);
static MirWindow* create_tooltip(MirConnection* const connection, MirWindow* const parent, const MirPixelFormat format);
typedef struct Color
{
GLfloat r, g, b, a;
int main(int argc, char *argv[])
{
float const opacity = mir_eglapp_background_opacity;
Color const orange = {0.866666667f, 0.282352941f, 0.141414141f, opacity};
unsigned int width = 300, height = 200;
if (!mir_eglapp_init(argc, argv, &width, &height, NULL))
return 1;
glClearColor(orange.r, orange.g, orange.b, orange.a);
glClear(GL_COLOR_BUFFER_BIT);
MirWindowSpec* const spec = mir_create_window_spec(connection);
mir_window_spec_set_name(spec, "tooltip example");
mir_window_apply_spec(parent, spec);
MirWindow* tooltip = create_tooltip(connection, parent, select_pixel_format(connection));
{
}
return 0;
}
static MirPixelFormat select_pixel_format(MirConnection* connection)
{
unsigned int format[mir_pixel_formats];
unsigned int nformats;
format, mir_pixel_formats, &nformats);
for (unsigned int f = 0; f < nformats; f++)
{
const bool opaque = (format[f] == mir_pixel_format_xbgr_8888 ||
format[f] == mir_pixel_format_bgr_888);
if (opaque)
{
pixel_format = format[f];
break;
}
}
return pixel_format;
}
static MirWindow* create_tooltip(MirConnection* const connection, MirWindow* const parent, const MirPixelFormat format)
{
MirRectangle zone = { 0, 0, 10, 10 };
int const width = 50;
int const height = 20;
connection, width, height, parent, &zone, mir_edge_attachment_vertical);
mir_window_spec_set_name(spec, "tooltip");
for (int y = 0; y != buffer.height; ++y)
{
for (int n = 0; n != buffer.width; ++n)
switch (format)
{
{
uint32_t* const pixel = (uint32_t*) (buffer.vaddr + y * buffer.stride);
pixel[n] = 0xff7f7f7f;
break;
}
{
uint32_t* const pixel = (uint32_t*) (buffer.vaddr + y * buffer.stride);
pixel[n] = 0x007f7f7f;
break;
}
{
uint8_t* const subpixel = (uint8_t*) (buffer.vaddr + y * buffer.stride);
subpixel[3 * n + 0] = 0x7f;
subpixel[3 * n + 1] = 0x7f;
subpixel[3 * n + 2] = 0x7f;
break;
}
default:
break;
}
}
return tooltip;
}

Copyright © 2012-2016 Canonical Ltd.
Generated on Mon Jun 5 13:49:26 UTC 2017