code stringlengths 1 2.01M | repo_name stringlengths 3 62 | path stringlengths 1 267 | language stringclasses 231 values | license stringclasses 13 values | size int64 1 2.01M |
|---|---|---|---|---|---|
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Datepicker - Default functionality</title>
<link rel="stylesheet" href="../../themes/base/jquery.ui.all.css">
<script src="../../jquery-1.8.2.js"></script>
<script src="../../ui/jquery.ui.core.js"></script>
<script src="../../ui/jquery.ui.widget.js"></script>
<script src="../../ui/jquery.ui.datepicker.js"></script>
<link rel="stylesheet" href="../demos.css">
<script>
$(function() {
$( "#datepicker" ).datepicker();
});
</script>
</head>
<body>
<p>Date: <input type="text" id="datepicker"></p>
<div class="demo-description">
<p>The datepicker is tied to a standard form input field. Focus on the input (click, or use the tab key) to open an interactive calendar in a small overlay. Choose a date, click elsewhere on the page (blur the input), or hit the Esc key to close. If a date is chosen, feedback is shown as the input's value.</p>
</div>
</body>
</html>
| 10bit1-group02-pmproject | trunk/Temp_Source/WUC/jquery-ui-1.9.1.custom/development-bundle/demos/datepicker/default.html | HTML | bsd | 960 |
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Datepicker - Show week of the year</title>
<link rel="stylesheet" href="../../themes/base/jquery.ui.all.css">
<script src="../../jquery-1.8.2.js"></script>
<script src="../../ui/jquery.ui.core.js"></script>
<script src="../../ui/jquery.ui.widget.js"></script>
<script src="../../ui/jquery.ui.datepicker.js"></script>
<link rel="stylesheet" href="../demos.css">
<script>
$(function() {
$( "#datepicker" ).datepicker({
showWeek: true,
firstDay: 1
});
});
</script>
</head>
<body>
<p>Date: <input type="text" id="datepicker"></p>
<div class="demo-description">
<p>The datepicker can show the week of the year. The default calculation follows
the ISO 8601 definition: the week starts on Monday, the first week of the year
contains the first Thursday of the year. This means that some days from one
year may be placed into weeks 'belonging' to another year.</p>
</div>
</body>
</html>
| 10bit1-group02-pmproject | trunk/Temp_Source/WUC/jquery-ui-1.9.1.custom/development-bundle/demos/datepicker/show-week.html | HTML | bsd | 987 |
module.exports = function( grunt ) {
"use strict";
var
// files
coreFiles = [
"jquery.ui.core.js",
"jquery.ui.widget.js",
"jquery.ui.mouse.js",
"jquery.ui.draggable.js",
"jquery.ui.droppable.js",
"jquery.ui.resizable.js",
"jquery.ui.selectable.js",
"jquery.ui.sortable.js",
"jquery.ui.effect.js"
],
uiFiles = coreFiles.map(function( file ) {
return "ui/" + file;
}).concat( grunt.file.expandFiles( "ui/*.js" ).filter(function( file ) {
return coreFiles.indexOf( file.substring(3) ) === -1;
})),
allI18nFiles = grunt.file.expandFiles( "ui/i18n/*.js" ),
cssFiles = [
"core",
"accordion",
"autocomplete",
"button",
"datepicker",
"dialog",
"menu",
"progressbar",
"resizable",
"selectable",
"slider",
"spinner",
"tabs",
"tooltip",
"theme"
].map(function( component ) {
return "themes/base/jquery.ui." + component + ".css";
}),
// minified files
minify = {
"dist/jquery-ui.min.js": [ "<banner:meta.bannerAll>", "dist/jquery-ui.js" ],
"dist/i18n/jquery-ui-i18n.min.js": [ "<banner:meta.bannerI18n>", "dist/i18n/jquery-ui-i18n.js" ]
},
minifyCSS = {
"dist/jquery-ui.min.css": "dist/jquery-ui.css"
},
compareFiles = {
all: [
"dist/jquery-ui.js",
"dist/jquery-ui.min.js"
]
};
function mapMinFile( file ) {
return "dist/" + file.replace( /\.js$/, ".min.js" ).replace( /ui\//, "minified/" );
}
uiFiles.concat( allI18nFiles ).forEach(function( file ) {
minify[ mapMinFile( file ) ] = [ "<banner>", file ];
});
cssFiles.forEach(function( file ) {
minifyCSS[ "dist/" + file.replace( /\.css$/, ".min.css" ).replace( /themes\/base\//, "themes/base/minified/" ) ] = [ "<banner>", "<strip_all_banners:" + file + ">" ];
});
uiFiles.forEach(function( file ) {
compareFiles[ file ] = [ file, mapMinFile( file ) ];
});
// grunt plugins
grunt.loadNpmTasks( "grunt-css" );
grunt.loadNpmTasks( "grunt-html" );
grunt.loadNpmTasks( "grunt-compare-size" );
grunt.loadNpmTasks( "grunt-junit" );
grunt.loadNpmTasks( "grunt-git-authors" );
// local testswarm and build tasks
grunt.loadTasks( "build/tasks" );
grunt.registerHelper( "strip_all_banners", function( filepath ) {
return grunt.file.read( filepath ).replace( /^\s*\/\*[\s\S]*?\*\/\s*/g, "" );
});
function stripBanner( files ) {
return files.map(function( file ) {
return "<strip_all_banners:" + file + ">";
});
}
function stripDirectory( file ) {
// TODO: we're receiving the directive, so we need to strip the trailing >
// we should be receving a clean path without the directive
return file.replace( /.+\/(.+?)>?$/, "$1" );
}
// allow access from banner template
global.stripDirectory = stripDirectory;
function createBanner( files ) {
// strip folders
var fileNames = files && files.map( stripDirectory );
return "/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - " +
"<%= grunt.template.today('isoDate') %>\n" +
"<%= pkg.homepage ? '* ' + pkg.homepage + '\n' : '' %>" +
"* Includes: " + (files ? fileNames.join(", ") : "<%= stripDirectory(grunt.task.current.file.src[1]) %>") + "\n" +
"* Copyright <%= grunt.template.today('yyyy') %> <%= pkg.author.name %>;" +
" Licensed <%= _.pluck(pkg.licenses, 'type').join(', ') %> */";
}
grunt.initConfig({
pkg: "<json:package.json>",
files: {
dist: "<%= pkg.name %>-<%= pkg.version %>",
cdn: "<%= pkg.name %>-<%= pkg.version %>-cdn",
themes: "<%= pkg.name %>-themes-<%= pkg.version %>"
},
meta: {
banner: createBanner(),
bannerAll: createBanner( uiFiles ),
bannerI18n: createBanner( allI18nFiles ),
bannerCSS: createBanner( cssFiles )
},
compare_size: compareFiles,
concat: {
ui: {
src: [ "<banner:meta.bannerAll>", stripBanner( uiFiles ) ],
dest: "dist/jquery-ui.js"
},
i18n: {
src: [ "<banner:meta.bannerI18n>", allI18nFiles ],
dest: "dist/i18n/jquery-ui-i18n.js"
},
css: {
src: [ "<banner:meta.bannerCSS>", stripBanner( cssFiles ) ],
dest: "dist/jquery-ui.css"
}
},
min: minify,
cssmin: minifyCSS,
htmllint: {
// ignore files that contain invalid html, used only for ajax content testing
all: grunt.file.expand( [ "demos/**/*.html", "tests/**/*.html" ] ).filter(function( file ) {
return !/(?:ajax\/content\d\.html|tabs\/data\/test\.html|tests\/unit\/core\/core\.html)/.test( file );
})
},
copy: {
dist: {
src: [
"AUTHORS.txt",
"jquery-*.js",
"MIT-LICENSE.txt",
"README.md",
"grunt.js",
"package.json",
"*.jquery.json",
"ui/**/*",
"ui/.jshintrc",
"demos/**/*",
"themes/**/*",
"external/**/*",
"tests/**/*"
],
renames: {
"dist/jquery-ui.js": "ui/jquery-ui.js",
"dist/jquery-ui.min.js": "ui/minified/jquery-ui.min.js",
"dist/i18n/jquery-ui-i18n.js": "ui/i18n/jquery-ui-i18n.js",
"dist/i18n/jquery-ui-i18n.min.js": "ui/minified/i18n/jquery-ui-i18n.min.js",
"dist/jquery-ui.css": "themes/base/jquery-ui.css",
"dist/jquery-ui.min.css": "themes/base/minified/jquery-ui.min.css"
},
dest: "dist/<%= files.dist %>"
},
dist_min: {
src: "dist/minified/**/*",
strip: /^dist/,
dest: "dist/<%= files.dist %>/ui"
},
dist_css_min: {
src: "dist/themes/base/minified/*.css",
strip: /^dist/,
dest: "dist/<%= files.dist %>"
},
dist_units_images: {
src: "themes/base/images/*",
strip: /^themes\/base\//,
dest: "dist/"
},
dist_min_images: {
src: "themes/base/images/*",
strip: /^themes\/base\//,
dest: "dist/<%= files.dist %>/themes/base/minified"
},
cdn: {
src: [
"AUTHORS.txt",
"MIT-LICENSE.txt",
"ui/*.js",
"package.json"
],
renames: {
"dist/jquery-ui.js": "jquery-ui.js",
"dist/jquery-ui.min.js": "jquery-ui.min.js",
"dist/i18n/jquery-ui-i18n.js": "i18n/jquery-ui-i18n.js",
"dist/i18n/jquery-ui-i18n.min.js": "i18n/jquery-ui-i18n.min.js",
"dist/jquery-ui.css": "themes/base/jquery-ui.css",
"dist/jquery-ui.min.css": "themes/base/minified/jquery-ui.min.css"
},
dest: "dist/<%= files.cdn %>"
},
cdn_i18n: {
src: "ui/i18n/jquery.ui.datepicker-*.js",
strip: "ui/",
dest: "dist/<%= files.cdn %>"
},
cdn_i18n_min: {
src: "dist/minified/i18n/jquery.ui.datepicker-*.js",
strip: "dist/minified",
dest: "dist/<%= files.cdn %>"
},
cdn_min: {
src: "dist/minified/*.js",
strip: /^dist\/minified/,
dest: "dist/<%= files.cdn %>/ui"
},
cdn_min_images: {
src: "themes/base/images/*",
strip: /^themes\/base\//,
dest: "dist/<%= files.cdn %>/themes/base/minified"
},
cdn_themes: {
src: "dist/<%= files.themes %>/themes/**/*",
strip: "dist/<%= files.themes %>",
dest: "dist/<%= files.cdn %>"
},
themes: {
src: [
"AUTHORS.txt",
"MIT-LICENSE.txt",
"package.json"
],
dest: "dist/<%= files.themes %>"
}
},
zip: {
dist: {
src: "<%= files.dist %>",
dest: "<%= files.dist %>.zip"
},
cdn: {
src: "<%= files.cdn %>",
dest: "<%= files.cdn %>.zip"
},
themes: {
src: "<%= files.themes %>",
dest: "<%= files.themes %>.zip"
}
},
md5: {
dist: {
src: "dist/<%= files.dist %>",
dest: "dist/<%= files.dist %>/MANIFEST"
},
cdn: {
src: "dist/<%= files.cdn %>",
dest: "dist/<%= files.cdn %>/MANIFEST"
},
themes: {
src: "dist/<%= files.themes %>",
dest: "dist/<%= files.themes %>/MANIFEST"
}
},
qunit: {
files: grunt.file.expandFiles( "tests/unit/**/*.html" ).filter(function( file ) {
// disabling everything that doesn't (quite) work with PhantomJS for now
// TODO except for all|index|test, try to include more as we go
return !( /(all|all-active|index|test|draggable|droppable|selectable|resizable|sortable|dialog|slider|datepicker|tabs|tabs_deprecated|tooltip)\.html$/ ).test( file );
})
},
lint: {
ui: grunt.file.expandFiles( "ui/*.js" ).filter(function( file ) {
// TODO remove items from this list once rewritten
return !( /(mouse|datepicker|draggable|droppable|resizable|selectable|sortable)\.js$/ ).test( file );
}),
grunt: [ "grunt.js", "build/**/*.js" ],
tests: "tests/unit/**/*.js"
},
csslint: {
// nothing: []
// TODO figure out what to check for, then fix and enable
base_theme: {
src: grunt.file.expandFiles( "themes/base/*.css" ).filter(function( file ) {
// TODO remove items from this list once rewritten
return !( /(button|datepicker|core|dialog|theme)\.css$/ ).test( file );
}),
// TODO consider reenabling some of these rules
rules: {
"import": false,
"important": false,
"outline-none": false,
// especially this one
"overqualified-elements": false,
"compatible-vendor-prefixes": false
}
}
},
jshint: (function() {
function parserc( path ) {
var rc = grunt.file.readJSON( (path || "") + ".jshintrc" ),
settings = {
options: rc,
globals: {}
};
(rc.predef || []).forEach(function( prop ) {
settings.globals[ prop ] = true;
});
delete rc.predef;
return settings;
}
return {
grunt: parserc(),
ui: parserc( "ui/" ),
// TODO: `evil: true` is only for document.write() https://github.com/jshint/jshint/issues/519
// TODO: don't create so many globals in tests
tests: parserc( "tests/" )
};
})()
});
grunt.registerTask( "default", "lint csslint htmllint qunit" );
grunt.registerTask( "sizer", "concat:ui min:dist/jquery-ui.min.js compare_size:all" );
grunt.registerTask( "sizer_all", "concat:ui min compare_size" );
grunt.registerTask( "build", "concat min cssmin copy:dist_units_images" );
grunt.registerTask( "release", "clean build copy:dist copy:dist_min copy:dist_min_images copy:dist_css_min md5:dist zip:dist" );
grunt.registerTask( "release_themes", "release generate_themes copy:themes md5:themes zip:themes" );
grunt.registerTask( "release_cdn", "release_themes copy:cdn copy:cdn_min copy:cdn_i18n copy:cdn_i18n_min copy:cdn_min_images copy:cdn_themes md5:cdn zip:cdn" );
};
| 10bit1-group02-pmproject | trunk/Temp_Source/WUC/jquery-ui-1.9.1.custom/development-bundle/grunt.js | JavaScript | bsd | 9,836 |
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace final
{
public partial class template : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
} | 10bit1-group02-pmproject | trunk/Temp_Source/WUC/final/template.Master.cs | C# | bsd | 333 |
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace final
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
} | 10bit1-group02-pmproject | trunk/Temp_Source/WUC/final/Post.aspx.cs | C# | bsd | 327 |
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace final
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
} | 10bit1-group02-pmproject | trunk/Temp_Source/WUC/final/Home.aspx.cs | C# | bsd | 327 |
<%@ Page Title="" Language="C#" MasterPageFile="~/template.Master" AutoEventWireup="true" CodeBehind="Home.aspx.cs" Inherits="final.WebForm1" %>
<%@ Register src="wuc/wuctinnong.ascx" tagname="wuctinnong" tagprefix="uc2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<style type="text/css">
.style18
{
width: 100%;
height: 325px;
}
.style19
{
width: 971px;
}
.style20
{
width: 971px;
height: 46px;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<table class="style18">
<tr>
<td class="style20"
style="margin-top: 15px; margin-right: 50px; margin-left: 50px; background-image: url('image/hotnews.png');">
</td>
</tr>
<tr>
<td class="style19"
style="margin-top: 15px; margin-right: 50px; margin-left: 50px; ">
<uc2:wuctinnong ID="wuctinnong1" runat="server" />
</td>
</tr>
</table>
</asp:Content>
| 10bit1-group02-pmproject | trunk/Temp_Source/WUC/final/Home.aspx | ASP.NET | bsd | 1,224 |
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("final")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("final")]
[assembly: AssemblyCopyright("Copyright © 2012")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("34328f58-f261-4789-9ef9-31608733f215")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
| 10bit1-group02-pmproject | trunk/Temp_Source/WUC/final/Properties/AssemblyInfo.cs | C# | bsd | 1,381 |
<%@ Page Title="" Language="C#" MasterPageFile="~/template.Master" AutoEventWireup="true" CodeBehind="Post.aspx.cs" Inherits="final.WebForm2" %>
<%@ Register src="wuc/wucchitietbaiviet.ascx" tagname="wucchitietbaiviet" tagprefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<uc1:wucchitietbaiviet ID="wucchitietbaiviet1" runat="server" />
</asp:Content>
| 10bit1-group02-pmproject | trunk/Temp_Source/WUC/final/Post.aspx | ASP.NET | bsd | 504 |
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="wucbinhluan.ascx.cs" Inherits="final.wuc.wucbinhluan" %>
<asp:TextBox ID="txtcomment" runat="server" TextMode="MultiLine"></asp:TextBox>
<asp:ImageButton ID="imgsubmitcomment" runat="server" Height="34px"
Width="47px" />
| 10bit1-group02-pmproject | trunk/Temp_Source/WUC/final/wuc/wucbinhluan.ascx | ASP.NET | bsd | 296 |
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BUS;
using DAO;
namespace final.wuc
{
public partial class wucdangtour : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void imgsubmit_Click(object sender, ImageClickEventArgs e)
{
TourBUS tourBus = new TourBUS();
TTOUR t_tour = new TTOUR();
t_tour.TourName = txtName.Text;
//t_tour.TourPlace = ddlDestination;
t_tour.TourTime = txtDuration.Text;
t_tour.TourPrice = txtPrice.Text;
t_tour.TourHighLights = txtHighlights.Text;
t_tour.TourCondition = autoFill(txtCondition.Text);
t_tour.TourInfo = autoFill(txtInfo.Text);
if (tourBus.addTour(t_tour))
{
Response.Redirect("~/home.aspx");
}
}
private string autoFill(string p)
{
if (p == "")
{
return "không có";
}
return p;
}
}
} | 10bit1-group02-pmproject | trunk/Temp_Source/WUC/final/wuc/wucdangtour.ascx.cs | C# | bsd | 1,233 |
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BUS;
using DAO;
namespace final.wuc
{
public partial class wucdangki : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void imgsubmit_Click(object sender, ImageClickEventArgs e)
{
UserBUS userbus = new UserBUS();
TUSER user = userbus.Getall().SingleOrDefault(n => n.Username == txtsignupuser.Text);
if (user != null)
{
lblerror.Text = "Username has exists";
txtsignupuser.Focus();
}
else
{
user = new TUSER();
user.Username = txtsignupuser.Text;
user.Pass = txtsignuppass.Text;
user.FullName = txtfullname.Text;
user.Email = txtemail.Text;
user.DoB = System.DateTime.Parse(txtdob.Text);
user.Phone = txtphone.Text;
user.Sex = rBtnSex.SelectedValue.ToString();
if (userbus.adduser(user) == true)
{
user = userbus.checkLogin(txtsignupuser.Text, txtsignuppass.Text);
Session["URLHienTai"] = Request.Url.ToString();
Session["isLogin"] = true;
Session["user"] = user;
Response.Redirect("~/test.aspx");
}
}
}
}
} | 10bit1-group02-pmproject | trunk/Temp_Source/WUC/final/wuc/wucdangki.ascx.cs | C# | bsd | 1,634 |
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="wuctinnong.ascx.cs" Inherits="final.wuc.wuctinnong" %>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1" Width="626px">
<Columns>
<asp:HyperLinkField DataTextField="ArticleName" NavigateUrl="~/Post.aspx" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:TravelConnectionString %>"
SelectCommand="SELECT [ArticleName] FROM [TARTICLE]"></asp:SqlDataSource>
| 10bit1-group02-pmproject | trunk/Temp_Source/WUC/final/wuc/wuctinnong.ascx | ASP.NET | bsd | 588 |
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAO;
using BUS;
namespace final.wuc
{
public partial class wucdangnhap : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Session["isLogin"] == null || (bool)Session["isLogin"] == false)
SetLogIn(false);
else
SetLogIn(true);
}
}
private void SetLogIn(bool p)
{
pnlLogIn.Visible = !p;
pnlLogOut.Visible = p;
if (p)
{
lblerrorlogin.Text = "";
lblusername.Text = ((TUSER)Session["User"]).Username;
}
else
{
lblerrorlogin.Text = "";
lblusername.Text = "";
}
}
protected void imglogin_Click(object sender, ImageClickEventArgs e)
{
UserBUS userBUS = new UserBUS();
TUSER user = userBUS.checkLogin(txtusername.Text, txtpassword.Text);
if (user == null)
{
lblerrorlogin.Text = "Invalid username or password";
}
else
{
Session["isLogin"] = true;
Session["user"] = user;
Response.Redirect("~/test.aspx");
}
}
protected void imglogout_Click(object sender, ImageClickEventArgs e)
{
Session["isLogin"] = false;
Session["user"] = null;
Response.Redirect("~/test.aspx");
}
}
} | 10bit1-group02-pmproject | trunk/Temp_Source/WUC/final/wuc/wucdangnhap.ascx.cs | C# | bsd | 1,801 |
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace final.wuc
{
public partial class wuctinnong : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
} | 10bit1-group02-pmproject | trunk/Temp_Source/WUC/final/wuc/wuctinnong.ascx.cs | C# | bsd | 340 |
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="wucxembaiviet.ascx.cs" Inherits="final.wuc.wucxembaiviet" %>
<style type="text/css">
.style1
{
width: 100%;
height: 237px;
}
.style2
{
height: 40px;
}
.style3
{
width: 134px;
}
</style>
<asp:GridView ID="GridView1" runat="server">
<EmptyDataTemplate>
<table class="style1">
<tr>
<td class="style2">
<asp:Label ID="lbltitle" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:Image ID="Image1" runat="server" Height="94px" Width="205px" />
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblcontent" runat="server"></asp:Label>
</td>
</tr>
</table>
</EmptyDataTemplate>
</asp:GridView>
| 10bit1-group02-pmproject | trunk/Temp_Source/WUC/final/wuc/wucxembaiviet.ascx | ASP.NET | bsd | 1,003 |
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="wucdangtour.ascx.cs" Inherits="final.wuc.wucdangtour" %>
<%@ Register src="wucupload.ascx" tagname="wucupload" tagprefix="uc1" %>
<style type="text/css">
.style1
{
width: 66%;
}
.style2
{
width: 236px;
}
.style3
{
width: 517px;
}
</style>
<table class="style1">
<tr>
<td class="style2">
Tên tour:</td>
<td class="style3">
<asp:TextBox ID="txtName" runat="server" Width="232px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
Địa điểm đến:</td>
<td class="style3">
<asp:DropDownList ID="ddlDestination" runat="server" Height="16px"
Width="232px">
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="style2">
Thời lượng</td>
<td class="style3">
<asp:TextBox ID="txtDuration" runat="server" Width="232px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
Gía tour:</td>
<td class="style3">
<asp:TextBox ID="txtPrice" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
Hình ảnh:</td>
<td class="style3">
<uc1:wucupload ID="upImage" runat="server" />
</td>
</tr>
<tr>
<td class="style2">
Điểm nổi bật:</td>
<td class="style3">
<asp:TextBox ID="txtHighlights" runat="server" Height="69px"
TextMode="MultiLine" Width="427px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
Điều kiện:</td>
<td class="style3">
<asp:TextBox ID="txtCondition" runat="server" Height="69px"
TextMode="MultiLine" Width="427px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
Thông tin khác:</td>
<td class="style3">
<asp:TextBox ID="txtInfo" runat="server" Height="101px"
TextMode="MultiLine" Width="430px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
</td>
<td class="style3">
<asp:ImageButton ID="imgsubmit" runat="server" Height="24px" Width="79px"
onclick="imgsubmit_Click" />
<asp:ImageButton ID="imgdraft" runat="server" Height="24px" Width="79px" />
</td>
</tr>
</table>
| 10bit1-group02-pmproject | trunk/Temp_Source/WUC/final/wuc/wucdangtour.ascx | ASP.NET | bsd | 2,661 |
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace final.wuc
{
public partial class wucxemtour : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
} | 10bit1-group02-pmproject | trunk/Temp_Source/WUC/final/wuc/wucxemtour.ascx.cs | C# | bsd | 340 |
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="wucxemtour.ascx.cs" Inherits="final.wuc.wucxemtour" %>
<style type="text/css">
.style1
{
width: 100%;
}
.style3
{
}
.style6
{
height: 23px;
}
.style8
{
width: 104px;
}
.style10
{
width: 69px;
}
.style11
{
width: 75px;
}
</style>
<asp:GridView ID="GridView1" runat="server">
<EmptyDataTemplate>
<table class="style1">
<tr>
<td colspan="2">
<asp:Label ID="lbltitletour" runat="server"></asp:Label>
</td>
<td>
<asp:Label ID="lbltimeposted" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td colspan="3">
</td>
</tr>
<tr>
<td class="style8" rowspan="4">
<asp:Image ID="imgtour" runat="server" Height="81px" Width="94px" />
</td>
<td class="style11">
Tour place:</td>
<td>
<asp:Label ID="lbltourplace" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td class="style11">
Tour time:</td>
<td>
<asp:Label ID="lbltourtime" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td class="style11">
Tour Price:</td>
<td>
<asp:Label ID="lbltourprice" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td class="style11">
</td>
<td>
</td>
</tr>
<tr>
<td class="style3" colspan="2">
<asp:Label ID="Label3" runat="server" Text="Điểm nổi bật"></asp:Label>
</td>
<td>
<asp:Label ID="Label4" runat="server" Text="Điều kiện"></asp:Label>
</td>
</tr>
<tr>
<td class="style6" colspan="2">
<asp:Label ID="lblhighlights" runat="server"></asp:Label>
</td>
<td class="style6">
<asp:Label ID="lblconditions" runat="server"></asp:Label>
</td>
</tr>
</table>
</EmptyDataTemplate>
</asp:GridView>
| 10bit1-group02-pmproject | trunk/Temp_Source/WUC/final/wuc/wucxemtour.ascx | ASP.NET | bsd | 2,704 |
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="wucdangnhap.ascx.cs" Inherits="final.wuc.wucdangnhap" %>
<style type="text/css">
.style1
{
width: 100%;
}
.style2
{
width: 145px;
}
.style3
{
width: 131px;
}
</style>
<asp:Panel ID="pnlLogIn" runat="server">
<table class="style1">
<tr>
<td>
Username
</td>
<td>
Password
</td>
</tr>
<tr>
<td class="style2">
<asp:TextBox ID="txtusername" runat="server" Width="141px"></asp:TextBox>
</td>
<td class="style3">
<asp:TextBox ID="txtpassword" runat="server" Width="141px" TextMode="Password"></asp:TextBox>
</td>
<td>
<asp:ImageButton ID="imglogin" runat="server" Height="16px" Width="75px"
onclick="imglogin_Click" />
</td>
</tr>
<tr>
<td class="style2">
</td>
<td class="style3">
<asp:Label ID="lblerrorlogin" runat="server" ForeColor="Red"></asp:Label>
</td>
<td>
</td>
</tr>
</table>
</asp:Panel>
<asp:Panel ID="pnlLogOut" runat="server">
<table class="style1">
<tr>
<td class="style2">
<asp:Label ID="lblusername" runat="server" Text="Label"></asp:Label>
</td>
<td class="style3">
<asp:ImageButton ID="imglogout" runat="server" onclick="imglogout_Click" />
</td>
<td>
</td>
</tr>
</table>
</asp:Panel>
| 10bit1-group02-pmproject | trunk/Temp_Source/WUC/final/wuc/wucdangnhap.ascx | ASP.NET | bsd | 1,638 |
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace final.wuc
{
public partial class wucupload : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
} | 10bit1-group02-pmproject | trunk/Temp_Source/WUC/final/wuc/wucupload.ascx.cs | C# | bsd | 339 |
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="wucdangki.ascx.cs" Inherits="final.wuc.wucdangki" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<style type="text/css">
.style1
{
width: 121%;
height: 247px;
}
.style2
{
width: 211px;
}
</style>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<table class="style1">
<tr>
<td class="style2">
Username</td>
<td>
<asp:TextBox ID="txtsignupuser" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
Password</td>
<td>
<asp:TextBox ID="txtsignuppass" runat="server" TextMode="Password"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
Email</td>
<td>
<asp:TextBox ID="txtemail" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ControlToValidate="txtEmail" ErrorMessage="Invalid Email" ForeColor="Red"
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">*</asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td class="style2">
Fullname</td>
<td>
<asp:TextBox ID="txtfullname" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
Date of Birth</td>
<td>
<asp:TextBox ID="txtdob" runat="server"></asp:TextBox>
<asp:CalendarExtender ID="CalendarExtender1" TargetControlID="txtdob" runat="server">
</asp:CalendarExtender>
</td>
</tr>
<tr>
<td class="style2">
Phone</td>
<td>
<asp:TextBox ID="txtphone" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
Sex</td>
<td>
<asp:RadioButtonList ID="rBtnSex" runat="server" Font-Names="Segoe Script"
RepeatDirection="Horizontal">
<asp:ListItem Value="Male">Male</asp:ListItem>
<asp:ListItem Value="Female">Female</asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
<tr>
<td class="style2">
<asp:Label ID="lblErrorEmail" runat="server"></asp:Label>
</td>
<td>
<asp:Label ID="lblerror" runat="server"></asp:Label>
<asp:ImageButton ID="imgsubmit" runat="server" Height="16px"
style="margin-left: 6px" Width="65px" onclick="imgsubmit_Click" />
</td>
</tr>
<tr>
<td class="style2">
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="txtsignupuser" ErrorMessage="RequiredFieldValidator"
ForeColor="Red"></asp:RequiredFieldValidator>
</td>
<td>
</td>
</tr>
</table>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="txtsignuppass" ErrorMessage="RequiredFieldValidator"
ForeColor="Red"></asp:RequiredFieldValidator>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" ForeColor="Red" />
| 10bit1-group02-pmproject | trunk/Temp_Source/WUC/final/wuc/wucdangki.ascx | ASP.NET | bsd | 3,459 |
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BUS;
using DAO;
namespace final.wuc
{
public partial class wucdangbaiviet : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void imgpost_Click(object sender, ImageClickEventArgs e)
{
ArticleBUS articleBus = new ArticleBUS();
TARTICLE t_article = articleBus.getAll().SingleOrDefault(n => n.ArticleName == txtTitle.Text.ToString());
if (t_article != null)
{
DateTime now = DateTime.Now;
txtTitle.Text += " (" + now.ToShortTimeString() + ")";
}
t_article = new TARTICLE();
t_article.ArticleName = txtTitle.Text;
t_article.ArticleInfo = txtContent.Text;
if (articleBus.addArticle(t_article))
{
Response.Redirect("~/home.aspx");
}
}
}
} | 10bit1-group02-pmproject | trunk/Temp_Source/WUC/final/wuc/wucdangbaiviet.ascx.cs | C# | bsd | 1,126 |
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="wucdangbaiviet.ascx.cs" Inherits="final.wuc.wucdangbaiviet" %>
<%@ Register src="wucupload.ascx" tagname="wucupload" tagprefix="uc1" %>
<style type="text/css">
.style1
{
width: 42%;
height: 212px;
}
.style4
{
height: 34px;
width: 505px;
}
.style6
{
height: 34px;
}
.style7
{
}
.style8
{
height: 34px;
width: 104px;
}
</style>
<table class="style1">
<tr>
<td class="style8">
Tựa đề</td>
<td class="style4">
<asp:TextBox ID="txtTitle" runat="server" Width="180px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style6" colspan="2">
Hình ảnh
<uc1:wucupload ID="wucupload1" runat="server" />
</td>
</tr>
<tr>
<td class="style6" colspan="2">
Nội dung:</td>
</tr>
<tr>
<td class="style7" colspan="2">
<asp:TextBox ID="txtContent" runat="server" Height="127px" Width="317px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style7" colspan="2">
<asp:ImageButton ID="imgpost" runat="server" Height="22px" Width="95px"
onclick="imgpost_Click" />
</td>
</tr>
</table>
| 10bit1-group02-pmproject | trunk/Temp_Source/WUC/final/wuc/wucdangbaiviet.ascx | ASP.NET | bsd | 1,433 |
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="wucupload.ascx.cs" Inherits="final.wuc.wucupload" %>
<asp:FileUpload ID="imgupload" runat="server" />
<asp:ImageButton ID="imguploadimage" runat="server" Height="22px"
Width="80px" />
| 10bit1-group02-pmproject | trunk/Temp_Source/WUC/final/wuc/wucupload.ascx | ASP.NET | bsd | 259 |
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace final.wuc
{
public partial class wucxembaiviet : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
} | 10bit1-group02-pmproject | trunk/Temp_Source/WUC/final/wuc/wucxembaiviet.ascx.cs | C# | bsd | 343 |
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace final.wuc
{
public partial class wucbinhluan : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
} | 10bit1-group02-pmproject | trunk/Temp_Source/WUC/final/wuc/wucbinhluan.ascx.cs | C# | bsd | 341 |
package controller;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.imageio.ImageIO;
import model.Food;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
import dao.FoodDAO;
@Controller
public class FoodController {
private static final int IMG_WIDTH = 100;
private static final int IMG_HEIGHT = 100;
String url = "";
String rootPath = System.getProperty("user.dir");
@Autowired
private FoodDAO dao;
@RequestMapping(value = "/foodlist", method = RequestMethod.GET)
public ModelAndView foodList() {
List<Food> list = dao.getList();
Map<String, Object> model = new HashMap<String, Object>();
url = "foodlist";
model.put("list", list);
model.put("url", url);
return new ModelAndView("../../Homepage", model);
}
@RequestMapping(value = "/addfood", method = RequestMethod.POST)
public ModelAndView addFood(@ModelAttribute Food food) {
Map<String, Object> model = new HashMap<String, Object>();
url = "foodinfo";
if (food.getId()==0) {
String name = food.getName();
File dir = new File(rootPath + File.separator + "workspace"
+ File.separator + "CNPM" + File.separator + "WebContent"
+ File.separator + "resources" + File.separator + "image");
Food.makeQR(name, dir.getAbsolutePath() + File.separator + "qr" + name
+ ".jpg");
String filePath = "/resources/image/qr" + name + ".jpg";
food.setQr(filePath);
}
dao.saveOrUpdate(food);
model.put("url", url);
return new ModelAndView("../../Homepage", model);
}
@RequestMapping(value = "/displayaddfood", method = RequestMethod.GET)
public ModelAndView displayAddFood() {
Map<String, Object> model = new HashMap<String, Object>();
url = "displayaddfood";
model.put("url", url);
model.put("food", new Food());
return new ModelAndView("../../Homepage", model);
}
@RequestMapping(value = "/displayupload", method = RequestMethod.GET)
public String displayUpload() {
return "Upload";
}
@RequestMapping(value = "/upload", method = RequestMethod.POST)
public ModelAndView upload(@RequestParam("file") MultipartFile file) {
Map<String, Object> model = new HashMap<String, Object>();
String message = "";
if (!file.isEmpty()) {
try {
byte[] bytes = file.getBytes();
File dir = new File(rootPath + File.separator + "workspace"
+ File.separator + "CNPM" + File.separator
+ "WebContent" + File.separator + "resources"
+ File.separator + "image");
if (!dir.exists())
dir.mkdirs();
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
String name = sdf.format(cal.getTime());
File serverFile = new File(dir.getAbsolutePath()
+ File.separator + "img" + name + ".jpg");
BufferedOutputStream stream = new BufferedOutputStream(
new FileOutputStream(serverFile));
stream.write(bytes);
stream.close();
resizeIMG(serverFile);
String filePath = "/resources/image/img" + name + ".jpg";
model.put("filepath", filePath);
message = "You successfully uploaded file";
} catch (Exception e) {
message = "You failed to upload => " + e.getMessage();
}
} else {
message = "You failed to upload because the file was empty.";
}
model.put("message", message);
return new ModelAndView("Upload", model);
}
public static void resizeIMG(File file) {
try {
BufferedImage originalImage = ImageIO.read(file);
int type = originalImage.getType() == 0 ? BufferedImage.TYPE_INT_ARGB
: originalImage.getType();
BufferedImage resizeImageJpg = resizeImage(originalImage, type);
ImageIO.write(resizeImageJpg, "jpg",
new File(file.getAbsolutePath()));
} catch (IOException e) {
e.printStackTrace();
}
}
private static BufferedImage resizeImage(BufferedImage originalImage,
int type) {
BufferedImage resizedImage = new BufferedImage(IMG_WIDTH, IMG_HEIGHT,
type);
Graphics2D g = resizedImage.createGraphics();
g.drawImage(originalImage, 0, 0, IMG_WIDTH, IMG_HEIGHT, null);
g.dispose();
return resizedImage;
}
}
| 09130037-cnpm | DTCNPM/src/controller/FoodController.java | Java | asf20 | 4,876 |
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript">
function done(){
var obj = window.dialogArguments;
obj.returnvalue = "${filepath}";
window.close();
}
</script>
</head>
<body>
<form method="POST" action="upload" enctype="multipart/form-data">
<br/>Image to upload: <input type="file" name="file"><br /> <input
type="submit" value="Upload"> Press here to upload the file!
<br/>
<c:if test="${message!=null}">
<c:out value="${message}"></c:out>
<c:if test="${filepath!=null}">
<img alt="" src="<%=request.getContextPath()%>${filepath}">
<button onclick="done()">Done</button>
</c:if>
</c:if>
</form>
</body>
</html> | 09130037-cnpm | DTCNPM/WebContent/WEB-INF/view/Upload.jsp | Java Server Pages | asf20 | 1,047 |
<?php
session_start();
if(!$_SESSION['login']) header("location: login_r.php");
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Bootstrap, from Twitter</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<!-- Le styles -->
<link href="assets/css/bootstrap.css" rel="stylesheet">
<style>
body {
padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
}
</style>
<link href="assets/css/bootstrap-responsive.css" rel="stylesheet">
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<!-- Fav and touch icons -->
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="assets/ico/apple-touch-icon-144-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="assets/ico/apple-touch-icon-114-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="assets/ico/apple-touch-icon-72-precomposed.png">
<link rel="apple-touch-icon-precomposed" href="assets/ico/apple-touch-icon-57-precomposed.png">
<link rel="shortcut icon" href="assets/ico/favicon.png">
</head>
<?php include"view/nav.php" ?>
<body>
<div class="container">
<h1>categories</h1>
<?php
//step 1 (connection)
$con=mysql_connect("localhost", "root", "");
//step 2 (database)
mysql_select_db("test");
//step 3 SQL/get result
$sql="SELECT * from `table`";
$result = mysql_query($sql);
?>
<div class="bs-docs-example">
<table class="table table-hover">
<thead>
<tr>
<th></th>
<th>Name</th>
<th>Detail</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php
//step 4 (grab/process result of query)
$i=1;
while($row = mysql_fetch_assoc($result)){
?>
<tr>
<td><?php echo $row['name'];?></td>
<td><?php echo $row['details'];?></td>
<td><a href="#">View</a> |
<a href="dbaction/user_edit.php?id=<?php echo $row['id'];?>"> Edit</a> |
<a href="dbaction/user_delete.php?id=<?php echo $row['id'];?>">Delete</a> </td>
</tr>
<?php } ?>
</tbody>
</table>
<?php
//step 5 (close connection)
mysql_close($con);
?>
<h3>ADD CATEGORIES</h3>
<form class="form-horizontal" action="dbaction/user_add.php" method="POST">
<div class="control-group">
<label class="control-label" for="f_name">First name</label>
<div class="controls">
<input type="text" name="f_name" >
</div>
</div>
<div class="control-group">
<label class="control-label" for="l_name">Last Name</label>
<div class="controls">
<input type="text" name="l_name">
</div>
</div>
<div class="control-group">
<label class="control-label" for="Username">email</label>
<div class="controls">
<input type="text" name="email">
</div>
</div>
<div class="control-group">
<label class="control-label" for="Username">password</label>
<div class="controls">
<input type="password" name="password">
</div>
</div>
<div class="control-group">
<div class="controls">
<button type="submit" class="btn" name="submit">Add User</button>
</div>
</div>
</form>
</div>
</div> <!-- /container -->
<!-- Le javascript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="assets/js/jquery.js"></script>
<script src="assets/js/bootstrap-transition.js"></script>
<script src="assets/js/bootstrap-alert.js"></script>
<script src="assets/js/bootstrap-modal.js"></script>
<script src="assets/js/bootstrap-dropdown.js"></script>
<script src="assets/js/bootstrap-scrollspy.js"></script>
<script src="assets/js/bootstrap-tab.js"></script>
<script src="assets/js/bootstrap-tooltip.js"></script>
<script src="assets/js/bootstrap-popover.js"></script>
<script src="assets/js/bootstrap-button.js"></script>
<script src="assets/js/bootstrap-collapse.js"></script>
<script src="assets/js/bootstrap-carousel.js"></script>
<script src="assets/js/bootstrap-typeahead.js"></script>
</body>
</html>
| 069ka1-pvgallery | trunk/admin/comments.php | PHP | mit | 4,698 |
<?php
session_start();
$password=$_POST['password'];
$email=$_POST['email'];
if($_POST['submit'])
{
if($email!="" && $password!="")
{
$con=mysql_connect("localhost", "root", "");
mysql_select_db("pv-gallery");
$sql = "SELECT * FROM `admin_users` where`email`='$email' and `password`='$password'";
$result=mysql_query($sql);
$count_result=mysql_num_rows($result);
if($count_result==1)
{
$_SESSION['login']=1;
$_SESSION['email']=$email;
header("location: users.php");
}
else
{
echo"log in failed!!please provide valid user name and password";
}
}
else
{
echo"please provide the username and password";
}
}
?><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Sign in · Twitter Bootstrap</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<!-- Le styles -->
<link href="assets/css/bootstrap.css" rel="stylesheet">
<style type="text/css">
body {
padding-top: 40px;
padding-bottom: 40px;
background-color: #f5f5f5;
}
.form-signin {
max-width: 300px;
padding: 19px 29px 29px;
margin: 0 auto 20px;
background-color: #fff;
border: 1px solid #e5e5e5;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
-webkit-box-shadow: 0 1px 2px rgba(0,0,0,.05);
-moz-box-shadow: 0 1px 2px rgba(0,0,0,.05);
box-shadow: 0 1px 2px rgba(0,0,0,.05);
}
.form-signin .form-signin-heading,
.form-signin .checkbox {
margin-bottom: 10px;
}
.form-signin input[type="text"],
.form-signin input[type="password"] {
font-size: 16px;
height: auto;
margin-bottom: 15px;
padding: 7px 9px;
}
</style>
<link href="assets/css/bootstrap-responsive.css" rel="stylesheet">
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<!-- Fav and touch icons -->
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="../assets/ico/apple-touch-icon-144-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="../assets/ico/apple-touch-icon-114-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="../assets/ico/apple-touch-icon-72-precomposed.png">
<link rel="apple-touch-icon-precomposed" href="../assets/ico/apple-touch-icon-57-precomposed.png">
<link rel="shortcut icon" href="../assets/ico/favicon.png">
</head>
<body>
<div class="container">
<form class="form-signin" action="" method="POST" >
<h2 class="form-signin-heading">Login</h2>
Username: <input name="email" value="" type="text" class="input-block-level" >
Password: <input name="password" value="" type="password" class="input-block-level" >
<button name="submit" value="Sign In" class="btn btn-large btn-primary" type="submit">Sign in</button>
</form>
</div> <!-- /container -->
<!-- Le javascript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="../assets/js/jquery.js"></script>
<script src="../assets/js/bootstrap-transition.js"></script>
<script src="../assets/js/bootstrap-alert.js"></script>
<script src="../assets/js/bootstrap-modal.js"></script>
<script src="../assets/js/bootstrap-dropdown.js"></script>
<script src="../assets/js/bootstrap-scrollspy.js"></script>
<script src="../assets/js/bootstrap-tab.js"></script>
<script src="../assets/js/bootstrap-tooltip.js"></script>
<script src="../assets/js/bootstrap-popover.js"></script>
<script src="../assets/js/bootstrap-button.js"></script>
<script src="../assets/js/bootstrap-collapse.js"></script>
<script src="../assets/js/bootstrap-carousel.js"></script>
<script src="../assets/js/bootstrap-typeahead.js"></script>
</body>
</html>
| 069ka1-pvgallery | trunk/admin/login_r.php | PHP | mit | 4,319 |
<?php
session_start();
if(!$_SESSION['login']) header("location: login_r.php");
?>
<?php
$con=mysql_connect("localhost", "root", "");
mysql_select_db("pv-gallery");
$id=$_GET['id'];
$sql = "SELECT * FROM `users` where `id`=$id";
$result=mysql_query($sql);
$row=mysql_fetch_assoc($result);
?>
<h3>update user <?php echo "$row[f_name]";?> </h3>
<form class="form-horizontal" action="" method="POST">
<div class="control-group error">
<label class="control-label" for="f_name" >First name</label>
<div class="controls">
<input type="text" name="f_name" value="<?php echo "$row[f_name]"; ?>" >
</div>
</div>
<div class="control-group">
<label class="control-label" for="l_name">Last Name</label>
<div class="controls">
<input type="text" name="l_name" value="<?php echo "$row[l_name]"; ?>">
</div>
</div>
<div class="control-group">
<label class="control-label" for="Username">email</label>
<div class="controls">
<input type="text" name="email" value="<?php echo "$row[email]"; ?>">
</div>
</div>
<div class="control-group">
<label class="control-label" for="Username">password</label>
<div class="controls">
<input type="password" name="password"value="<?php echo "$row[password]"; ?>">
</div>
</div>
<div class="control-group">
<div class="controls">
<button type="submit" class="btn" name="submit">update User</button>
</div>
</div>
</form>
<?php
//step 1 (connection)
$con=mysql_connect("localhost", "root", "");
//step 2 (database)
mysql_select_db("test");
$password=$_POST['password'];
$f_name=$_POST['f_name'];
$l_name=$_POST['l_name'];
$email=$_POST['email'];
$sql = "UPDATE `test`.`table` SET `f_name` = \''$f_name'\', `l_name` = \''$l_name'\', `password` = \''$password'\', `email` = \''$email'\' WHERE `table`.`id` = 73 LIMIT 1;";
mysql_query($sql);
header("location: ./users.php");
?>
| 069ka1-pvgallery | trunk/admin/dbactions/user_edit.php | PHP | mit | 1,957 |
<?php
session_start();
if(!$_SESSION['login']) header("location: login.php");
?>
<?php
//step 1 (connection)
$con=mysql_connect("localhost", "root", "");
//step 2 (database)
mysql_select_db("test");
$id=$_GET['id'];
$sql="delete from `test`.`table`where`table`.`id`=$id";
mysql_query($sql);
//echo"user id".$_Get['id']."deleted";
header("location: ../database1.php");
?> | 069ka1-pvgallery | trunk/admin/dbactions/user_delete.php | PHP | mit | 401 |
<?php
session_start();
if(!$_SESSION['login']) header("location: login.php");
?>
<?php
//step 1 (connection)
$con=mysql_connect("localhost", "root", "");
//step 2 (database)
mysql_select_db("test");
$password=$_POST['password'];
$f_name=$_POST['f_name'];
$l_name=$_POST['l_name'];
$email=$_POST['email'];
$sql = "INSERT INTO `test`.`table` (`id`, `f_name`, `l_name`, `password`, `email`) VALUES (NULL, '$f_name','$l_name','$password','$email');";
mysql_query($sql);
header("location: ../database1.php");
?> | 069ka1-pvgallery | trunk/admin/dbactions/user_add.php | PHP | mit | 532 |
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<div class="nav-collapse collapse">
<ul class="nav">
<li class="active"><a href="users.php">users</a></li>
<li><a href="categories.php">categories</a></li>
<li><a href="comments.php">comments</a></li>
<li><a href="media.php">media</a></li>
<li><a href="mediatype.php">media type</a></li>
<li><a href="logout.php">logout</a></li>
<li><font color="yellow"><marquee>wel~come to ***PV-GALLERY***</marquee></font></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
</div> | 069ka1-pvgallery | trunk/admin/view/nav.php | Hack | mit | 969 |
<?php
session_start();
$password=$_POST['password'];
$email=$_POST['email'];
//echo"log in success!";
//set session
$_SESSION['login']=0;
$_SESSION['email']="";
session_destroy();
header("location: login_r.php");
?>
| 069ka1-pvgallery | trunk/admin/logout.php | PHP | mit | 253 |
<?php
session_start();
if(!$_SESSION['login']) header("location: login_r.php");
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>pv-gallery</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<!-- Le styles -->
<link href="assets/css/bootstrap.css" rel="stylesheet">
<style>
body {
padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
}
</style>
<link href="assets/css/bootstrap-responsive.css" rel="stylesheet">
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<!-- Fav and touch icons -->
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="assets/ico/apple-touch-icon-144-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="assets/ico/apple-touch-icon-114-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="assets/ico/apple-touch-icon-72-precomposed.png">
<link rel="apple-touch-icon-precomposed" href="assets/ico/apple-touch-icon-57-precomposed.png">
<link rel="shortcut icon" href="assets/ico/favicon.png">
<ul class="nav nav-tabs">
</head>
<?php include"view/nav.php" ?>
<body>
<div class="container">
<h1>categories</h1>
<?php
//step 1 (connection)
$con=mysql_connect("localhost", "root", "");
//step 2 (database)
mysql_select_db("pv-gallery");
//step 3 SQL/get result
$sql="SELECT * from `category`";
$result = mysql_query($sql);
?>
<div class="bs-docs-example">
<table class="table table-hover">
<thead>
<tr>
<th>Name</th>
<th>Detail</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php
//step 4 (grab/process result of query)
$i=1;
while($row = mysql_fetch_assoc($result)){
?>
<tr>
<td><?php echo $row['name'];?></td>
<td><?php echo $row['details'];?></td>
<td><a href="#">View</a> |
<a href="dbaction/user_edit.php?id=<?php echo $row['id'];?>"> Edit</a> |
<a href="dbaction/user_delete.php?id=<?php echo $row['id'];?>">Delete</a> </td>
</tr>
<?php } ?>
</tbody>
</table>
<?php
//step 5 (close connection)
mysql_close($con);
?>
<h3>ADD CATEGORIES</h3>
<form class="form-horizontal" action="dbaction/user_add.php" method="POST">
<div class="control-group">
<label class="control-label" for="f_name">First name</label>
<div class="controls">
<input type="text" name="f_name" >
</div>
</div>
<div class="control-group">
<label class="control-label" for="l_name">Last Name</label>
<div class="controls">
<input type="text" name="l_name">
</div>
</div>
<div class="control-group">
<label class="control-label" for="Username">email</label>
<div class="controls">
<input type="text" name="email">
</div>
</div>
<div class="control-group">
<label class="control-label" for="Username">password</label>
<div class="controls">
<input type="password" name="password">
</div>
</div>
<div class="control-group">
<div class="controls">
<button type="submit" class="btn" name="submit">Add User</button>
</div>
</div>
</form>
</div>
</div> <!-- /container -->
<!-- Le javascript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="assets/js/jquery.js"></script>
<script src="assets/js/bootstrap-transition.js"></script>
<script src="assets/js/bootstrap-alert.js"></script>
<script src="assets/js/bootstrap-modal.js"></script>
<script src="assets/js/bootstrap-dropdown.js"></script>
<script src="assets/js/bootstrap-scrollspy.js"></script>
<script src="assets/js/bootstrap-tab.js"></script>
<script src="assets/js/bootstrap-tooltip.js"></script>
<script src="assets/js/bootstrap-popover.js"></script>
<script src="assets/js/bootstrap-button.js"></script>
<script src="assets/js/bootstrap-collapse.js"></script>
<script src="assets/js/bootstrap-carousel.js"></script>
<script src="assets/js/bootstrap-typeahead.js"></script>
</body>
</html>
| 069ka1-pvgallery | trunk/admin/categories.php | PHP | mit | 4,707 |
<?php
session_start();
if(!$_SESSION['login']) header("location: login_r.php");
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Bootstrap, from Twitter</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<!-- Le styles -->
<link href="assets/css/bootstrap.css" rel="stylesheet">
<style>
body {
padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
}
</style>
<link href="assets/css/bootstrap-responsive.css" rel="stylesheet">
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<!-- Fav and touch icons -->
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="assets/ico/apple-touch-icon-144-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="assets/ico/apple-touch-icon-114-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="assets/ico/apple-touch-icon-72-precomposed.png">
<link rel="apple-touch-icon-precomposed" href="assets/ico/apple-touch-icon-57-precomposed.png">
<link rel="shortcut icon" href="assets/ico/favicon.png">
</head>
<?php include"view/nav.php" ?>
<body>
<div class="container">
<h1>categories</h1>
<?php
//step 1 (connection)
$con=mysql_connect("localhost", "root", "");
//step 2 (database)
mysql_select_db("test");
//step 3 SQL/get result
$sql="SELECT * from `table`";
$result = mysql_query($sql);
?>
<div class="bs-docs-example">
<table class="table table-hover">
<thead>
<tr>
<th></th>
<th>Name</th>
<th>Detail</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php
//step 4 (grab/process result of query)
$i=1;
while($row = mysql_fetch_assoc($result)){
?>
<tr>
<td><?php echo $row['name'];?></td>
<td><?php echo $row['details'];?></td>
<td><a href="#">View</a> |
<a href="dbaction/user_edit.php?id=<?php echo $row['id'];?>"> Edit</a> |
<a href="dbaction/user_delete.php?id=<?php echo $row['id'];?>">Delete</a> </td>
</tr>
<?php } ?>
</tbody>
</table>
<?php
//step 5 (close connection)
mysql_close($con);
?>
<h3>ADD CATEGORIES</h3>
<form class="form-horizontal" action="dbaction/user_add.php" method="POST">
<div class="control-group">
<label class="control-label" for="f_name">First name</label>
<div class="controls">
<input type="text" name="f_name" >
</div>
</div>
<div class="control-group">
<label class="control-label" for="l_name">Last Name</label>
<div class="controls">
<input type="text" name="l_name">
</div>
</div>
<div class="control-group">
<label class="control-label" for="Username">email</label>
<div class="controls">
<input type="text" name="email">
</div>
</div>
<div class="control-group">
<label class="control-label" for="Username">password</label>
<div class="controls">
<input type="password" name="password">
</div>
</div>
<div class="control-group">
<div class="controls">
<button type="submit" class="btn" name="submit">Add User</button>
</div>
</div>
</form>
</div>
</div> <!-- /container -->
<!-- Le javascript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="assets/js/jquery.js"></script>
<script src="assets/js/bootstrap-transition.js"></script>
<script src="assets/js/bootstrap-alert.js"></script>
<script src="assets/js/bootstrap-modal.js"></script>
<script src="assets/js/bootstrap-dropdown.js"></script>
<script src="assets/js/bootstrap-scrollspy.js"></script>
<script src="assets/js/bootstrap-tab.js"></script>
<script src="assets/js/bootstrap-tooltip.js"></script>
<script src="assets/js/bootstrap-popover.js"></script>
<script src="assets/js/bootstrap-button.js"></script>
<script src="assets/js/bootstrap-collapse.js"></script>
<script src="assets/js/bootstrap-carousel.js"></script>
<script src="assets/js/bootstrap-typeahead.js"></script>
</body>
</html>
| 069ka1-pvgallery | trunk/admin/media.php | PHP | mit | 4,698 |
<?php
session_start();
if(!$_SESSION['login']) header("location: login_r.php");
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Bootstrap, from Twitter</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<!-- Le styles -->
<link href="assets/css/bootstrap.css" rel="stylesheet">
<style>
body {
padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
}
</style>
<link href="assets/css/bootstrap-responsive.css" rel="stylesheet">
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<!-- Fav and touch icons -->
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="assets/ico/apple-touch-icon-144-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="assets/ico/apple-touch-icon-114-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="assets/ico/apple-touch-icon-72-precomposed.png">
<link rel="apple-touch-icon-precomposed" href="assets/ico/apple-touch-icon-57-precomposed.png">
<link rel="shortcut icon" href="assets/ico/favicon.png">
</head>
<?php include"view/nav.php" ?>
<body>
<div class="container">
<h1>categories</h1>
<?php
//step 1 (connection)
$con=mysql_connect("localhost", "root", "");
//step 2 (database)
mysql_select_db("test");
//step 3 SQL/get result
$sql="SELECT * from `table`";
$result = mysql_query($sql);
?>
<div class="bs-docs-example">
<table class="table table-hover">
<thead>
<tr>
<th></th>
<th>Name</th>
<th>Detail</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php
//step 4 (grab/process result of query)
$i=1;
while($row = mysql_fetch_assoc($result)){
?>
<tr>
<td><?php echo $row['name'];?></td>
<td><?php echo $row['details'];?></td>
<td><a href="#">View</a> |
<a href="dbaction/user_edit.php?id=<?php echo $row['id'];?>"> Edit</a> |
<a href="dbaction/user_delete.php?id=<?php echo $row['id'];?>">Delete</a> </td>
</tr>
<?php } ?>
</tbody>
</table>
<?php
//step 5 (close connection)
mysql_close($con);
?>
<h3>ADD CATEGORIES</h3>
<form class="form-horizontal" action="dbaction/user_add.php" method="POST">
<div class="control-group">
<label class="control-label" for="f_name">First name</label>
<div class="controls">
<input type="text" name="f_name" >
</div>
</div>
<div class="control-group">
<label class="control-label" for="l_name">Last Name</label>
<div class="controls">
<input type="text" name="l_name">
</div>
</div>
<div class="control-group">
<label class="control-label" for="Username">email</label>
<div class="controls">
<input type="text" name="email">
</div>
</div>
<div class="control-group">
<label class="control-label" for="Username">password</label>
<div class="controls">
<input type="password" name="password">
</div>
</div>
<div class="control-group">
<div class="controls">
<button type="submit" class="btn" name="submit">Add User</button>
</div>
</div>
</form>
</div>
</div> <!-- /container -->
<!-- Le javascript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="assets/js/jquery.js"></script>
<script src="assets/js/bootstrap-transition.js"></script>
<script src="assets/js/bootstrap-alert.js"></script>
<script src="assets/js/bootstrap-modal.js"></script>
<script src="assets/js/bootstrap-dropdown.js"></script>
<script src="assets/js/bootstrap-scrollspy.js"></script>
<script src="assets/js/bootstrap-tab.js"></script>
<script src="assets/js/bootstrap-tooltip.js"></script>
<script src="assets/js/bootstrap-popover.js"></script>
<script src="assets/js/bootstrap-button.js"></script>
<script src="assets/js/bootstrap-collapse.js"></script>
<script src="assets/js/bootstrap-carousel.js"></script>
<script src="assets/js/bootstrap-typeahead.js"></script>
</body>
</html>
| 069ka1-pvgallery | trunk/admin/mediatype.php | PHP | mit | 4,698 |
<?php
session_start();
if(!$_SESSION['login']) header("location: login_r.php");
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Bootstrap, from Twitter</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<!-- Le styles -->
<link href="assets/css/bootstrap.css" rel="stylesheet">
<style>
body {
padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
}
</style>
<link href="assets/css/bootstrap-responsive.css" rel="stylesheet">
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<!-- Fav and touch icons -->
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="assets/ico/apple-touch-icon-144-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="assets/ico/apple-touch-icon-114-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="assets/ico/apple-touch-icon-72-precomposed.png">
<link rel="apple-touch-icon-precomposed" href="assets/ico/apple-touch-icon-57-precomposed.png">
<link rel="shortcut icon" href="assets/ico/favicon.png">
</head>
<body>
<?php include"view/nav.php" ?>
<div class="container">
<h1>Bootstrap starter template</h1>
<p>Use this document as a way to quick start any new project.<br> All you get is this message and a barebones HTML document.</p>
<?php
//step 1 (connection)
$con=mysql_connect("localhost", "root", "");
//step 2 (database)
mysql_select_db("test");
//step 3 SQL/get result
$sql="SELECT * from `table`";
$result = mysql_query($sql);
?>
<div class="bs-docs-example">
<table class="table table-hover">
<thead>
<tr>
<th>#</th>
<th>First Name</th>
<th>Last Name</th>
<th>email</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php
//step 4 (grab/process result of query)
$i=1;
while($row = mysql_fetch_assoc($result)){
?>
<tr>
<td>1</td>
<td><?php echo $row['f_name'];?></td>
<td><?php echo $row['l_name'];?></td>
<td><?php echo $row['email'];?></td>
<td><a href="#">View</a> |
<a href="dbaction/user_edit.php?id=<?php echo $row['id'];?>"> Edit</a> |
<a href="dbaction/user_delete.php?id=<?php echo $row['id'];?>">Delete</a> </td>
</tr>
<?php } ?>
</tbody>
</table>
<?php
//step 5 (close connection)
mysql_close($con);
?>
<h3>Add new users</h3>
<form class="form-horizontal" action="dbaction/user_add.php" method="POST">
<div class="control-group">
<label class="control-label" for="f_name">First name</label>
<div class="controls">
<input type="text" name="f_name" >
</div>
</div>
<div class="control-group">
<label class="control-label" for="l_name">Last Name</label>
<div class="controls">
<input type="text" name="l_name">
</div>
</div>
<div class="control-group">
<label class="control-label" for="Username">email</label>
<div class="controls">
<input type="text" name="email">
</div>
</div>
<div class="control-group">
<label class="control-label" for="Username">password</label>
<div class="controls">
<input type="password" name="password">
</div>
</div>
<div class="control-group">
<div class="controls">
<button type="submit" class="btn" name="submit">Add User</button>
</div>
</div>
</form>
</div>
</div> <!-- /container -->
<!-- Le javascript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="assets/js/jquery.js"></script>
<script src="assets/js/bootstrap-transition.js"></script>
<script src="assets/js/bootstrap-alert.js"></script>
<script src="assets/js/bootstrap-modal.js"></script>
<script src="assets/js/bootstrap-dropdown.js"></script>
<script src="assets/js/bootstrap-scrollspy.js"></script>
<script src="assets/js/bootstrap-tab.js"></script>
<script src="assets/js/bootstrap-tooltip.js"></script>
<script src="assets/js/bootstrap-popover.js"></script>
<script src="assets/js/bootstrap-button.js"></script>
<script src="assets/js/bootstrap-collapse.js"></script>
<script src="assets/js/bootstrap-carousel.js"></script>
<script src="assets/js/bootstrap-typeahead.js"></script>
</body>
</html>
| 069ka1-pvgallery | trunk/admin/database1.php | PHP | mit | 4,951 |
<?php
session_start();
if(!$_SESSION['login']) header("location: login.php");
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Bootstrap, from Twitter</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<!-- Le styles -->
<link href="assets/css/bootstrap.css" rel="stylesheet">
<style>
body {
padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
}
</style>
<link href="assets/css/bootstrap-responsive.css" rel="stylesheet">
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<!-- Fav and touch icons -->
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="assets/ico/apple-touch-icon-144-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="assets/ico/apple-touch-icon-114-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="assets/ico/apple-touch-icon-72-precomposed.png">
<link rel="apple-touch-icon-precomposed" href="assets/ico/apple-touch-icon-57-precomposed.png">
<link rel="shortcut icon" href="assets/ico/favicon.png">
</head>
<?php include"view/nav.php" ?>
<body>
<div class="container">
<h1>Users</h1>
<?php
//step 1 (connection)
$con=mysql_connect("localhost", "root", "");
//step 2 (database)
mysql_select_db("pv-gallery");
//step 3 SQL/get result
$sql="SELECT * from `users`";
$result = mysql_query($sql);
?>
<div class="bs-docs-example">
<table class="table table-hover">
<thead>
<tr>
<th>#</th>
<th>Username</th>
<th>Email</th>
<th>Type</th>
<th>Created at</th>
</tr>
</thead>
<tbody>
<?php
//step 4 (grab/process result of query)
$i=1;
while($row = mysql_fetch_assoc($result)){
?>
<tr>
<td>1</td>
<td><?php echo $row['username'];?></td>
<td><?php echo $row['email'];?></td>
<td><?php echo $row['type'];?></td>
<td><?php echo $row['created_at'];?></td>
<td><a href="#">View</a> |
<a href="dbaction/user_edit.php?id=<?php echo $row['id'];?>"> Edit</a> |
<a href="dbaction/user_delete.php?id=<?php echo $row['id'];?>">Delete</a> </td>
</tr>
<?php } ?>
</tbody>
</table>
<?php
//step 5 (close connection)
mysql_close($con);
?>
<h3>Add new users</h3>
<form class="form-horizontal" action="dbaction/user_add.php" method="POST">
<div class="control-group">
<label class="control-label" for="username">Username</label>
<div class="controls">
<input type="text" name="username" >
</div>
</div>
<div class="control-group">
<label class="control-label" for="password">Password</label>
<div class="controls">
<input type="password" name="password">
</div>
</div>
<div class="control-group">
<label class="control-label" for="email">email</label>
<div class="controls">
<input type="text" name="email">
</div>
</div>
</div>
<div class="control-group">
<label class="control-label" for="type">email</label>
<div class="controls">
<input type="int" name="type">
</div>
</div>
<div class="control-group">
<div class="controls">
<button type="submit" class="btn" name="submit">Add User</button>
</div>
</div>
</form>
</div>
</div> <!-- /container -->
<!-- Le javascript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="assets/js/jquery.js"></script>
<script src="assets/js/bootstrap-transition.js"></script>
<script src="assets/js/bootstrap-alert.js"></script>
<script src="assets/js/bootstrap-modal.js"></script>
<script src="assets/js/bootstrap-dropdown.js"></script>
<script src="assets/js/bootstrap-scrollspy.js"></script>
<script src="assets/js/bootstrap-tab.js"></script>
<script src="assets/js/bootstrap-tooltip.js"></script>
<script src="assets/js/bootstrap-popover.js"></script>
<script src="assets/js/bootstrap-button.js"></script>
<script src="assets/js/bootstrap-collapse.js"></script>
<script src="assets/js/bootstrap-carousel.js"></script>
<script src="assets/js/bootstrap-typeahead.js"></script>
</body>
</html>
| 069ka1-pvgallery | trunk/admin/users.php | PHP | mit | 4,838 |
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>
| 076-ria | trunk/ria.nbp/jpa_query.nbp/src/main/webapp/index.jsp | Java Server Pages | lgpl | 374 |
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package edu.chl.tdaniel.jpa_query.nbp.core;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
/**
*
* @author Daniel
*/
@Entity
@Table(name = "PRODUCT")
@NamedQueries({
@NamedQuery(name = "Product.findAll", query = "SELECT p FROM Product p")})
public class Product implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@NotNull
@Column(name = "PRODUCT_ID")
private Integer productId;
// @Max(value=?) @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
@Column(name = "PURCHASE_COST")
private BigDecimal purchaseCost;
@Column(name = "QUANTITY_ON_HAND")
private Integer quantityOnHand;
@Column(name = "MARKUP")
private BigDecimal markup;
@Size(max = 5)
@Column(name = "AVAILABLE")
private String available;
@Size(max = 50)
@Column(name = "DESCRIPTION")
private String description;
@JoinColumn(name = "PRODUCT_CODE", referencedColumnName = "PROD_CODE")
@ManyToOne(optional = false)
private ProductCode productCode;
@JoinColumn(name = "MANUFACTURER_ID", referencedColumnName = "MANUFACTURER_ID")
@ManyToOne(optional = false)
private Manufacturer manufacturerId;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "productId")
private Collection<PurchaseOrder> purchaseOrderCollection;
public Product() {
}
public Product(Integer productId) {
this.productId = productId;
}
public Integer getProductId() {
return productId;
}
public void setProductId(Integer productId) {
this.productId = productId;
}
public BigDecimal getPurchaseCost() {
return purchaseCost;
}
public void setPurchaseCost(BigDecimal purchaseCost) {
this.purchaseCost = purchaseCost;
}
public Integer getQuantityOnHand() {
return quantityOnHand;
}
public void setQuantityOnHand(Integer quantityOnHand) {
this.quantityOnHand = quantityOnHand;
}
public BigDecimal getMarkup() {
return markup;
}
public void setMarkup(BigDecimal markup) {
this.markup = markup;
}
public String getAvailable() {
return available;
}
public void setAvailable(String available) {
this.available = available;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public ProductCode getProductCode() {
return productCode;
}
public void setProductCode(ProductCode productCode) {
this.productCode = productCode;
}
public Manufacturer getManufacturerId() {
return manufacturerId;
}
public void setManufacturerId(Manufacturer manufacturerId) {
this.manufacturerId = manufacturerId;
}
public Collection<PurchaseOrder> getPurchaseOrderCollection() {
return purchaseOrderCollection;
}
public void setPurchaseOrderCollection(Collection<PurchaseOrder> purchaseOrderCollection) {
this.purchaseOrderCollection = purchaseOrderCollection;
}
@Override
public int hashCode() {
int hash = 0;
hash += (productId != null ? productId.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Product)) {
return false;
}
Product other = (Product) object;
if ((this.productId == null && other.productId != null) || (this.productId != null && !this.productId.equals(other.productId))) {
return false;
}
return true;
}
@Override
public String toString() {
return "edu.chl.tdaniel.jpa_query.nbp.core.Product[ productId=" + productId + " ]";
}
}
| 076-ria | trunk/ria.nbp/jpa_query.nbp/src/main/java/edu/chl/tdaniel/jpa_query/nbp/core/Product.java | Java | lgpl | 4,596 |
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package edu.chl.tdaniel.jpa_query.nbp.core;
import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
/**
*
* @author Daniel
*/
@Entity
@Table(name = "CUSTOMER")
@NamedQueries({
@NamedQuery(name = "Customer.findAll", query = "SELECT c FROM Customer c")})
public class Customer implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@NotNull
@Column(name = "CUSTOMER_ID")
private Integer customerId;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 10)
@Column(name = "ZIP")
private String zip;
@Size(max = 30)
@Column(name = "NAME")
private String name;
@Size(max = 30)
@Column(name = "ADDRESSLINE1")
private String addressline1;
@Size(max = 30)
@Column(name = "ADDRESSLINE2")
private String addressline2;
@Size(max = 25)
@Column(name = "CITY")
private String city;
@Size(max = 2)
@Column(name = "STATE")
private String state;
// @Pattern(regexp="^\\(?(\\d{3})\\)?[- ]?(\\d{3})[- ]?(\\d{4})$", message="Invalid phone/fax format, should be as xxx-xxx-xxxx")//if the field contains phone or fax number consider using this annotation to enforce field validation
@Size(max = 12)
@Column(name = "PHONE")
private String phone;
// @Pattern(regexp="^\\(?(\\d{3})\\)?[- ]?(\\d{3})[- ]?(\\d{4})$", message="Invalid phone/fax format, should be as xxx-xxx-xxxx")//if the field contains phone or fax number consider using this annotation to enforce field validation
@Size(max = 12)
@Column(name = "FAX")
private String fax;
// @Pattern(regexp="[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?", message="Invalid email")//if the field contains email address consider using this annotation to enforce field validation
@Size(max = 40)
@Column(name = "EMAIL")
private String email;
@Column(name = "CREDIT_LIMIT")
private Integer creditLimit;
@JoinColumn(name = "DISCOUNT_CODE", referencedColumnName = "DISCOUNT_CODE")
@ManyToOne(optional = false)
private DiscountCode discountCode;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "customerId")
private Collection<PurchaseOrder> purchaseOrderCollection;
public Customer() {
}
public Customer(Integer customerId) {
this.customerId = customerId;
}
public Customer(Integer customerId, String zip) {
this.customerId = customerId;
this.zip = zip;
}
public Integer getCustomerId() {
return customerId;
}
public void setCustomerId(Integer customerId) {
this.customerId = customerId;
}
public String getZip() {
return zip;
}
public void setZip(String zip) {
this.zip = zip;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddressline1() {
return addressline1;
}
public void setAddressline1(String addressline1) {
this.addressline1 = addressline1;
}
public String getAddressline2() {
return addressline2;
}
public void setAddressline2(String addressline2) {
this.addressline2 = addressline2;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getFax() {
return fax;
}
public void setFax(String fax) {
this.fax = fax;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Integer getCreditLimit() {
return creditLimit;
}
public void setCreditLimit(Integer creditLimit) {
this.creditLimit = creditLimit;
}
public DiscountCode getDiscountCode() {
return discountCode;
}
public void setDiscountCode(DiscountCode discountCode) {
this.discountCode = discountCode;
}
public Collection<PurchaseOrder> getPurchaseOrderCollection() {
return purchaseOrderCollection;
}
public void setPurchaseOrderCollection(Collection<PurchaseOrder> purchaseOrderCollection) {
this.purchaseOrderCollection = purchaseOrderCollection;
}
@Override
public int hashCode() {
int hash = 0;
hash += (customerId != null ? customerId.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Customer)) {
return false;
}
Customer other = (Customer) object;
if ((this.customerId == null && other.customerId != null) || (this.customerId != null && !this.customerId.equals(other.customerId))) {
return false;
}
return true;
}
@Override
public String toString() {
return "edu.chl.tdaniel.jpa_query.nbp.core.Customer[ customerId=" + customerId + " ]";
}
}
| 076-ria | trunk/ria.nbp/jpa_query.nbp/src/main/java/edu/chl/tdaniel/jpa_query/nbp/core/Customer.java | Java | lgpl | 6,003 |
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package edu.chl.tdaniel.jpa_query.nbp.core;
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
/**
*
* @author Daniel
*/
@Entity
@Table(name = "MICRO_MARKET")
@NamedQueries({
@NamedQuery(name = "MicroMarket.findAll", query = "SELECT m FROM MicroMarket m")})
public class MicroMarket implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 10)
@Column(name = "ZIP_CODE")
private String zipCode;
// @Max(value=?) @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
@Column(name = "RADIUS")
private Double radius;
@Column(name = "AREA_LENGTH")
private Double areaLength;
@Column(name = "AREA_WIDTH")
private Double areaWidth;
public MicroMarket() {
}
public MicroMarket(String zipCode) {
this.zipCode = zipCode;
}
public String getZipCode() {
return zipCode;
}
public void setZipCode(String zipCode) {
this.zipCode = zipCode;
}
public Double getRadius() {
return radius;
}
public void setRadius(Double radius) {
this.radius = radius;
}
public Double getAreaLength() {
return areaLength;
}
public void setAreaLength(Double areaLength) {
this.areaLength = areaLength;
}
public Double getAreaWidth() {
return areaWidth;
}
public void setAreaWidth(Double areaWidth) {
this.areaWidth = areaWidth;
}
@Override
public int hashCode() {
int hash = 0;
hash += (zipCode != null ? zipCode.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof MicroMarket)) {
return false;
}
MicroMarket other = (MicroMarket) object;
if ((this.zipCode == null && other.zipCode != null) || (this.zipCode != null && !this.zipCode.equals(other.zipCode))) {
return false;
}
return true;
}
@Override
public String toString() {
return "edu.chl.tdaniel.jpa_query.nbp.core.MicroMarket[ zipCode=" + zipCode + " ]";
}
}
| 076-ria | trunk/ria.nbp/jpa_query.nbp/src/main/java/edu/chl/tdaniel/jpa_query/nbp/core/MicroMarket.java | Java | lgpl | 2,736 |
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package edu.chl.tdaniel.jpa_query.nbp.core;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
/**
*
* @author Daniel
*/
@Entity
@Table(name = "PURCHASE_ORDER")
@NamedQueries({
@NamedQuery(name = "PurchaseOrder.findAll", query = "SELECT p FROM PurchaseOrder p")})
public class PurchaseOrder implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@NotNull
@Column(name = "ORDER_NUM")
private Integer orderNum;
@Column(name = "QUANTITY")
private Short quantity;
// @Max(value=?) @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
@Column(name = "SHIPPING_COST")
private BigDecimal shippingCost;
@Column(name = "SALES_DATE")
@Temporal(TemporalType.DATE)
private Date salesDate;
@Column(name = "SHIPPING_DATE")
@Temporal(TemporalType.DATE)
private Date shippingDate;
@Size(max = 30)
@Column(name = "FREIGHT_COMPANY")
private String freightCompany;
@JoinColumn(name = "PRODUCT_ID", referencedColumnName = "PRODUCT_ID")
@ManyToOne(optional = false)
private Product productId;
@JoinColumn(name = "CUSTOMER_ID", referencedColumnName = "CUSTOMER_ID")
@ManyToOne(optional = false)
private Customer customerId;
public PurchaseOrder() {
}
public PurchaseOrder(Integer orderNum) {
this.orderNum = orderNum;
}
public Integer getOrderNum() {
return orderNum;
}
public void setOrderNum(Integer orderNum) {
this.orderNum = orderNum;
}
public Short getQuantity() {
return quantity;
}
public void setQuantity(Short quantity) {
this.quantity = quantity;
}
public BigDecimal getShippingCost() {
return shippingCost;
}
public void setShippingCost(BigDecimal shippingCost) {
this.shippingCost = shippingCost;
}
public Date getSalesDate() {
return salesDate;
}
public void setSalesDate(Date salesDate) {
this.salesDate = salesDate;
}
public Date getShippingDate() {
return shippingDate;
}
public void setShippingDate(Date shippingDate) {
this.shippingDate = shippingDate;
}
public String getFreightCompany() {
return freightCompany;
}
public void setFreightCompany(String freightCompany) {
this.freightCompany = freightCompany;
}
public Product getProductId() {
return productId;
}
public void setProductId(Product productId) {
this.productId = productId;
}
public Customer getCustomerId() {
return customerId;
}
public void setCustomerId(Customer customerId) {
this.customerId = customerId;
}
@Override
public int hashCode() {
int hash = 0;
hash += (orderNum != null ? orderNum.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof PurchaseOrder)) {
return false;
}
PurchaseOrder other = (PurchaseOrder) object;
if ((this.orderNum == null && other.orderNum != null) || (this.orderNum != null && !this.orderNum.equals(other.orderNum))) {
return false;
}
return true;
}
@Override
public String toString() {
return "edu.chl.tdaniel.jpa_query.nbp.core.PurchaseOrder[ orderNum=" + orderNum + " ]";
}
}
| 076-ria | trunk/ria.nbp/jpa_query.nbp/src/main/java/edu/chl/tdaniel/jpa_query/nbp/core/PurchaseOrder.java | Java | lgpl | 4,187 |
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package edu.chl.tdaniel.jpa_query.nbp.core;
import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
/**
*
* @author Daniel
*/
@Entity
@Table(name = "PRODUCT_CODE")
@NamedQueries({
@NamedQuery(name = "ProductCode.findAll", query = "SELECT p FROM ProductCode p")})
public class ProductCode implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 2)
@Column(name = "PROD_CODE")
private String prodCode;
@Basic(optional = false)
@NotNull
@Column(name = "DISCOUNT_CODE")
private char discountCode;
@Size(max = 10)
@Column(name = "DESCRIPTION")
private String description;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "productCode")
private Collection<Product> productCollection;
public ProductCode() {
}
public ProductCode(String prodCode) {
this.prodCode = prodCode;
}
public ProductCode(String prodCode, char discountCode) {
this.prodCode = prodCode;
this.discountCode = discountCode;
}
public String getProdCode() {
return prodCode;
}
public void setProdCode(String prodCode) {
this.prodCode = prodCode;
}
public char getDiscountCode() {
return discountCode;
}
public void setDiscountCode(char discountCode) {
this.discountCode = discountCode;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Collection<Product> getProductCollection() {
return productCollection;
}
public void setProductCollection(Collection<Product> productCollection) {
this.productCollection = productCollection;
}
@Override
public int hashCode() {
int hash = 0;
hash += (prodCode != null ? prodCode.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof ProductCode)) {
return false;
}
ProductCode other = (ProductCode) object;
if ((this.prodCode == null && other.prodCode != null) || (this.prodCode != null && !this.prodCode.equals(other.prodCode))) {
return false;
}
return true;
}
@Override
public String toString() {
return "edu.chl.tdaniel.jpa_query.nbp.core.ProductCode[ prodCode=" + prodCode + " ]";
}
}
| 076-ria | trunk/ria.nbp/jpa_query.nbp/src/main/java/edu/chl/tdaniel/jpa_query/nbp/core/ProductCode.java | Java | lgpl | 3,105 |
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package edu.chl.tdaniel.jpa_query.nbp.core;
import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
/**
*
* @author Daniel
*/
@Entity
@Table(name = "MANUFACTURER")
@NamedQueries({
@NamedQuery(name = "Manufacturer.findAll", query = "SELECT m FROM Manufacturer m")})
public class Manufacturer implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@NotNull
@Column(name = "MANUFACTURER_ID")
private Integer manufacturerId;
@Size(max = 30)
@Column(name = "NAME")
private String name;
@Size(max = 30)
@Column(name = "ADDRESSLINE1")
private String addressline1;
@Size(max = 30)
@Column(name = "ADDRESSLINE2")
private String addressline2;
@Size(max = 25)
@Column(name = "CITY")
private String city;
@Size(max = 2)
@Column(name = "STATE")
private String state;
@Size(max = 10)
@Column(name = "ZIP")
private String zip;
// @Pattern(regexp="^\\(?(\\d{3})\\)?[- ]?(\\d{3})[- ]?(\\d{4})$", message="Invalid phone/fax format, should be as xxx-xxx-xxxx")//if the field contains phone or fax number consider using this annotation to enforce field validation
@Size(max = 12)
@Column(name = "PHONE")
private String phone;
// @Pattern(regexp="^\\(?(\\d{3})\\)?[- ]?(\\d{3})[- ]?(\\d{4})$", message="Invalid phone/fax format, should be as xxx-xxx-xxxx")//if the field contains phone or fax number consider using this annotation to enforce field validation
@Size(max = 12)
@Column(name = "FAX")
private String fax;
// @Pattern(regexp="[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?", message="Invalid email")//if the field contains email address consider using this annotation to enforce field validation
@Size(max = 40)
@Column(name = "EMAIL")
private String email;
@Size(max = 30)
@Column(name = "REP")
private String rep;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "manufacturerId")
private Collection<Product> productCollection;
public Manufacturer() {
}
public Manufacturer(Integer manufacturerId) {
this.manufacturerId = manufacturerId;
}
public Integer getManufacturerId() {
return manufacturerId;
}
public void setManufacturerId(Integer manufacturerId) {
this.manufacturerId = manufacturerId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddressline1() {
return addressline1;
}
public void setAddressline1(String addressline1) {
this.addressline1 = addressline1;
}
public String getAddressline2() {
return addressline2;
}
public void setAddressline2(String addressline2) {
this.addressline2 = addressline2;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getZip() {
return zip;
}
public void setZip(String zip) {
this.zip = zip;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getFax() {
return fax;
}
public void setFax(String fax) {
this.fax = fax;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getRep() {
return rep;
}
public void setRep(String rep) {
this.rep = rep;
}
public Collection<Product> getProductCollection() {
return productCollection;
}
public void setProductCollection(Collection<Product> productCollection) {
this.productCollection = productCollection;
}
@Override
public int hashCode() {
int hash = 0;
hash += (manufacturerId != null ? manufacturerId.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Manufacturer)) {
return false;
}
Manufacturer other = (Manufacturer) object;
if ((this.manufacturerId == null && other.manufacturerId != null) || (this.manufacturerId != null && !this.manufacturerId.equals(other.manufacturerId))) {
return false;
}
return true;
}
@Override
public String toString() {
return "edu.chl.tdaniel.jpa_query.nbp.core.Manufacturer[ manufacturerId=" + manufacturerId + " ]";
}
}
| 076-ria | trunk/ria.nbp/jpa_query.nbp/src/main/java/edu/chl/tdaniel/jpa_query/nbp/core/Manufacturer.java | Java | lgpl | 5,430 |
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package edu.chl.tdaniel.jpa_query.nbp.core;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
/**
*
* @author Daniel
*/
@Entity
@Table(name = "DISCOUNT_CODE")
@NamedQueries({
@NamedQuery(name = "DiscountCode.findAll", query = "SELECT d FROM DiscountCode d")})
public class DiscountCode implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@NotNull
@Column(name = "DISCOUNT_CODE")
private Character discountCode;
// @Max(value=?) @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
@Column(name = "RATE")
private BigDecimal rate;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "discountCode")
private Collection<Customer> customerCollection;
public DiscountCode() {
}
public DiscountCode(Character discountCode) {
this.discountCode = discountCode;
}
public Character getDiscountCode() {
return discountCode;
}
public void setDiscountCode(Character discountCode) {
this.discountCode = discountCode;
}
public BigDecimal getRate() {
return rate;
}
public void setRate(BigDecimal rate) {
this.rate = rate;
}
public Collection<Customer> getCustomerCollection() {
return customerCollection;
}
public void setCustomerCollection(Collection<Customer> customerCollection) {
this.customerCollection = customerCollection;
}
@Override
public int hashCode() {
int hash = 0;
hash += (discountCode != null ? discountCode.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof DiscountCode)) {
return false;
}
DiscountCode other = (DiscountCode) object;
if ((this.discountCode == null && other.discountCode != null) || (this.discountCode != null && !this.discountCode.equals(other.discountCode))) {
return false;
}
return true;
}
@Override
public String toString() {
return "edu.chl.tdaniel.jpa_query.nbp.core.DiscountCode[ discountCode=" + discountCode + " ]";
}
}
| 076-ria | trunk/ria.nbp/jpa_query.nbp/src/main/java/edu/chl/tdaniel/jpa_query/nbp/core/DiscountCode.java | Java | lgpl | 2,825 |
<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
BUGS !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
<input type="submit" value="Start Obtrusive Flash" onclick="flashScreen('bottom',
null);"/>
Sending null as color to flash.
Best try: document.getElementById('bottom').style.backgroundColor
didn't work at all (sends empty)
-->
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" type="text/css" href="main.css"/>
<script type="text/javascript" src="js/jquery-1.6.4.js"/>
<script type="text/javascript" src="js/flash.js"/>
<script type="text/javascript" src="js/lighten_jquery.js"/>
<script type="text/javascript" src="js/darken_jquery.js"/>
<script type="text/javascript" src="js/menu.js"/>
<script type="text/javascript" src="js/rgb.js"/>
<title>TODO supply a title</title>
</head>
<body>
<div id="topleft">
<div id="topright"></div>
<ul>
<li id="fruits_button">Fruits</li>
<li id="vegetables_button">Vegetables</li>
<li id="nuts_button">Nuts</li>
</ul>
</div>
<div id="bottom">
<div id="content">"We will populate this <b>div</b> with content that depends
on choice in the above menu!</div>
</div>
<br/>
<p id="flash_button"><input type="submit" value="Start Obtrusive Flash" onclick="Flasher.flash('bottom',
window.getComputedStyle(document.getElementById('bottom'),null).backgroundColor);"/>
</p>
<div class="dropdown" id="fruits_dropdown"></div>
<div class="dropdown" id="vegetables_dropdown"></div>
<div class="dropdown" id="nuts_dropdown"></div>
</body>
</html>
| 076-ria | trunk/ria.nbp/src/main/webapp/index.xhtml | HTML | lgpl | 1,939 |
/*
Document : main
Created on : Sep 2, 2011, 11:40:49 AM
Author : Mikey
Description:
Purpose of the stylesheet follows.
*/
/*
TODO customize this sample style
Syntax recommendation http://www.w3.org/TR/REC-CSS2/
*/
/*
BUGS:
1. max zoom out, the menu bar is outside the div.
Can't set auto height on div, because then child div disappears.
2. What's wrong with the bg picture?
*/
root {
}
body {
width: 50em;
margin-left: auto;
margin-right: auto;
}
/* TOPLEFT -- contains menu
*/
#topleft {
background-color: darkseagreen;
margin-top: 20px;
margin-bottom: 20px;
/* padding: 0px; This is not necessary */
border: solid 1px #000000;
border-color: black;
width: 100%;
height: 4em;
}
/* TOPRIGHT -- contains smiley face
*/
#topright {
border-left: solid 1px #000000;
border-color: black;
width: 100px;
float: right;
background-color: moccasin;
background-size: 300px;
background-image: url('http://upload.wikimedia.org/wikipedia/commons/7/79/Face-smile.svg');
background-position: center;
height: inherit;
}
#topleft ul {
margin-left: 0;
padding-left: 1.5em;
}
#topleft li {
display: inline-block;
margin-left: 0px;
padding-right: 2.2em;
font-size: 1.5em;
font-variant: small-caps;
}
#topleft li:hover {
color: white;
}
#bottom {
border: dashed 1px black;
width: 50em;
height: 20em;
background-color: moccasin;
}
#content {
margin: 20px;
color: brown;
font-size: 1em;
font-style: italic;
font-family: "Times New Roman";
}
#flash_button {
text-align: center;
}
ul.dropdown {
margin-left: 0;
padding-left: 2em;
}
ul.dropdown li {
font-weight: bold;
list-style-type: none;
}
ul.dropdown li:hover {
color: white;
}
#fruits_dropdown, #vegetables_dropdown, #nuts_dropdown {
position: absolute;
background-color: moccasin;
width: 15em;
height: 5em;
border: double 3px black;
visibility: hidden;
} | 076-ria | trunk/ria.nbp/src/main/webapp/main.css | CSS | lgpl | 2,079 |
var Flasher = {
/*
* This function takes the id of an element and animates it's background colour from
* black to white. Once the color is white, the animation is stopped and the original
* colour of the element is restored.
*
* NOTE: Several things need to be fixed before it works...
*/
flash: function(id, original_colour) {
var e = document.getElementById(id);
var colour = 0;
id = setInterval(function() {
colour += 5;
e.style.backgroundColor = "#"+ colour.toString(16)
+ colour.toString(16) + colour.toString(16);
if (colour == 250) {
clearInterval(id);
e.style.backgroundColor = original_colour;
}
}, 5);
}
} | 076-ria | trunk/ria.nbp/src/main/webapp/js/flash.js | JavaScript | lgpl | 719 |
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
$(document).ready(function() {
MenuBar.enableHover();
//Menu.showMenu(param);
});
/*
* Inspect the ihtml/ directory in the ria.zip archive and then add it to the project.
When initializing the menu, you should dynamically add the content of each drop-
down_* le into one of the above div's. To do this, you can use:
a) $.ajax()
b) $(*).load() - Simpler to use, but $.ajax() gives you additional control.
*
* For each entry in the drop down, you need to register a click event. Whenever the
user clicks on an item in the drop down menu, you should populate the bottom
div with an appropriate text from the ihtml/ directory by using one of the calls
described in {6.4}. This time around though, a problem exists. Because the div's
we added are populated dynamically using AJAX, there is no guarantee that the
newly loaded content has been added to the DOM when we call $(*).click(). The
solution to this problem is to use $(*).live(). Refer to the JQuery documentation
for more information.
*
*/
var shownDropDown = 0;
var timeout = 200;
var closetimer = 0;
var MenuBar = {
enableHover:function() {
/*
* Load contents of dropdowns into respective menus
*/
$('#fruits_dropdown').load('ihtml/dropdown_fruits.ihtml');
$('#vegetables_dropdown').load('ihtml/dropdown_vegetables.ihtml');
$('#nuts_dropdown').load('ihtml/dropdown_nuts.ihtml');
/*
* Register onclick for all the buttons
*/
$('ul.dropdown #apple').live('click', function() {
registerClick("apple");
});
$('ul.dropdown #banana').live('click', function() {
registerClick("banana");
});
$('ul.dropdown #cashew').live('click', function() {
registerClick("cashew");
});
$('ul.dropdown #pecan').live('click', function() {
registerClick("pecan");
});
$('ul.dropdown #lettuce').live('click', function() {
registerClick("lettuce");
});
$('ul.dropdown #tomato').live('click', function() {
registerClick("tomato");
});
/*
* Register hover for menu buttons
*/
$("#fruits_button").hover(function() {
placeDropDown("#fruits_button", "#fruits_dropdown");
showDropDown("#fruits_dropdown");
}, function() {
startCloseTimer();
});
$("#vegetables_button").hover(function() {
placeDropDown("#vegetables_button", "#vegetables_dropdown");
showDropDown("#vegetables_dropdown");
}, function() {
startCloseTimer();
});
$("#nuts_button").hover(function() {
placeDropDown("#nuts_button", "#nuts_dropdown");
showDropDown("#nuts_dropdown");
}, function() {
startCloseTimer();
});
}
}
var registerClick = function(param) {
$('#content').load("/EncylopediaServlet", {what: param});
}
var showDropDown = function(dropdown) {
cancelCloseTimer();
closeDropDown();
shownDropDown = $(dropdown);
shownDropDown.css("visibility", "visible");
shownDropDown.mouseenter(cancelCloseTimer);
shownDropDown.mouseleave(startCloseTimer);
}
var placeDropDown = function(button,dropdown) {
var pos = $(button).offset();
var height = $(button).height();
$(dropdown).css(
{"left": (pos.left ) + "px",
"top" : (pos.top + height) + "px"} );
};
// closes drop down
function closeDropDown()
{
if(shownDropDown) shownDropDown.css("visibility", "hidden");
}
// go close timer
function startCloseTimer()
{
closetimer = window.setTimeout(closeDropDown, timeout);
}
// cancel close timer
function cancelCloseTimer()
{
if(closetimer)
{
window.clearTimeout(closetimer);
closetimer = null;
}
}
var Menu = {
showMenu:function(param) {
$(param).load();
}
} | 076-ria | trunk/ria.nbp/src/main/webapp/js/menu.js | JavaScript | lgpl | 4,191 |
/* Here, you should not change anything else than the argument in the call below */
addLoadEvent(function() {
Lighten.lightenElement('bottom');
})
var Lighten = {
/*
* Takes an id to an element and brightens its colour a notch...
* You should implement the lightenElement(id) function.
*/
lightenElement: function(id) {
var element = document.getElementById(id);
var color = new RGB(window.getComputedStyle(element,null)
.backgroundColor);
element.onmouseout = function() {
element.style.backgroundColor = color.getHex();
}
element.onmouseover = function() {
color2 = new RGB(window.getComputedStyle(element,null)
.backgroundColor);
color2.addRGB(30, 30, 30);
element.style.backgroundColor = color2.getHex();
}
}
}
| 076-ria | trunk/ria.nbp/src/main/webapp/js/lighten.js | JavaScript | lgpl | 913 |
/*
* Taken from
* http://developer.expressionz.in/blogs/2009/03/07/calling-multiple-windows-onload-functions-in-javascript/
*/
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func
} else {
window.onload = function() {
if (oldonload) {
oldonload()
}
func()
}
}
}
/*
* A working solution, but
* not very good...
*/
//window.onload = function() {
// Darken.darkenElement('topleft');
// Lighten.lightenElement('bottom');
//}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
| 076-ria | trunk/ria.nbp/src/main/webapp/js/launch.js | JavaScript | lgpl | 697 |
/* Here, you should not change anything else than the argument in the call below */
$(document).ready(function(){
Lighten.lightenElement('#bottom');
});
var Lighten = {
/*
* Takes an id to an element and brightens its colour a notch...
* You should implement the lightenElement(id) function.
*/
lightenElement: function(id) {
var color = $(id).css('backgroundColor');
var color2 = new RGB(color);
color2.addRGB(30, 30, 30);
$(id).hover(
function(){$(id).css("backgroundColor",color2.getHex());},
function(){$(id).css("backgroundColor",color);}
);
}
} | 076-ria | trunk/ria.nbp/src/main/webapp/js/lighten_jquery.js | JavaScript | lgpl | 670 |
/* Here, you should not change anything else than the argument in the call below */
/*
* The problem with darken and lighten is:
* window.onload can't be executed in both
*
*/
$(document).ready(function() {
Darken.darkenElement('#topleft');
});
var Darken = {
/*
* Takes an id to an element and darkens its colour a notch...
* You should implement the darkenElement(id) function.
*/
darkenElement: function(id) {
var color = $(id).css('backgroundColor');
var color2 = new RGB(color);
color2.subRGB(30, 30, 30);
$(id).hover(
function(){$(id).css("backgroundColor",color2.getHex());},
function(){$(id).css("backgroundColor",color);}
);
}
} | 076-ria | trunk/ria.nbp/src/main/webapp/js/darken_jquery.js | JavaScript | lgpl | 757 |
/* Here, you should not change anything else than the argument in the call below */
/*
* The problem with darken and lighten is:
* window.onload can't be executed in both
*
*/
addLoadEvent(function() {
Darken.darkenElement('topleft');
})
var Darken = {
/*
* Takes an id to an element and darkens its colour a notch...
* You should implement the darkenElement(id) function.
*/
darkenElement: function(id) {
var element = document.getElementById(id);
var color = new RGB(window.getComputedStyle(element,null)
.backgroundColor);
element.onmouseout = function() {
element.style.backgroundColor = color.getHex();
}
element.onmouseover = function() {
color2 = new RGB(window.getComputedStyle(element,null)
.backgroundColor);
color2.subRGB(30, 30, 30);
element.style.backgroundColor = color2.getHex();
}
}
}
| 076-ria | trunk/ria.nbp/src/main/webapp/js/darken.js | JavaScript | lgpl | 1,004 |
/*
* RGB "class".
* col = a string representing a colour in the form "rgb(r,g,b)".
*/
var RGB = function(col) {
this.colour = [0, 0, 0];
/*
* Simple snippet of code that parses an incoming rgb(r,g,b)
* values an populates colour[].
*/
col = col.split(",");
this.colour[0] = parseInt(col[0].substring(4));
this.colour[1] = parseInt(col[1]);
this.colour[2] = parseInt(col[2].substring(0, col[2].length - 1));
/*
* Returns the hex value (#rrggbb) for the current colour.
*/
this.getHex = function() {
return "#" + this.colour[0].toString(16) +
this.colour[1].toString(16) +
this.colour[2].toString(16);
}
/*
* Adds the given r, g and b values to the current colour value.
*/
this.addRGB = function(r, g, b) {
r += this.colour[0];
g += this.colour[1];
b += this.colour[2];
this.colour = [r > 255 ? 255 : (r < 0 ? 0 : r),
g > 255 ? 255 : (g < 0 ? 0 : g),
b > 255 ? 255 : (b < 0 ? 0 : b)];
}
/*
* Substracts the given r, g and b values from the current colour value.
*/
this.subRGB = function(r, g, b) {
this.addRGB(-r, -g, -b);
}
return this;
}
| 076-ria | trunk/ria.nbp/src/main/webapp/js/rgb.js | JavaScript | lgpl | 1,146 |
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package edu.chl.tdaniel.ria;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
*
* @author Daniel
*/
@WebServlet(name = "EncylopediaServlet", urlPatterns = {"/EncylopediaServlet"})
public class EncylopediaServlet extends HttpServlet {
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
InputStream in = this.getClass().getClassLoader().getResourceAsStream(request.getParameter("what") + ".ihtml");
Scanner scan = new Scanner(in);
//juhegviebviebvgi
try {
while (scan.hasNext()){
out.println(scan.nextLine());
}
} finally {
scan.close();
out.close();
}
}
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/**
* Handles the HTTP <code>GET</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Returns a short description of the servlet.
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}
| 076-ria | trunk/ria.nbp/src/main/java/edu/chl/tdaniel/ria/EncylopediaServlet.java | Java | lgpl | 2,961 |
#ifndef FILE_HPP
#define FILE_HPP
#include "Shared.hpp"
#include <fstream>
namespace engine {
/// \brief Read/Write file opening mode
enum eReadWriteMode{
RWM_Write = 1, /// Read/Write, make a new file or overwrite an existant one
RWM_Open = 0, /// Read/Write, does not overwrite, file must exist
RWM_ReadOnly = -1, /// Read Only mode, file must exist
};
/// \brief Opening cursor position in file
enum eFilePos{
FP_Top,
FP_Bottom
};
/// \brief Class used for any file handling
class OOXAPI File{
public:
/// \brief Ctor, default, do nothing
File();
/// \brief Ctor, open the given file in given mode
/// \param pFilename : name of the file
/// \param pFp : file cursor position
/// \param pRwm : opening mode
File(const std::string &pFilename, eReadWriteMode pRwm = RWM_Open, eFilePos pFp = FP_Top);
virtual ~File();
/// \brief Open a file (in buffer)
/// \param pFilename : name of the file
/// \param pFp : file cursor position
/// \param pRwm : opening mode
void Open(const std::string &pFilename, eReadWriteMode pRwm = RWM_Open, eFilePos pFp = FP_Top);
/// \brief Close the opened file (buffer)
void Close();
/// \brief Flush the buffer in the file
void Flush();
/// \brief Returns the content of opened file in one string
std::string Read() const;
/// \brief Returns true if a file is opened
bool IsOpened() const;
/// \brief Returns the name of opened file
std::string Filename() const;
/// \brief Returns true if EoF is reached
bool End() const;
/// \brief Returns the current line in the opened file(and increments cursor afterwards)
std::string GetLine();
/// \brief Stream Op for in file writing
template<class T> File& operator<< (T &pMsg);
/// Static Methods
/// \brief Check if a file exists on drive
/// \param pFilename : path to the file
static bool Exists(const std::string &pFilename);
protected:
std::fstream mFile; /// File buffer
std::string mFileName; /// File name (with path)
};
template<class T>
inline File& File::operator<< (T &pMsg){
if(IsOpened())
mFile << pMsg;
return (*this);
}
}
#endif
| 00xengine | src/Utils/File.hpp | C++ | mit | 2,260 |
#ifndef SPOINTER_HPP
#define SPOINTER_HPP
#include "SPointerPolicies.hpp"
#include "Debug/New.hpp"
namespace engine {
/// \brief Smart Pointer class used to limit and ease the use of real pointers
template <class T, template<class> class Ownership = RefCountPolicy>
class SPointer : public Ownership<T>{
protected:
T* Ptr;
public:
/// \brief Ctor, Null init
SPointer() : Ptr(NULL){
}
/// \brief Ctor, Copy of another SPointer
SPointer(const SPointer<T> &P) : Ownership<T>(P),
Ptr(Clone(P.Ptr)){
}
/// \brief Ctor, Pointer init
SPointer( T* obj ) : Ptr(obj){
}
/// \brief Dtor, release an instance of the stored pointer if it exists
~SPointer(){
Kill();
}
/// \brief Release an instance of the stored pointer if it exists
void Kill(){
Release(Ptr);
}
/// \brief Returns the content of stored pointer
T& operator*() const { return *Ptr; }
/// \brief Returns the stored pointer
T* operator->() const { return Ptr; }
/// \brief Returns the stored pointer
operator T*() const { return Ptr; }
/// \brief Returns the stored pointer
T* Get() { return Ptr; }
/// \brief Internally used function to swap two pointers and their policy
void Swap(SPointer &P){
Ownership<T>::Swap(P);
std::swap(Ptr, P.Ptr);
}
/// \brief Returns a copy of this SPointer and its policy
SPointer& Copy(){
Ptr = Clone(Ptr);
return *this;
}
/// \brief Copy operator, add a reference to policy
SPointer& operator=(const SPointer &P){
SPointer<T, Ownership>(P).Swap(*this);
return *this;
}
/// \brief Assign operator
SPointer& operator=(T* obj){
if(Ptr != obj)
SPointer<T, Ownership>(obj).Swap(*this);
return *this;
}
/// \brief Returns true if stored pointer is null
bool operator!() { return Ptr == NULL; }
};
#include "Debug/NewOff.hpp"
}
#endif
| 00xengine | src/Utils/SPointer.hpp | C++ | mit | 2,027 |
#ifndef SHARED
#define SHARED
#define ENGINE_MAJOR 0
#define ENGINE_MINOR 3
#define ENGINE_PATCH 0
/// SFML
#include "SFML/Graphics.hpp"
/// Platform
#if defined(_WIN32) || defined(WIN32)
# define OOXWIN32
# include <time.h>
#else
# define OOXLINUX
# include <sys/time.h>
#endif
/// DLL managment under WIN32
#ifdef OOXWIN32
# ifdef OOXEXPORTS
# define OOXAPI __declspec(dllexport)
# else
# define OOXAPI __declspec(dllimport)
# endif
# ifdef _MSC_VER
# pragma warning(disable : 4251)
# pragma warning(disable : 4661)
# endif
#else
# define OOXAPI
#endif
/// Open GL 3
#ifdef OOXWIN32
# define GLEW_STATIC 1
# include "GL/glew.h"
#else
# define GL3_PROTOTYPES 1
# include <GL3/gl3.h>
#endif
/// Anisotropic extension definition
#define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE
#define GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF
/// String (always used anyway)
#include <string>
/// End Of Line
#define eol "\n"
/// Types declaration
typedef char s8;
typedef unsigned char u8;
typedef short s16;
typedef unsigned short u16;
typedef int s32;
typedef unsigned int u32;
typedef long long s64;
typedef unsigned long long u64;
typedef float f32;
typedef double f64;
/// \brief Returns time in "HH:MM:SS" format
inline std::string GetTime(){
time_t tps = time(NULL);
tm* temps = localtime(&tps);
char ret[9];
strftime(ret, 9, "%H:%M:%S", temps);
return ret;
}
/// \brief Returns date in "Day DD MMM YYYY" format
inline std::string GetDate(){
time_t tps = time(NULL);
tm* temps = localtime(&tps);
char ret[16];
strftime(ret, 16, "%a %d %b %Y", temps);
return ret;
}
#endif
| 00xengine | src/Utils/Shared.hpp | C++ | mit | 1,673 |
#ifndef KEYS_HPP
#define KEYS_HPP
#include "SFML/Window/Event.hpp"
namespace engine{
/// \brief Enumeration of the different mouse buttons
enum MouseButton{
LeftButton = sf::Mouse::Left,
RightButton = sf::Mouse::Right,
MiddleButton = sf::Mouse::Middle,
X1Button = sf::Mouse::XButton1,
X2Button = sf::Mouse::XButton2,
};
/// \brief Enumeration of the different Keyboard keys
enum Key{
A = sf::Key::A,
B = sf::Key::B,
C = sf::Key::C,
D = sf::Key::D,
E = sf::Key::E,
F = sf::Key::F,
G = sf::Key::G,
H = sf::Key::H,
I = sf::Key::I,
J = sf::Key::J,
K = sf::Key::K,
L = sf::Key::L,
M = sf::Key::M,
N = sf::Key::N,
O = sf::Key::O,
P = sf::Key::P,
Q = sf::Key::Q,
R = sf::Key::R,
S = sf::Key::S,
T = sf::Key::T,
U = sf::Key::U,
V = sf::Key::V,
X = sf::Key::X,
Y = sf::Key::Y,
Z = sf::Key::Z,
Num0 = sf::Key::Num0,
Num1 = sf::Key::Num1,
Num2 = sf::Key::Num2,
Num3 = sf::Key::Num3,
Num4 = sf::Key::Num4,
Num5 = sf::Key::Num5,
Num6 = sf::Key::Num6,
Num7 = sf::Key::Num7,
Num8 = sf::Key::Num8,
Num9 = sf::Key::Num9,
Escape = sf::Key::Escape,
LShift = sf::Key::LShift,
LControl = sf::Key::LControl,
LAlt = sf::Key::LAlt,
LSystem = sf::Key::LSystem,
RShift = sf::Key::RShift,
RAlt = sf::Key::RAlt,
RControl = sf::Key::RControl,
RSystem = sf::Key::RSystem,
Menu = sf::Key::Menu,
LBracket = sf::Key::LBracket,
RBracket = sf::Key::RBracket,
SemiColon = sf::Key::SemiColon,
Comma = sf::Key::Comma,
Period = sf::Key::Period,
Quote = sf::Key::Quote,
Slash = sf::Key::Slash,
BackSlash = sf::Key::BackSlash,
Tilde = sf::Key::Tilde,
Equal = sf::Key::Equal,
Dash = sf::Key::Dash,
Space = sf::Key::Space,
Return = sf::Key::Return,
Back = sf::Key::Back,
Tab = sf::Key::Tab,
PageUp = sf::Key::PageUp,
PageDown = sf::Key::PageDown,
End = sf::Key::End,
Home = sf::Key::Home,
Insert = sf::Key::Insert,
Delete = sf::Key::Delete,
Add = sf::Key::Add,
Subtract = sf::Key::Subtract,
Multiply = sf::Key::Multiply,
Divide = sf::Key::Divide,
Left = sf::Key::Left,
Right = sf::Key::Right,
Up = sf::Key::Up,
Down = sf::Key::Down,
Numpad0 = sf::Key::Numpad0,
Numpad1 = sf::Key::Numpad1,
Numpad2 = sf::Key::Numpad2,
Numpad3 = sf::Key::Numpad3,
Numpad4 = sf::Key::Numpad4,
Numpad5 = sf::Key::Numpad5,
Numpad6 = sf::Key::Numpad6,
Numpad7 = sf::Key::Numpad7,
Numpad8 = sf::Key::Numpad8,
Numpad9 = sf::Key::Numpad9,
F1 = sf::Key::F1,
F2 = sf::Key::F2,
F3 = sf::Key::F3,
F4 = sf::Key::F4,
F5 = sf::Key::F5,
F6 = sf::Key::F6,
F7 = sf::Key::F7,
F8 = sf::Key::F8,
F9 = sf::Key::F9,
F10 = sf::Key::F10,
F11 = sf::Key::F11,
F12 = sf::Key::F12,
Pause = sf::Key::Pause,
};
}
#endif
| 00xengine | src/Utils/Keys.hpp | C++ | mit | 2,940 |
#include "Clock.hpp"
#ifdef OOXWIN32
# include <Windows.h>
#endif
namespace engine {
// ============================== //
f64 GetSystemTime(){
#if defined(OOXWIN32)
static LARGE_INTEGER Frequency;
static BOOL UseHighPerformanceTimer = QueryPerformanceFrequency(&Frequency);
if (UseHighPerformanceTimer)
{
// High performance counter available : use it
LARGE_INTEGER CurrentTime;
QueryPerformanceCounter(&CurrentTime);
return static_cast<double>(CurrentTime.QuadPart) / Frequency.QuadPart;
}
else
{
// High performance counter not available : use GetTickCount (less accurate)
return GetTickCount() * 0.001;
}
#else
timeval Time = {0, 0};
gettimeofday(&Time, NULL);
return Time.tv_sec + Time.tv_usec / 1000000.;
#endif
}
void Sleep(f32 pTime){
#if defined(OOXWIN32)
::Sleep(static_cast<DWORD>(pTime * 1000));
#else
usleep(static_cast<u32>(pTime * 1000000));
#endif
}
// ============================== //
Clock::Clock() : mPaused(false), mClockTime(0.0){
mLastFrameTime = GetSystemTime();
}
void Clock::Reset(){
mLastFrameTime = GetSystemTime();
mClockTime = 0.0;
}
void Clock::Pause(){
mPaused = true;
}
void Clock::Resume(){
mLastFrameTime = GetSystemTime();
mPaused = false;
}
f32 Clock::GetElapsedTime(){
if(!mPaused) {
mTempTime = GetSystemTime();
mClockTime += mTempTime - mLastFrameTime;
mLastFrameTime = mTempTime;
}
return static_cast<f32>(mClockTime);
}
}
| 00xengine | src/Utils/Clock.cpp | C++ | mit | 1,573 |
#ifndef CLOCK_HPP
#define CLOCK_HPP
#include "Shared.hpp"
namespace engine {
/// \brief Returns system time, depending on platform
/// \return the UTC time, seconds only
f64 GetSystemTime();
/// \brief Make the current thread sleep
/// \param pTime : sleep time in seconds
void Sleep(f32 pTime);
/// \brief Clock is a small class used to manage time like with a timer
class OOXAPI Clock{
public:
/// \brief Ctor, zeroed clock
Clock();
/// \brief Reset the clock to zero
void Reset();
/// \brief Pause the clock
void Pause();
/// \brief Resume the clock if it has been paused
void Resume();
/// \brief Returns time elapsed since last Reset
f32 GetElapsedTime();
private:
f64 mLastFrameTime; /// Global seconds elapsed the previons frame
f64 mClockTime; /// Seconds since last clock reset
f64 mTempTime; /// Variable used in mClockTime calculation
bool mPaused; /// True if the clock is paused
};
}
#endif
| 00xengine | src/Utils/Clock.hpp | C++ | mit | 1,002 |
template<typename T>
inline engine::String::String(const T &ppValue){
mString << ppValue;
}
template<typename T>
inline String& engine::String::operator +(const T &pValue){
mString << pValue;
return *this;
}
template<typename T>
inline String& engine::String::operator+=(const T &pValue){
return (*this + pValue);
}
inline std::ostream& operator<<(std::ostream& oss, const String &pStr){
return oss << pStr.str();
}
inline void engine::String::operator=(const std::string &pStr){
mString.str(pStr);
}
inline void engine::String::operator=(const String &pStr){
mString.str(pStr);
}
inline engine::String::operator std::string() const{
return mString.str();
}
inline bool engine::String::operator ==(const std::string &pStr) const{
return this->str() == pStr;
}
inline bool engine::String::operator !=(const std::string &pStr) const{
return !(*this == pStr);
}
inline std::string engine::String::str() const{
return mString.str();
}
inline std::ostringstream& engine::String::ostr(){
return mString;
}
inline size_t engine::String::size() const{
return mString.str().size();
}
inline bool engine::String::Empty() const{
return str().empty();
}
inline bool engine::String::IsCommentary() const{
return str().substr(0,2) == "//";
}
inline StringVector engine::StringUtils::SplitString(const std::string &pIn, const std::string &pSep, u32 pMaxSplit){
StringVector v;
// pre allocation pour performance
v.reserve(pMaxSplit ? pMaxSplit + 1 : 5); // 5 nbr max de mot le plus souvent
u32 splitNbr = 0;
// Parcourt de la chaine
size_t p1 = 0, p2;
do{
p2 = pIn.find_first_of(pSep, p1);
if(p2 == p1)
p1 = p2 + 1;
else if( p2 == std::string::npos || (pMaxSplit && splitNbr == pMaxSplit)){
v.push_back(pIn.substr(p1));
break;
}else{
v.push_back(pIn.substr(p1, p2 - p1));
p1 = p2 + 1;
}
p1 = pIn.find_first_not_of(pSep, p1);
++splitNbr;
} while(p2 != std::string::npos);
return v;
}
inline std::string engine::StringUtils::ToLower(const std::string &pStr){
std::string retStr(pStr.size(), ' ');
s32 (*pf)(s32) = std::tolower;
std::transform(pStr.begin(), pStr.end(), retStr.begin(), pf);
return retStr;
}
inline std::string engine::StringUtils::ToUpper(const std::string &pStr){
std::string retStr(pStr.size(), ' ');
s32 (*pf)(s32) = std::toupper;
std::transform(pStr.begin(), pStr.end(), retStr.begin(), pf);
return retStr;
}
inline std::string engine::StringUtils::GetExtension(const std::string &pFileName){
std::string::size_type Pos = pFileName.find_first_of(".");
if( Pos != std::string::npos)
return pFileName.substr( Pos+1, std::string::npos);
return "";
}
inline std::string engine::StringUtils::GetFileName(const std::string &pFileName){
std::string::size_type pos = pFileName.find_first_of(".");
if(pos != std::string::npos)
return pFileName.substr(0, pos);
return "";
}
inline bool engine::StringUtils::StartsWith(const std::string &pStr, const std::string &pStart, bool pLowerCase){
size_t strlen = pStr.length(), startlen = pStart.length();
if(strlen < startlen || startlen == 0)
return false;
std::string strstart = pStr.substr(0, startlen);
std::string str = pStr;
if(pLowerCase){
strstart = ToLower(strstart);
str = ToLower(str);
}
return strstart == str;
} | 00xengine | src/Utils/String.inl | C++ | mit | 3,508 |
#ifndef COLOR_HPP
#define COLOR_HPP
#include "Shared.hpp"
namespace engine {
/// \brief Color class with RGBA Components
class OOXAPI Color{
public:
/// \brief Ctor, color from RGBA
Color(f32 R = 0.f, f32 G = 0.f, f32 B = 0.f, f32 A = 1.f);
/// \brief Returns the RGB color components in a float array
void RGB(float pTab[]) const;
/// \brief Returns the RGBA color components in a float array
void RGBA(float pTab[]) const;
f32 R() const{ return r; }
f32 G() const{ return g; }
f32 B() const{ return b; }
f32 A() const{ return a; }
/// \brief Returns a pointer on r
operator f32*() { return &r; }
/// \brief Sets the RGB color components
void RGB(f32 pR, f32 pG, f32 pB);
/// \brief Sets the RGBA color components
void RGBA(f32 pR, f32 pG, f32 pB, f32 pA);
void R(f32 pR) { r = pR; }
void G(f32 pG) { g = pG; }
void B(f32 pB) { b = pB; }
void A(f32 pA) { a = pA; }
/// \brief Common Colors
static const Color Black;
static const Color White;
static const Color Red;
static const Color Green;
static const Color Blue;
static const Color Magenta;
static const Color Cyan;
static const Color Yellow;
static const Color Orange;
static const Color Grey;
private:
f32 r, g, b, a;
};
/// \brief SFML to 00xEngine conversion
Color To00xColor(const sf::Color &pColor);
/// \brief 00xEngine to SFML conversion
sf::Color ToSFMLColor(const Color &pColor);
}
#endif
| 00xengine | src/Utils/Color.hpp | C++ | mit | 1,468 |
#ifndef STRINGCONVERTER_HPP
#define STRINGCONVERTER_HPP
#include "Shared.hpp"
#include "Math/Vector2.hpp"
#include "Math/Vector3.hpp"
namespace engine {
class String;
class Color;
/// \brief String Converter (types -> String & String -> types)
class OOXAPI StringConverter{
public:
/// \brief STRING TO FLOAT
static f32 ToFloat(const std::string &pVal);
/// \brief STRING TO INT
static s32 ToInt(const std::string &pVal);
/// \brief STRING TO UNSIGNED
static u32 ToUnsigned(const std::string &pVal);
/// \brief STRING TO BOOL
static bool ToBool(const std::string &pVal);
/// \brief STRING to VECTOR2
static Vector2F ToVector2(const std::string &pVal);
/// \brief STRING to VECTOR3
static Vector3F ToVector3(const std::string &pVal);
/// \brief STRING to COLOR
static Color ToColor(const std::string &pVal);
/// \brief FLOAT to STRING
static String ToString(f32 pVal, u16 pPrecision = 6);
/// \brief DOUBLE to STRING
static String ToString(f64 pVal, u16 pPrecision = 6);
/// \brief LINT to STRING
static String ToString(s32 pVal);
/// \brief LUNSIGNED to STRING
static String ToString(u32 pVal);
/// \brief SHORT to STRING
static String ToString(s16 pVal);
/// \brief UNSIGNED to STRING
static String ToString(u16 pVal);
};
}
#endif
| 00xengine | src/Utils/StringConverter.hpp | C++ | mit | 1,362 |
#include "StringConverter.hpp"
#include "String.hpp"
#include "Color.hpp"
#include "Debug/New.hpp"
namespace engine {
// STRING TO FLOAT
f32 StringConverter::ToFloat(const std::string &pVal){
std::istringstream str(pVal);
f32 ret = 0;
str >> ret;
return ret;
}
// STRING TO INT
s32 StringConverter::ToInt(const std::string &pVal){
std::istringstream str(pVal);
s32 ret = 0;
str >> ret;
return ret;
}
// STRING TO UNSIGNED
u32 StringConverter::ToUnsigned(const std::string &pVal){
std::istringstream str(pVal);
u32 ret = 0;
str >> ret;
return ret;
}
// STRING TO BOOL
bool StringConverter::ToBool(const std::string &pVal){
return StringUtils::StartsWith(pVal, "true") || StringUtils::StartsWith(pVal, "1") || StringUtils::StartsWith(pVal, "yes");
}
// STRING StringConverter::to VECTOR2
Vector2F StringConverter::ToVector2(const std::string &pVal){
Vector2F ret;
StringVector vec = StringUtils::SplitString(pVal);
if(vec.size() != 2)
ret = Vector2F::ZERO;
else
ret = Vector2F(ToFloat(vec[0]), ToFloat(vec[1]));
return ret;
}
// STRING StringConverter::to VECTOR3
Vector3F StringConverter::ToVector3(const std::string &pVal){
Vector3F ret;
StringVector vec = StringUtils::SplitString(pVal);
if(vec.size() != 3)
ret = Vector3F::ZERO;
else
ret = Vector3F(ToFloat(vec[0]), ToFloat(vec[1]), ToFloat(vec[2]));
return ret;
}
// STRING StringConverter::to COLOR
Color StringConverter::ToColor(const std::string &pVal){
Color ret;
StringVector vec = StringUtils::SplitString(pVal, ",");
if(vec[0].find_first_of(".")){
// Float Color
if(vec.size() == 4)
ret = Color(ToFloat(vec[0]),ToFloat(vec[1]),ToFloat(vec[2]),ToFloat(vec[3]));
else if(vec.size() == 3)
ret = Color(ToFloat(vec[0]),ToFloat(vec[1]),ToFloat(vec[2]), 1.f);
else
ret = Color::Black;
}else{
// Unsigned Color
if(vec.size() == 4)
ret = Color(ToFloat(vec[0]) / 255.f,ToFloat(vec[1]) / 255.f,ToFloat(vec[2]) / 255.f,ToFloat(vec[3]) / 255.f);
else if(vec.size() == 3)
ret = Color(ToFloat(vec[0]) / 255.f,ToFloat(vec[1]) / 255.f,ToFloat(vec[2]) / 255.f, 1.f);
else
ret = Color::Black;
}
return ret;
}
// FLOAT StringConverter::to STRING
String StringConverter::ToString(f32 pVal, u16 pPrecision){
std::ostringstream oss;
oss.precision(pPrecision);
oss << pVal;
return oss.str();
}
// DOUBLE StringConverter::to STRING
String StringConverter::ToString(f64 pVal, u16 pPrecision){
std::ostringstream oss;
oss.precision(pPrecision);
oss << pVal;
return oss.str();
}
// LINT StringConverter::to STRING
String StringConverter::ToString(s32 pVal){
std::ostringstream oss;
oss << pVal;
return oss.str();
}
// LUNSIGNED StringConverter::to STRING
String StringConverter::ToString(u32 pVal){
std::ostringstream oss;
oss << pVal;
return oss.str();
}
// SHORT StringConverter::to STRING
String StringConverter::ToString(s16 pVal){
std::ostringstream oss;
oss << pVal;
return oss.str();
}
// UNSIGNED StringConverter::to STRING
String StringConverter::ToString(u16 pVal){
std::ostringstream oss;
oss << pVal;
return oss.str();
}
}
| 00xengine | src/Utils/StringConverter.cpp | C++ | mit | 3,408 |
#include "Core/Entity.hpp"
namespace engine{
void Entity::MakeCube(const std::string &pMeshName, Shader &pShader){
Vector3F position[] = { Vector3F(-1.f,-1.f,-1.f), Vector3F(-1.f,-1.f,1.f), Vector3F(1.f,-1.f,1.f), Vector3F(1.f,-1.f,-1.f),
Vector3F(-1.f,1.f,-1.f), Vector3F(-1.f,1.f,1.f), Vector3F(1.f,1.f,1.f), Vector3F(1.f,1.f,-1.f),
Vector3F(-1.f,-1.f,-1.f), Vector3F(-1.f,1.f,-1.f), Vector3F(1.f,1.f,-1.f), Vector3F(1.f,-1.f,-1.f),
Vector3F(-1.f,-1.f,1.f), Vector3F(-1.f,1.f,1.f), Vector3F(1.f,1.f,1.f), Vector3F(1.f,-1.f,1.f),
Vector3F(-1.f,-1.f,-1.f), Vector3F(-1.f,-1.f,1.f), Vector3F(-1.f,1.f,1.f), Vector3F(-1.f,1.f,-1.f),
Vector3F(1.f,-1.f,-1.f), Vector3F(1.f,-1.f,1.f), Vector3F(1.f,1.f,1.f), Vector3F(1.f,1.f,-1.f)
};
Index indices[] = { 0, 2, 1, 0, 3, 2,
4, 5, 6, 4, 6, 7,
8, 9, 10, 8, 10, 11,
12, 15, 14, 12, 14, 13,
16, 17, 18, 16, 18, 19,
20, 23, 22, 20, 22, 21
};
Vector2F texcoords[] = {Vector2F(1.f, 1.f), Vector2F(1.f, 0.f), Vector2F(0.f, 0.f), Vector2F(0.f, 1.f),
Vector2F(1.f, 1.F), Vector2F(1.f, 0.f), Vector2F(0.f, 0.f), Vector2F(0.f, 1.f),
Vector2F(1.f, 1.F), Vector2F(1.f, 0.f), Vector2F(0.f, 0.f), Vector2F(0.f, 1.f),
Vector2F(1.f, 1.F), Vector2F(1.f, 0.f), Vector2F(0.f, 0.f), Vector2F(0.f, 1.f),
Vector2F(1.f, 1.F), Vector2F(1.f, 0.f), Vector2F(0.f, 0.f), Vector2F(0.f, 1.f),
Vector2F(1.f, 1.F), Vector2F(1.f, 0.f), Vector2F(0.f, 0.f), Vector2F(0.f, 1.f)
};
Vector3F normals[] = { Vector3F::NEGUNIT_Y, Vector3F::NEGUNIT_Y, Vector3F::NEGUNIT_Y, Vector3F::NEGUNIT_Y,
Vector3F::UNIT_Y, Vector3F::UNIT_Y, Vector3F::UNIT_Y, Vector3F::UNIT_Y,
Vector3F::NEGUNIT_Z, Vector3F::NEGUNIT_Z, Vector3F::NEGUNIT_Z, Vector3F::NEGUNIT_Z,
Vector3F::UNIT_Z, Vector3F::UNIT_Z, Vector3F::UNIT_Z, Vector3F::UNIT_Z,
Vector3F::NEGUNIT_X, Vector3F::NEGUNIT_X, Vector3F::NEGUNIT_X, Vector3F::NEGUNIT_X,
Vector3F::UNIT_X, Vector3F::UNIT_X, Vector3F::UNIT_X, Vector3F::UNIT_X
};
CreateVAO(pMeshName, pShader, position, sizeof(position), indices, sizeof(indices));
switch(mType){
case ET_MESH:
Make(normals,texcoords);break;
case ET_OBJECT:
Make(normals);break;
case ET_DEBUGOBJECT:
Make(texcoords);break;
}
}
// :[
void Entity::MakeSphere(const std::string &pMeshName, Shader &pShader, s32 pSlices){
std::vector<Vector3F> vertices;
std::vector<Vector2F> texcoords;
std::vector<Vector3F> normals;
std::vector<Index> indices;
Vector3F v;
f32 angleStep = 2.f * Math::Pi / (f32)pSlices;
int midP = pSlices;
for(int i = 0; i < pSlices; ++i)
for(int j = 0; j < pSlices; ++j){
v.x = Math::Sin(angleStep * (f32)i) * Math::Sin(angleStep * (f32)j);
v.y = Math::Cos(angleStep * (f32)i);
v.z = Math::Sin(angleStep * (f32)i) * Math::Cos(angleStep * (f32)j);
vertices.push_back(v);
normals.push_back(v);
texcoords.push_back(Vector2F((f32)j / (f32)pSlices, (1.f - (f32)i) / (f32)(pSlices - 1)));
}
for(int i = 0; i < pSlices; ++i)
for(int j = 0; j < pSlices; ++j){
indices.push_back( i * (pSlices + 1) + j);
indices.push_back((i+1) * (pSlices + 1) + j);
indices.push_back((i+1) * (pSlices + 1) + (j + 1));
indices.push_back( i * (pSlices + 1) + j);
indices.push_back((i+1) * (pSlices + 1) + (j + 1));
indices.push_back( i * (pSlices + 1) + (j + 1));
}
CreateVAO(pMeshName, pShader, &vertices[0], vertices.size() * sizeof(Vector3F), &indices[0], indices.size() * sizeof(Index));
Make(&normals[0]);
}
} | 00xengine | src/Utils/Shape.cpp | C++ | mit | 3,649 |
#ifndef STRING_HPP
#define STRING_HPP
#include <sstream>
#include <vector>
#include <algorithm>
#include <cctype>
#include "StringConverter.hpp"
namespace engine {
/// \brief Ease of use class for string managment, allowing String creation from multiple types
class OOXAPI String{
public:
/// \brief Default Ctor
String(){ mString << "";}
/// \brief Copy Ctor
String(const String &s){ mString << s.str(); }
/// \brief Ctor from any data type
template<typename T> String(const T& ppValue);
/// \brief Operators allowing concatenation of different data types
template<typename T> String& operator+(const T &ppValue);
template<typename T> String& operator+=(const T &ppValue);
/// \brief Stream operator (maybe useless with above one)
friend std::ostream& operator<<(std::ostream& oss, const String &pStr);
/// \brief Cast operator in std::string
operator std::string() const;
/// \brief Explicit Cast operator in std::string
std::string str() const;
/// \brief Comparison operators
bool operator==(const std::string &pStr) const;
bool operator !=(const std::string &pStr) const;
/// \brief Affectation operators
void operator=(const std::string &pStr);
void operator=(const String &pStr);
/// \brief Returns the oss for string operations
std::ostringstream& ostr();
/// \brief Returns the String length
size_t size() const;
/// \brief Returns true if the String is empty
bool Empty() const;
/// \brief Returns true if the String is a commentary (begins with "//")
bool IsCommentary() const;
protected:
std::ostringstream mString;
};
/// \brief Vector of strings
typedef std::vector<std::string> StringVector;
/// \brief String utility functions
class OOXAPI StringUtils{
public:
/// \brief Splits a string according to different separators
/// \param pIn : input string to be splitted
/// \param pSep : different char separators
/// \param pMaxSplit : max splits operation. 0 means infinite
static StringVector SplitString(const std::string &pIn, const std::string &pSep = "\t\n ", u32 pMaxSplit = 0);
/// \brief Returns the lower case input string
static std::string ToLower(const std::string &pStr);
/// \brief Returns the upper case input string
static std::string ToUpper(const std::string &pStr);
/// \brief Returns only the extension of a complete file name
static std::string GetExtension(const std::string &pFileName);
/// \brief Returns only the file name without its extension
static std::string GetFileName(const std::string &pFileName);
/// \brief Check if a string begins by another
/// \param pStr : string to check
/// \param pStart : substring used for comparison
/// \param pLowerCase : true for a case insensitive comparison
static bool StartsWith(const std::string &pStr, const std::string &pStart, bool pLowerCase = true);
};
#include "String.inl"
}
#endif
| 00xengine | src/Utils/String.hpp | C++ | mit | 3,023 |
#ifndef SPOINTERPOLICIES_HPP
#define SPOINTERPOLICIES_HPP
#include <cstdlib>
#include "Debug/New.hpp"
namespace engine {
/// \brief Reference counting policy
template<class T>
class RefCountPolicy{
public:
RefCountPolicy() : mCounter(new int(1)) {}
/// \brief Add a reference
T* Clone(T* pPtr){
++*mCounter;
return pPtr;
}
/// \brief Substract a reference, and delete pointer if needed
void Release(T* pPtr){
if(--*mCounter == 0){
delete mCounter;
delete pPtr;
}
}
/// \brief Swap two Refcount policies
void Swap(RefCountPolicy &pRefCount){
std::swap(pRefCount.mCounter, mCounter);
}
private:
int* mCounter;
};
/// \brief Resource-Type counting policy
template<class T>
class ResourceTypePolicy{
public:
/// \brief Add a reference to resource
T* Clone(T* pPtr){
if(pPtr)
pPtr->AddRef();
return pPtr;
}
/// \brief Release a reference to resource
static void Release(T* pPtr){
if(pPtr)
pPtr->Release();
}
/// \brief Swap. Do nothing
void Swap(ResourceTypePolicy &p){
}
};
#include "Debug/NewOff.hpp"
}
#endif
| 00xengine | src/Utils/SPointerPolicies.hpp | C++ | mit | 1,168 |
#include <sstream>
#include "File.hpp"
#include "Debug/Exceptions.hpp"
#include "Debug/New.hpp"
namespace engine {
File::File() : mFileName(""){
}
File::File(const std::string &pFilename, eReadWriteMode pRwm, eFilePos pFp) {
Open(pFilename, pRwm, pFp);
}
File::~File(){
Close();
}
void File::Open(const std::string &pFilename, eReadWriteMode pRwm, eFilePos pFp){
std::ios_base::openmode mode;
switch(pRwm){
case RWM_Write:
mode = std::fstream::in | std::fstream::out | std::fstream::trunc; break;
case RWM_Open :
mode = std::fstream::in | std::fstream::out; break;
case RWM_ReadOnly :
mode = std::fstream::in; break;
default: throw LoadingFailed(pFilename, "ReadWriteMode is invalid!");
}
switch(pFp){
case FP_Top:
break;
case FP_Bottom:
mode |= std::fstream::ate; break;
default:
throw LoadingFailed(pFilename, "File Positionment value is invalid!");
}
mFileName = pFilename;
mFile.open(pFilename.c_str(), mode);
}
void File::Close(){
if(IsOpened())
mFile.close();
}
void File::Flush(){
if(IsOpened())
mFile.flush();
}
bool File::IsOpened() const{
return mFile.is_open();
}
bool File::Exists(const std::string &pFilename){
std::ifstream readFile(pFilename.c_str());
return readFile.is_open();
}
std::string File::Filename() const{
return mFileName;
}
bool File::End() const{
return mFile.eof();
}
std::string File::GetLine(){
std::string line;
getline(mFile, line);
return line;
}
std::string File::Read() const{
if(mFile){
std::stringstream buffer;
buffer << mFile.rdbuf();
std::string ret(buffer.str());
ret.push_back('\0');
return ret;
}else
throw Exception("Tried to read an inexistant file : "+mFileName);
}
/*
void File::GoTo(FilePos pos){
if(mFile.is_open())
switch(pos){
case BEG: mFile.seekg(0, ios::beg); break;
case END: mFile.seekg(0, ios::end); break;
case NEXT: JumpLine(); break;
default:break;
}
}
s
string File::GetUntil(string s, char c){
size_t pos = s.find_first_of(c);
if(pos >= 10000){
pos = 0;
ErrLog << "File : in " << s << ", " << c << " is not present!" << eol;
}
return s.substr(0,pos);
}
*/
}
| 00xengine | src/Utils/File.cpp | C++ | mit | 2,467 |
#include "Color.hpp"
namespace engine {
const Color Color::Black(0.f,0.f,0.f,1.f);
const Color Color::White(1.f,1.f,1.f,1.f);
const Color Color::Red(1.f,0.f,0.f,1.f);
const Color Color::Green(0.f,1.f,0.f,1.f);
const Color Color::Blue(0.f,0.f,1.f,1.f);
const Color Color::Magenta(1.f,0.f,1.f,1.f);
const Color Color::Cyan(0.f,1.f,1.f,1.f);
const Color Color::Yellow(1.f,1.f,0.f,1.f);
const Color Color::Orange(1.f,0.5f,0.f,1.f);
const Color Color::Grey(0.5f,0.5f,0.5f,1.f);
Color::Color(f32 R, f32 G, f32 B, f32 A) : r(R), g(G), b(B), a(A){
}
void Color::RGB(float pTab[]) const{
pTab[0] = r;
pTab[1] = g;
pTab[2] = b;
}
void Color::RGBA(float pTab[]) const{
pTab[0] = r;
pTab[1] = g;
pTab[2] = b;
pTab[3] = a;
}
void Color::RGB(f32 pR, f32 pG, f32 pB){
r = pR;
g = pG;
b = pB;
}
void Color::RGBA(f32 pR, f32 pG, f32 pB, f32 pA){
r = pR;
g = pG;
b = pB;
a = pA;
}
Color To00xColor(const sf::Color &pColor){
return Color(pColor.r / 255.f, pColor.g / 255.f, pColor.b / 255.f, pColor.a / 255.f);
}
sf::Color ToSFMLColor(const Color &pColor){
return sf::Color(static_cast<u8>(pColor.R() * 255),
static_cast<u8>(pColor.G() * 255),
static_cast<u8>(pColor.B() * 255),
static_cast<u8>(pColor.A() * 255));
}
}
| 00xengine | src/Utils/Color.cpp | C++ | mit | 1,290 |
#ifndef SINGLETON_HPP
#define SINGLETON_HPP
#include "Debug/New.hpp"
namespace engine{
/// \brief Classic Singleton class to store an object pointer in its only instance
template<class T>
class Singleton{
private:
/// \brief Pointer on object stored by singleton
static T *mSingleton;
/// \brief Copy Ctor, forbidden
Singleton(Singleton &){}
/// \brief Copy Op, forbidden
void operator=(Singleton &){}
protected:
/// \brief Default Ctor/Dtor, forbidden
Singleton(){}
~Singleton(){}
public:
/// \brief Returns a pointer on stored object
static T* Get(){
if(mSingleton == 0)
mSingleton = new T;
return (static_cast<T*> (mSingleton));
}
/// \brief Returns the reference of stored object
static T& Call(){
if(mSingleton == 0)
mSingleton = new T;
return *mSingleton;
}
/// \brief Destroy the stored object
static void Kill(){
if(mSingleton != 0){
delete mSingleton;
mSingleton = 0;
}
}
};
/// Initialisation
template<class T> T *Singleton<T>::mSingleton = 0;
}
#include "Debug/NewOff.hpp"
#endif
| 00xengine | src/Utils/Singleton.hpp | C++ | mit | 1,423 |
// CORE
#include "Core/Camera.hpp"
#include "Core/Entity.hpp"
#include "Core/Enums.hpp"
#include "Core/Frustum.hpp"
#include "Core/Image.hpp"
#include "Core/Input.hpp"
#include "Core/Resource.hpp"
#include "Core/ResourceManager.hpp"
#include "Core/Settings.hpp"
#include "Core/Window.hpp"
// DEBUG
#include "Debug/Exceptions.hpp"
#include "Debug/Logger.hpp"
#include "Debug/MemoryManager.hpp"
// MATH
#include "Math/AABB.hpp"
#include "Math/Mathlib.hpp"
#include "Math/Matrix4.hpp"
#include "Math/Quaternion.hpp"
#include "Math/Rectangle.hpp"
#include "Math/Vector2.hpp"
#include "Math/Vector3.hpp"
// RENDERER
#include "Renderer/Light.hpp"
#include "Renderer/Renderer.hpp"
#include "Renderer/Shader.hpp"
#include "Renderer/Text.hpp"
#include "Renderer/Texture.hpp"
#include "Renderer/VAO.hpp"
#include "Renderer/VBO.hpp"
// UTILS
#include "Utils/Clock.hpp"
#include "Utils/File.hpp"
#include "Utils/Keys.hpp"
#include "Utils/SPointer.hpp"
#include "Utils/Shared.hpp"
#include "Utils/Singleton.hpp"
#include "Utils/String.hpp"
#include "Utils/StringConverter.hpp"
| 00xengine | src/Engine.hpp | C++ | mit | 1,071 |
#ifndef TEXT_HPP
#define TEXT_HPP
#include "Math/Vector2.hpp"
#include "Utils/Color.hpp"
namespace engine {
/// \brief Wrapper class for SFML Text
class OOXAPI Text{
public:
Text();
Text( const Vector2I &pPosition,
const std::string &pText,
const Color &pColor = Color::Black,
const sf::Font &pFont = sf::Font::GetDefaultFont(),
u16 pSize = 15,
bool pBold = false,
bool pItalic = false);
/// \brief Add this text to the renderer text drawlist
void Draw();
/// \brief Change the text string
void SetText(const std::string &pText);
/// \brief Change the text position
void SetPosition(const Vector2I &pPos);
void SetPosition(s16 x, s16 y);
/// \brief Change the text font
void SetFont(const std::string &pFontName);
/// \brief Change the text color
void SetColor(const Color &pColor);
/// \brief Change the text size
void SetSize(u16 pSize);
/// \brief Make the text bold or not
void SetBold(bool pVal);
/// \brief Make the text Italic or not
void SetItalic(bool pVal);
/// Getters
Vector2I GetPosition() const { return To00xVector2I(mText.GetPosition()); }
Color GetColor() const { return To00xColor(mText.GetColor()); }
u16 GetSize() const { return mText.GetCharacterSize(); }
std::string GetText() const { return mText.GetString(); }
const sf::Text& GetSFMLText() const { return mText; }
private:
sf::Text mText; /// SFML text used to render text
/// Text Style, keep record for changes
bool mBold;
bool mItalic;
/// Internal function called after a SetBold/Italic function
void ChangeTextStyle();
};
}
#endif
| 00xengine | src/Renderer/Text.hpp | C++ | mit | 1,623 |
#ifndef RENDERER_HPP
#define RENDER_HPP
#include <map>
#include "Text.hpp"
#include "Texture.hpp"
#include "Math/Matrix4.hpp"
#include "Utils/Singleton.hpp"
#include "Core/Enums.hpp"
namespace engine {
class Color;
class Shader;
class Entity;
class Object;
class Mesh;
class DebugObject;
class Window;
class Camera;
struct RendererSpecs{
/// Max and User Wanted Anisotropy Levels
u32 mMaximumAnisotropy;
u32 mWantedAnisotropy;
/// Max and User Wanted Anti-Aliasing Levels
s16 mMaximumMultiSamples;
s16 mWantedMultiSamples;
/// BackFace Culling Face
u32 mCullingFace;
/// Field of View
f32 mFOV;
/// Near & Far plane
f32 mNearPlane;
f32 mFarPlane;
/// Ambient Color
Color mAmbientColor;
/// Wireframe mode
bool mWireframe;
bool mWireframeChange;
/// Vertical Synchronisation
bool mVsync;
};
class OOXAPI Renderer : public Singleton<Renderer>{
friend class Singleton<Renderer>;
public:
/// \brief Initialize the Renderer from Window
/// \param pWindow : Window used to Render
void Init(Window &pWindow);
/// \brief Function called before rendering every frame
/// \param pColor : Window background color
void BeginScene(const Color &pColor) const;
/// \brief Function called right after rendering every frame
void EndScene();
/// \brief Returns a pointer on the associated window
const Window* GetWindow() { return mWindow; }
/// \brief Returns the renderer specifications
const RendererSpecs& GetSpecifications() const { return mSpecs; }
// Functions used to render a drawable object with the renderer
/// \brief Add a Mesh to the next frame drawing list
void DrawMesh(Mesh* pEntity);
/// \brief Add an Object to the next frame drawing list
void DrawObject(Object* pEntity);
/// \brief Add a DebugObject to the next frame drawing list
void DrawDebugObject(DebugObject* pEntity);
/// \brief Add a Text to the next frame drawing list
void DrawText(Text* pText);
/// \brief Render the drawable objects of the current frame
void Render();
/// \brief Change the Field of View
void SetFOV(f32 pFov);
/// \brief Change the Wireframe Mode
void WireframeMode(bool pVal);
/// \brief Resize the Window with the associated window new Width and Height
void Resize();
/// Matrix
/// \brief Change the current 2D Projection Matrix
void Set2DProjectionMatrix(const Matrix4 &pProj) { m2DProjectionMatrix = pProj; }
/// \brief Change the current 3D Projection Matrix
void Set3DProjectionMatrix(const Matrix4 &pProj) { m3DProjectionMatrix = pProj; }
/// \brief Change the current 3D View Matrix. Changes also the ViewProj and Normal Matrices accordingly
void Set3DViewMatrix(const Matrix4 &pView){
m3DViewMatrix = pView;
m3DViewProjMatrix = m3DViewMatrix * m3DProjectionMatrix;
m3DNormalMatrix = m3DViewMatrix.Inverse();
m3DNormalMatrix = m3DNormalMatrix.Transpose();
}
/// Getters
const Matrix4& Get2DProjectionMatrix() const { return m2DProjectionMatrix; }
const Matrix4& Get3DProjectionMatrix() const { return m3DProjectionMatrix; }
const Matrix4& Get3DViewProjMatrix() const { return m3DViewProjMatrix; }
const Matrix4& Get3DNormalMatrix() const { return m3DNormalMatrix; }
const Matrix4& Get3DViewMatrix() const { return m3DViewMatrix; }
/// Camera
/// \brief Set current camera from pointer
void SetCamera(Camera* pCamera) { mCamera = pCamera; }
/// \brief Returns a pointer on the current camera
const Camera* GetCamera() const { return mCamera; }
private:
/// Private Ctor/Dtor (Singleton)
Renderer();
~Renderer();
/// Window
Window* mWindow;
u32 mWindowWidth, mWindowHeight;
/// Camera
Camera* mCamera;
/// Specifications
RendererSpecs mSpecs;
/// Vector containing Objects to be drawn next frame
typedef std::vector<Object*> ObjectMap;
ObjectMap mObjectMap;
ObjectMap::iterator mObjectMapIt;
/// Vector containing Meshes to be drawn next frame
typedef std::vector<Mesh*> MeshMap;
MeshMap mMeshMap;
MeshMap::iterator mMeshMapIt;
/// Vector containing DebugObjects to be drawn next frame
typedef std::vector<DebugObject*> DebugObjectMap;
DebugObjectMap mDebugObjectMap;
DebugObjectMap::iterator mDebugObjectMapIt;
/// Number of drawed entities every frame
Text mEntityNumberText;
u16 mEntityNumber, mLastFrameEntityNumber;
/// Vector containing Objects to be drawn next frame
typedef std::vector<Text*> TextMap;
TextMap mTextMap;
TextMap::iterator mTextMapIt;
/// Matrices used by the renderer
Matrix4 m3DViewMatrix, m3DProjectionMatrix, m3DViewProjMatrix, m3DNormalMatrix;
Matrix4 m2DProjectionMatrix;
/// FUNCTIONS
/// Specific drawable object rendering functions
/// \brief Text Rendering
void RenderTexts();
/// \brief Objects Rendering
void RenderObjects();
/// \brief Meshes Rendering
void RenderMeshes();
/// \brief DebugObject Rendering
void RenderDebugObjects();
};
}
#endif
| 00xengine | src/Renderer/Renderer.hpp | C++ | mit | 5,098 |
#include "VBO.hpp"
#include "Utils/Color.hpp"
#include "Utils/String.hpp"
#include "Debug/Exceptions.hpp"
#include "Debug/New.hpp"
namespace engine {
GLenum GetUsage(eBufferUsage usage){
GLenum ret;
switch(usage){
case BU_Static: ret = GL_STATIC_DRAW; break;
case BU_Stream: ret = GL_STREAM_DRAW; break;
case BU_Dynamic: ret = GL_DYNAMIC_DRAW; break;
}
return ret;
}
VBO::VBO() : mVbo(0), mType(BT_VERTEX), mUsage(BU_Static){
}
VBO::~VBO(){
if(mVbo)
Destroy();
}
void VBO::Destroy(){
glDeleteBuffers(1, &mVbo);
}
void VBO::Generate(const Index* pIndices, u32 pSize, eBufferUsage usage){
// On élimine les buffers contenus précédement
if(mVbo)
Destroy();
// On génère le bufer
glGenBuffers(1, &mVbo);
// On Lock le Buffer en mémoire et on le remplit
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mVbo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, pSize, pIndices, GetUsage(usage));
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
// On change le type en IBO et l'usage
mType = BT_INDEX;
mUsage = usage;
}
void VBO::Generate(const Vector3F* pVector, u32 pSize, eBufferUsage usage){
// On élimine les buffers contenus précédement
if(mVbo)
Destroy();
// On génère le bufer
glGenBuffers(1, &mVbo);
// On Lock le Buffer en mémoire et on le remplit
glBindBuffer(GL_ARRAY_BUFFER, mVbo);
glBufferData(GL_ARRAY_BUFFER, pSize, pVector, GetUsage(usage));
glBindBuffer(GL_ARRAY_BUFFER, 0);
// changement possible de l'usage
mUsage = usage;
}
void VBO::Generate(const Vector2F* pVector, u32 pSize, eBufferUsage usage){
// On élimine les buffers contenus précédement
if(mVbo)
Destroy();
// On génère le bufer
glGenBuffers(1, &mVbo);
// On Lock le Buffer en mémoire et on le remplit
glBindBuffer(GL_ARRAY_BUFFER, mVbo);
glBufferData(GL_ARRAY_BUFFER, pSize, pVector, GetUsage(usage));
glBindBuffer(GL_ARRAY_BUFFER, 0);
// changement possible de l'usage
mUsage = usage;
}
void VBO::Update(const Vector3F* pVector, u32 pSize){
// Check si le buffer est dynamic
//if(mUsage != BU_Dynamic)
// throw Exception("VBO : Tried to Update a static buffer.");
glBindBuffer(GL_ARRAY_BUFFER, mVbo);
glBufferData(GL_ARRAY_BUFFER, 0, NULL, GetUsage(mUsage));
glBufferData(GL_ARRAY_BUFFER, pSize, pVector, GetUsage(mUsage));
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
void VBO::Update(const Vector2F* pVector, u32 pSize){
// Check si le buffer est dynamic
//if(mUsage != BU_Dynamic)
// throw Exception("VBO : Tried to Update a static buffer.");
glBindBuffer(GL_ARRAY_BUFFER, mVbo);
glBufferData(GL_ARRAY_BUFFER, 0, NULL, GetUsage(mUsage));
glBufferData(GL_ARRAY_BUFFER, pSize, pVector, GetUsage(mUsage));
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
void VBO::Update(const Index* pVector, u32 pSize){
// Check si le buffer est dynamic
//if(mUsage != BU_Dynamic)
// throw Exception("VBO : Tried to Update a static buffer.");
glBindBuffer(GL_ARRAY_BUFFER, mVbo);
glBufferData(GL_ARRAY_BUFFER, 0, NULL, GetUsage(mUsage));
glBufferData(GL_ARRAY_BUFFER, pSize, pVector, GetUsage(mUsage));
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
}
| 00xengine | src/Renderer/VBO.cpp | C++ | mit | 3,152 |
#ifndef TEXTURE_HPP
#define TEXTURE_HPP
#include "Core/Image.hpp"
#include "Math/Rectangle.hpp"
namespace engine {
/// \brief Wrapper class for OpenGL Texture, load from Image only
class OOXAPI Texture{
public:
Texture();
~Texture();
/// \brief Load the OpenGL Texture from an Image
/// \param pImage : Image to use
/// \param pSubRect : SubRect optionnel (partie d'une image)
void LoadFromImage(const Image &pImage, const Rectangle &pSubRect = Rectangle(0,0,0,0));
/// \brief Bind the texture to OpenGL Render State
void Bind() const;
/// \brief Unbind the texture
void UnBind() const;
/// \brief Destroy the OpenGL Texture
void Destroy();
private:
GLuint mTexture; /// Texture ID
};
}
#endif
| 00xengine | src/Renderer/Texture.hpp | C++ | mit | 732 |
#ifndef SHADER_HPP
#define SHADER_HPP
#include "Core/Resource.hpp"
#include "Utils/SPointer.hpp"
#include "Utils/Shared.hpp"
#include "Math/Vector2.hpp"
#include "Math/Vector3.hpp"
namespace engine {
class Color;
class Matrix4;
/// \brief Wrapper class for GLSL Shader Program, with Vertex/Fragment/Geometry shader loading and compilation
class OOXAPI Shader : public IResource{
public:
Shader();
~Shader();
/// \brief Destroy the program
void Destroy();
/// \brief Compile the shader from sources
/// \param pVSName : Vertex Shader source file name
/// \param pFSName : Fragment Shader source file name
/// \param pGSName : Geometry Shader source file name
void Compile(const std::string &pVSName, const std::string &pFSName, const std::string &pGSName = "");
/// \brief Bind the shader to the OpenGL State
void Bind() const;
/// \brief Unbind the Shader
void UnBind() const;
/// \brief Returns the Shader ID
GLuint GetProgram() { return mProgram; }
/// Send/Access functions for sending uniform variables
/// \brief Matrix 4x4
/// \param pVarName : Variable name in shader source
/// \param pMatrix : matrix to send
void SendMatrix4(const std::string &pVarName, const Matrix4 &pMatrix);
/// \brief Vector 3
/// \param pVarName : Variable name in shader source
/// \param pVector : vector to send
void SendVector3(const std::string &pVarName, const Vector3F &pVector);
/// \brief Vector 2
/// \param pVarName : Variable name in shader source
/// \param pVector : vector to send
void SendVector2(const std::string &pVarName, const Vector2F &pVector);
/// \brief Color
/// \param pVarName : Variable name in shader source
/// \param pColor : color to send
void SendColor(const std::string &pVarName, const Color &pColor);
/// \brief Float
/// \param pVarName : Variable name in shader source
/// \param pVar : float to send
void SendFloat(const std::string &pVarName, f32 pVar);
private:
/// \brief Private method used by Compile to load a Vertex Shader from source
void LoadVertexShader(const std::string &pFilename);
/// \brief Private method used by Compile to load a Fragment Shader from source
void LoadFragmentShader(const std::string &pFilename);
/// \brief Private method used by Compile to load a Geometry Shader from source
void LoadGeometryShader(const std::string &pFilename);
GLuint mProgram; /// Program ID
GLuint mVShader; /// Vertex Shader ID
GLuint mFShader; /// Fragment Shader ID
GLuint mGShader; /// Geometry Shader ID
};
typedef SPointer<Shader, ResourceTypePolicy> ShaderPtr;
}
#endif
| 00xengine | src/Renderer/Shader.hpp | C++ | mit | 2,656 |
#include "Shader.hpp"
#include "Core/ResourceManager.hpp"
//#include "Core/DataManager.hpp"
#include "Math/Matrix4.hpp"
#include "Utils/Color.hpp"
#include "Utils/File.hpp"
#include "Utils/String.hpp"
#include "Debug/Exceptions.hpp"
#include "Debug/New.hpp"
#include <iostream>
namespace engine {
Shader::Shader() : mProgram(0), mVShader(0), mFShader(0), mGShader(0){
}
Shader::~Shader(){
Destroy();
}
void Shader::Destroy(){
if(mProgram)
glDeleteProgram(mProgram);
}
void Shader::LoadVertexShader(const std::string &pFilename){
// Creation des shaders
mVShader = glCreateShader(GL_VERTEX_SHADER);
// Récupération de la source
std::string filePath = ResourceManager::Call().FindFile(pFilename, "Shader");
if(filePath == "0")
throw Exception(String("Vertex Shader file \"")+pFilename+"\" does not exist. Double check file path!");
File vFile(filePath);
std::string vSourceStr = vFile.Read();
const char* vSource = vSourceStr.c_str();
glShaderSource(mVShader, 1, &vSource, NULL);
// Compilation
glCompileShader(mVShader);
// Vérification
GLint error;
glGetShaderiv(mVShader, GL_COMPILE_STATUS, &error);
if(error != GL_TRUE){
char log[1024];
glGetShaderInfoLog(mVShader, 1024, NULL, log);
glDeleteShader(mVShader);
if(mFShader)
glDeleteShader(mFShader);
if(mGShader)
glDeleteShader(mGShader);
throw Exception(String("Vertex Shader Compilation Error (\"")+pFilename+"\") :\n"+log);
}
}
void Shader::LoadFragmentShader(const std::string &pFilename){
// Creation des shaders
mFShader = glCreateShader(GL_FRAGMENT_SHADER);
// Récupération de la source
std::string filePath = ResourceManager::Call().FindFile(pFilename, "Shader");
if(filePath == "0")
throw Exception(String("Fragment Shader file \"")+pFilename+"\" does not exist. Double check file path!");
File fFile(filePath);
std::string fSourceStr = fFile.Read();
const char* fSource = fSourceStr.c_str();
glShaderSource(mFShader, 1, &fSource, NULL);
// Compilation
glCompileShader(mFShader);
// Vérification
GLint error;
glGetShaderiv(mFShader, GL_COMPILE_STATUS, &error);
if(error != GL_TRUE){
char log[1024];
glGetShaderInfoLog(mFShader, 1024, NULL, log);
if(mVShader)
glDeleteShader(mVShader);
glDeleteShader(mFShader);
if(mGShader)
glDeleteShader(mGShader);
throw Exception(String("Fragment Shader Compilation Error (\"")+pFilename+"\") :\n"+log);
}
}
void Shader::LoadGeometryShader(const std::string &pFilename){
// Creation des shaders
mGShader = glCreateShader(GL_GEOMETRY_SHADER);
// Récupération de la source
std::string filePath = ResourceManager::Call().FindFile(pFilename, "Shader");
if(filePath == "0")
throw Exception(String("Geometry Shader file \"")+pFilename+"\" does not exist. Double check file path!");
File gFile(filePath);
std::string gSourceStr = gFile.Read();
const char* gSource = gSourceStr.c_str();
glShaderSource(mGShader, 1, &gSource, NULL);
// Compilation
glCompileShader(mGShader);
// Vérification
GLint error;
glGetShaderiv(mGShader, GL_COMPILE_STATUS, &error);
if(error != GL_TRUE){
char log[1024];
glGetShaderInfoLog(mGShader, 1024, NULL, log);
if(mVShader)
glDeleteShader(mVShader);
if(mFShader)
glDeleteShader(mFShader);
glDeleteShader(mGShader);
throw Exception(String("Geometry Shader Compilation Error (\"")+pFilename+"\") :\n"+log);
}
}
void Shader::Compile(const std::string &pVSName, const std::string &pFSName, const std::string &pGSName){
std::string all = String(pVSName)+pFSName+pGSName;
Shader* tmp = ResourceManager::Call().Get<Shader>(all);
if(tmp != 0){
//Shader existe deja, on copie ses identifiants dans celui ci
mProgram = tmp->mProgram;
}else{
//Shader n'existe pas, on le cree
// Ajout du shader au ResourceManager
ResourceManager::Call().Add(all, this);
// Chargement des fichiers shaders
LoadVertexShader(pVSName);
LoadFragmentShader(pFSName);
if(!pGSName.empty())
LoadGeometryShader(pGSName);
// Creation du shader mProgram
mProgram = glCreateProgram();
// Linkage des deux shaders précédemment créés
glAttachShader(mProgram, mVShader);
glAttachShader(mProgram, mFShader);
if(mGShader)
glAttachShader(mProgram, mGShader);
// Linkage du mProgramme a OGL
glLinkProgram(mProgram);
GLint error;
glGetProgramiv(mProgram, GL_LINK_STATUS, &error);
if(!error){
char log[1024];
glGetProgramInfoLog(mProgram, 1024, NULL, log);
if(mVShader)
glDeleteShader(mVShader);
if(mFShader)
glDeleteShader(mFShader);
if(mGShader)
glDeleteShader(mGShader);
throw Exception(String("Shader Link Error :\n")+log);
}
// Destruction des Shaders. ils sont maintenant dans le program
glDeleteShader(mVShader);
glDeleteShader(mFShader);
if(mGShader)
glDeleteShader(mGShader);
// Attribution des texCoords
glUseProgram(mProgram);
glUniform1i(glGetUniformLocation(mProgram, "tex"), 0);
glBindFragDataLocation(mProgram, 0, "finalColor");
glUseProgram(0);
}
}
void Shader::Bind() const{
glUseProgram(mProgram);
}
void Shader::UnBind() const{
glUseProgram(0);
}
void Shader::SendMatrix4(const std::string &pVarName, const Matrix4 &pMatrix){
glUniformMatrix4fv(glGetUniformLocation(mProgram, pVarName.c_str()), 1, GL_FALSE, pMatrix);
#ifdef _DEBUG
GLenum error = GL_NO_ERROR;
if((error = glGetError()) != GL_NO_ERROR){
throw Exception(String("OpenGL Error: \"")+GetGLErrorStr(error)+"\" in function \"SendMatrix4\"\n\tDoes \""+pVarName+"\" exists or has the right type?");
}
#endif
}
void Shader::SendVector3(const std::string &pVarName, const Vector3F &pVector){
float toSend[3];
pVector.XYZ(toSend);
glUniform3fv(glGetUniformLocation(mProgram, pVarName.c_str()), 1, toSend);
#ifdef _DEBUG
GLenum error = GL_NO_ERROR;
if((error = glGetError()) != GL_NO_ERROR){
throw Exception(String("OpenGL Error: \"")+GetGLErrorStr(error)+"\" in function \"SendVector3\"\n\tDoes \""+pVarName+"\" exists or has the right type?");
}
#endif
}
void Shader::SendVector2(const std::string &pVarName, const Vector2F &pVector){
float toSend[2];
pVector.XY(toSend);
glUniform2fv(glGetUniformLocation(mProgram, pVarName.c_str()), 1, toSend);
#ifdef _DEBUG
GLenum error = GL_NO_ERROR;
if((error = glGetError()) != GL_NO_ERROR){
throw Exception(String("OpenGL Error: \"")+GetGLErrorStr(error)+"\" in function \"SendVector2\"\n\tDoes \""+pVarName+"\" exists or has the right type?");
}
#endif
}
void Shader::SendColor(const std::string &pVarName, const Color &pColor){
float toSend[4];
pColor.RGBA(toSend);
glUniform4fv(glGetUniformLocation(mProgram, pVarName.c_str()), 1, toSend);
#ifdef _DEBUG
GLenum error = GL_NO_ERROR;
if((error = glGetError()) != GL_NO_ERROR){
throw Exception(String("OpenGL Error: \"")+GetGLErrorStr(error)+"\" in function \"SendColor\"\n\tDoes \""+pVarName+"\" exists or has the right type?");
}
#endif
}
void Shader::SendFloat(const std::string &pVarName, f32 pVar){
glUniform1f(glGetUniformLocation(mProgram, pVarName.c_str()), pVar);
#ifdef _DEBUG
GLenum error = GL_NO_ERROR;
if((error = glGetError()) != GL_NO_ERROR){
throw Exception(String("OpenGL Error: \"")+GetGLErrorStr(error)+"\" in function \"SendFloat\"\n\tDoes \""+pVarName+"\" exists or has the right type?");
}
#endif
}
}
| 00xengine | src/Renderer/Shader.cpp | C++ | mit | 7,449 |
#ifndef VAO_HPP
#define VAO_HPP
#include "VBO.hpp"
#include "Core/Resource.hpp"
#include "Utils/SPointer.hpp"
namespace engine {
class Shader;
class Color;
class VAO;
typedef SPointer<VAO, ResourceTypePolicy> VAOPtr;
/// \brief Interface Wrapper Class for OpenGL VAO
/// - Use it as it is for only Vertice Position/Indices
/// - Use one of the inherited class (ColorVAO, ColorMesh, TexMesh) for advanced uses
class OOXAPI VAO : public IResource{
public:
VAO();
~VAO();
/// \brief Generate the VAO and its included VBO from Vertices/Indices arrays
/// \param pShader : pointer on the Shader used to draw the VAO
/// \param pVertices : Array of Positions (Vector3F)
/// \param pVerticeSize : Size of associated arrays
/// \param pIndices : Array of Indices (Index)
/// \param pIndiceSize : Size of associated arrays
/// \param pBu : VBO Usage
void Generate(Shader* pShader, const Vector3F* pVertices, u32 pVerticeSize, const Index* pIndices, u32 pIndiceSize, eBufferUsage pBu = BU_Static);
/// \brief Update an already dynamically created VAO with new vertices/indices data
/// \param pVertices : Array of Positions (Vector3F)
/// \param pVerticeSize : Size of associated arrays
/// \param pIndices : Array of Indices (Index)
/// \param pIndiceSize : Size of associated arrays
void Update(const Vector3F* pVertices, u32 pVerticeSize, const Index* pIndices, u32 pIndiceSize);
/// \brief Copy a VAO
void CopyVAO(const VAOPtr& pVao);
/// \brief Destroy the VAO and associated VBO
void Destroy();
/// \brief Bind the VAO to OpenGL Render State
void Bind() const;
/// \brief Unbind the VAO
void UnBind() const;
/// Getters
const GLuint GetVAO() const { return mVao; }
const VBO GetVertices() const { return mVbo; }
const VBO GetIndices() const { return mIbo; }
const u32 GetVertexCount() const { return mVCount; }
const u32 GetIndexCount() const { return mICount; }
/// Setters
void SetVAO(GLuint pVao) { mVao = pVao; }
void SetVertices(VBO pVbo) { mVbo = pVbo; }
void SetIndices(VBO pIbo) { mIbo = pIbo; }
void SetVertexCount(u32 pVc) { mVCount = pVc; }
void SetIndexCount(u32 pIc) { mICount = pIc; }
/// \brief Returns if the VAO possesses indices
bool HasIndices() const { return mHasIndices; }
protected:
GLuint mVao; /// VAO ID
VBO mVbo; /// Vertice Position VBO
VBO mIbo; /// Indice VBO
u32 mVCount; /// Vertices number
u32 mICount; /// Indices number
bool mHasIndices; /// True if VAO possesses indices
};
/// \brief VAO with additionnals VBOs used for Texture Coordinates and Normals
class OOXAPI TextureMesh : public VAO{
public:
/// \brief Generate the Normal VBO with given data
/// \param pNormals : Vector3F Array for normal coordinates
/// \param pSize : size of the above array
/// \param pShader : shader used for VAO rendering
/// \param pBu : VBO Usage Flag
void GenerateNormals(const Vector3F* pNormals, u32 pSize, Shader* pShader, eBufferUsage pBu = BU_Static);
/// \brief Generate the TexCoords VBO with given data
/// \param pTexCoords : Vector2F Array for texture coordinates
/// \param pSize : size of the above array
/// \param pShader : shader used for VAO rendering
/// \param pBu : VBO Usage Flag
void GenerateTexCoords(const Vector2F* pTexCoords, u32 pSize, Shader* pShader, eBufferUsage pBu = BU_Static);
/// \brief Update an already dynamically created Normal VBO with new data
/// \param pNormals : Array of Vector3F for normal coordinates
/// \param pSize : Size of above array
void UpdateNormals(const Vector3F* pNormals, u32 pSize);
/// \brief Update an already dynamically created Texcoords VBO with new data
/// \param pTexCoords : Array of Vector2F for texture coordinates
/// \param pSize : Size of above array
void UpdateTexCoords(const Vector2F* pTexCoords, u32 pSize);
private:
VBO mNormals;
VBO mTexCoords;
};
typedef SPointer<TextureMesh, ResourceTypePolicy> TexMeshPtr;
/// \brief VAO with an additionnal VBO used for Normals
class OOXAPI ColorMesh : public VAO{
public:
/// \brief Generate the Normal VBO with given data
/// \param pNormals : Vector3F Array for normal coordinates
/// \param pSize : size of the above array
/// \param pShader : shader used for VAO rendering
/// \param pBu : VBO Usage Flag
void GenerateNormals(const Vector3F* pNormals, u32 pSize, Shader* pShader, eBufferUsage pBu = BU_Static);
/// \brief Update an already dynamically created Normal VBO with new data
/// \param pNormals : Array of Vector3F for normal coordinates
/// \param pSize : Size of above array
void UpdateNormals(const Vector3F* pNormals, u32 pSize);
private:
VBO mNormals;
};
typedef SPointer<ColorMesh, ResourceTypePolicy> ColorMeshPtr;
/// \brief VAO with an additionnal VBO used for Texture Coordinates
class OOXAPI ColorVAO : public VAO{
public:
/// \brief Generate the TexCoords VBO with given data
/// \param pTexCoords : Vector2F Array for texture coordinates
/// \param pSize : size of the above array
/// \param pShader : shader used for VAO rendering
/// \param pBu : VBO Usage Flag
void GenerateTexCoords(const Vector2F* pTexCoords, u32 pSize, Shader* pShader, eBufferUsage pBu = BU_Static);
/// \brief Update an already dynamically created Texcoords VBO with new data
/// \param pTexCoords : Array of Vector2F for texture coordinates
/// \param pSize : Size of above array
void UpdateTexCoords(const Vector2F* pTexCoords, u32 pSize);
private:
VBO mTexCoords;
};
typedef SPointer<ColorVAO, ResourceTypePolicy> ColorVAOPtr;
}
#endif
| 00xengine | src/Renderer/VAO.hpp | C++ | mit | 5,636 |
#ifndef LIGHT_HPP
#define LIGHT_HPP
#include "Utils/Color.hpp"
#include "Math/Vector3.hpp"
namespace engine{
/// \brief Light type. Used with shaders
enum LightType{
LTPoint,
LTDirectionnal,
LTSpot
};
/// \brief Light class containing only informations used by shaders
class Light{
public:
/// \brief Empty Ctor, initialize with default Light
Light() : mType(LTPoint),
mAmbient(Color::Black),
mDiffuse(Color::White),
mSpecular(Color::Black),
mPosition(Vector3F::ZERO),
mDirection(Vector3F::NEGUNIT_Y),
mRange(5),
mFalloff(0),
mAttenuation0(0.f),
mAttenuation1(1.f),
mAttenuation2(0.5f),
mTheta(0),
mPhi(0)
{
}
/// \brief Light Update
void Update();
/// \brief Enable or Disable the Light
void Enable(bool pVal) { mIsOn = pVal; }
/// \brief Setters
void SetPosition(const Vector3F &pPos) { mPosition = pPos; }
void SetDirection(const Vector3F &pDir) { mDirection = pDir; }
void SetRange(f32 pRange) { mRange = pRange; }
void SetFalloff(f32 pFalloff) { mFalloff = pFalloff; }
void SetAttenuationConstant(f32 pAtt) { mAttenuation0 = pAtt; }
void SetAttenuationLinear(f32 pAtt) { mAttenuation1 = pAtt; }
void SetAttenuationQuadratic(f32 pAtt) { mAttenuation2 = pAtt; }
void SetTheta(f32 pTheta) { mTheta = pTheta; }
void SetPhi(f32 pPhi) { mPhi = pPhi; }
void SetAmbient(Color pColor) { mAmbient = pColor; }
void SetDiffuse(Color pColor) { mDiffuse = pColor; }
void SetSpecular(Color pColor) { mSpecular = pColor; }
void SetType(LightType pType) { mType = pType; }
/// \brief Getters
f32 GetRange() const{ return mRange; }
f32 GetFalloff() const{ return mFalloff; }
f32 GetAttenuationConstant() const{ return mAttenuation0; }
f32 GetAttenuationLinear() const{ return mAttenuation1; }
f32 GetAttenuationQuadratic() const{ return mAttenuation2; }
f32 GetTheta() const{ return mTheta; }
f32 GetPhi() const{ return mPhi; }
LightType GetType() const{ return mType; }
Color GetAmbient() const{ return mAmbient; }
Color GetDiffuse() const{ return mDiffuse; }
Color GetSpecular() const{ return mSpecular; }
Vector3F GetPosition() const{ return mPosition; }
Vector3F GetDirection() const{ return mDirection; }
private:
bool mIsOn;
LightType mType;
Color mAmbient, mDiffuse, mSpecular;
Vector3F mPosition, mDirection;
f32 mRange, mFalloff;
f32 mAttenuation0, mAttenuation1, mAttenuation2;
f32 mTheta, mPhi;
};
}
#endif | 00xengine | src/Renderer/Light.hpp | C++ | mit | 2,584 |
#include "Text.hpp"
#include "Renderer.hpp"
#include "Debug/Logger.hpp"
#include "Debug/New.hpp"
namespace engine {
Text::Text() : mBold(false), mItalic(false){
}
Text::Text( const Vector2I &pPosition, const std::string &pText, const Color &pColor, const sf::Font &pFont, u16 pSize, bool pBold, bool pItalic){
mText.SetPosition(ToSFMLVector2f(pPosition));
mText.SetString(pText);
mText.SetColor(ToSFMLColor(pColor));
mText.SetFont(pFont);
mText.SetCharacterSize(pSize);
mBold = pBold;
mItalic = pItalic;
ChangeTextStyle();
}
void Text::SetText(const std::string &pText){
mText.SetString(pText);
}
void Text::SetColor(const Color &pColor){
mText.SetColor(ToSFMLColor(pColor));
}
void Text::SetFont(const std::string &pFont){
sf::Font font;
if(!font.LoadFromFile(pFont))
OmniLog << "Text : Font loading error, \"" << pFont << "\" does not exist, not changing anything" << eol;
else
mText.SetFont(font);
}
void Text::SetPosition(const Vector2I &pPos){
mText.SetPosition(ToSFMLVector2f(pPos));
}
void Text::SetPosition(s16 x, s16 y){
mText.SetPosition(x,y);
}
void Text::SetSize(u16 pSize){
mText.SetCharacterSize(pSize);
}
void Text::SetBold(bool pVal){
mBold = pVal;
ChangeTextStyle();
}
void Text::SetItalic(bool pVal){
mItalic = pVal;
ChangeTextStyle();
}
void Text::ChangeTextStyle(){
static u8 style;
style = 0;
style += mBold ? 1 : 0;
style += mItalic ? 2 : 0;
mText.SetStyle(style);
}
void Text::Draw(){
Renderer::Call().DrawText(this);
}
}
| 00xengine | src/Renderer/Text.cpp | C++ | mit | 1,541 |
#ifndef VBO_HPP
#define VBO_HPP
#include "Utils/Shared.hpp"
#include "Math/Vector3.hpp"
#include "Math/Vector2.hpp"
namespace engine{
class Color;
/// \brief Differents types of Buffer
enum eBufferType{
BT_VERTEX,
BT_INDEX,
BT_NORMALS
};
/// \brief Usage Flag for VBO creation
enum eBufferUsage{
BU_Static,
BU_Stream,
BU_Dynamic
};
/// \brief Return GL Usage Flag from eBufferUsage
GLenum GetUsage(eBufferUsage);
/// \brief OLD. Erase?
struct Vertex{
Vector3F position;
Vector3F color;
Vector2F texcoord;
};
/// \brief Just for usage
typedef u32 Index;
/// \brief Wrapper class for OpenGL VBO
class OOXAPI VBO{
public:
VBO();
~VBO();
/// \brief Generate Buffer from Indices (u32)
/// \param pIndices : Index array to place in the buffer
/// \param pSize : Size of this array
/// \param pUsage : Usage Flag for vbo creation
void Generate(const Index* pIndices, u32 pSize, eBufferUsage pUsage = BU_Static);
/// \brief Generate Buffer from 3D Float Vector
/// \param pVector : Vector array to place in the buffer
/// \param pSize : Size of this array
/// \param pUsage : Usage Flag for vbo creation
void Generate(const Vector3F* pVector, u32 pSize, eBufferUsage pUsage = BU_Static);
/// \brief Generate Buffer from 2D Float Vector
/// \param pVector : Vector array to place in the buffer
/// \param pSize : Size of this array
/// \param pUsage : Usage Flag for vbo creation
void Generate(const Vector2F* pVector, u32 pSize, eBufferUsage pUsage = BU_Static);
/// \brief Update an already dynamically created 3D Float Vector VBO with new Data
/// \param pVector : Vector array to place in the buffer
/// \param pSize : Size of this array
void Update(const Vector3F* pVector, u32 pSize);
/// \brief Update an already dynamically created 2D Float Vector VBO with new Data
/// \param pVector : Vector array to place in the buffer
/// \param pSize : Size of this array
void Update(const Vector2F* pVector, u32 pSize);
/// \brief Update an already dynamically created Index VBO with new Data
/// \param pVector : Index array to place in the buffer
/// \param pSize : Size of this array
void Update(const Index* pVector, u32 pSize);
/// \brief Destroy the VBO in OpenGL Memory
void Destroy();
/// \brief Returns the OGL Buffer
GLuint GetBuffer() { return mVbo; }
private:
GLuint mVbo; /// Buffer ID
eBufferType mType; /// Buffer Type
eBufferUsage mUsage; /// Usage Flag
};
}
#endif
| 00xengine | src/Renderer/VBO.hpp | C++ | mit | 2,504 |
#include "VAO.hpp"
#include "Shader.hpp"
#include "Utils/Color.hpp"
#include "Utils/String.hpp"
#include "Debug/Exceptions.hpp"
namespace engine {
VAO::VAO() : mVao(0), mVCount(0), mICount(0), mHasIndices(false){
}
VAO::~VAO(){
if(mIbo.GetBuffer())
mIbo.Destroy();
if(mVbo.GetBuffer())
mVbo.Destroy();
if(mVao)
Destroy();
}
void VAO::CopyVAO(const VAOPtr& pVao){
mHasIndices = pVao->HasIndices();
mVao = pVao->GetVAO();
mVbo = pVao->GetVertices();
mIbo = pVao->GetIndices();
mICount = pVao->GetIndexCount();
mVCount = pVao->GetVertexCount();
}
void VAO::Destroy(){
glDeleteVertexArrays(1, &mVao);
}
void VAO::Bind() const{
glBindVertexArray(mVao);
}
void VAO::UnBind() const{
glBindVertexArray(0);
}
void VAO::Generate(Shader* pShader, const Vector3F* pVertices, u32 pVerticeSize, const Index* pIndices, u32 pIndiceSize, eBufferUsage bu){
// On s'assure que le tableau est remplit
//Assert(pVertices != NULL);
// On regarde s'il existe deja un VAO ici
if(mVao)
Destroy();
// On génère le VAO
glGenVertexArrays(1, &mVao);
// On génère le VBO
mVbo.Generate(pVertices, pVerticeSize, bu);
mVCount = pVerticeSize / sizeof(Vector3F);
// On fait de même avec l'IBO s'il existe
// if(pIndices){
mIbo.Generate(pIndices, pIndiceSize, bu);
mICount = pIndiceSize / sizeof(Index);
mHasIndices = true;
// }
// On bascule notre VAO comme VAO courant
glBindVertexArray(mVao);
// De meme avec le VertexBuffer
glBindBuffer(GL_ARRAY_BUFFER, mVbo.GetBuffer());
// On met le tableau de vertices dans le VAO
GLint loc = glGetAttribLocation(pShader->GetProgram(), "inVertex");
glVertexAttribPointer(loc, 3, GL_FLOAT, GL_FALSE, 0, 0);
#ifdef _DEBUG
GLenum error = GL_NO_ERROR;
if((error = glGetError()) != GL_NO_ERROR){
throw Exception(String("OpenGL Error: \"")+GetGLErrorStr(error)+"\" in function \"VAO::Generate\"\n\tDoes \"inVertex\" exists or is used?");
}
#endif
glEnableVertexAttribArray(loc);
// Si on a des indices, on active notre IBO
if(mHasIndices)
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIbo.GetBuffer());
// On dé-lie notre VAO
glBindVertexArray(0);
}
void VAO::Update(const Vector3F* pVertices, u32 pVerticeSize, const Index* pIndices, u32 pIndiceSize){
mVCount = pVerticeSize / sizeof(Vector3F);
mICount = pIndiceSize / sizeof(Index);
mVbo.Update(pVertices, pVerticeSize);
mIbo.Update(pIndices, pIndiceSize);
}
// ################################################################### //
// COLORMESH
void ColorMesh::GenerateNormals(const Vector3F* pNormals, u32 pSize, Shader* shader, eBufferUsage bu){
glBindVertexArray(mVao);
mNormals.Generate(pNormals, pSize, bu);
glBindBuffer(GL_ARRAY_BUFFER, mNormals.GetBuffer());
GLint loc = glGetAttribLocation(shader->GetProgram(), "inNormal");
glVertexAttribPointer(loc, 3, GL_FLOAT, GL_FALSE, 0, 0);
#ifdef _DEBUG
GLenum error = GL_NO_ERROR;
if((error = glGetError()) != GL_NO_ERROR){
throw Exception(String("OpenGL Error: \"")+GetGLErrorStr(error)+"\" in function \"ColorMesh::GenerateNormals\"\n\tDoes \"inNormal\" exists or is used?");
}
#endif
glEnableVertexAttribArray(loc);
glBindVertexArray(0);
}
void ColorMesh::UpdateNormals(const Vector3F* pNormals, u32 pSize){
mNormals.Update(pNormals, pSize);
}
// ################################################################### //
// COLORVAO
void ColorVAO::GenerateTexCoords(const Vector2F* pTexCoords, u32 pSize, Shader* shader, eBufferUsage bu){
glBindVertexArray(mVao);
mTexCoords.Generate(pTexCoords, pSize, bu);
glBindBuffer(GL_ARRAY_BUFFER, mTexCoords.GetBuffer());
GLint loc = glGetAttribLocation(shader->GetProgram(), "inTexcoord");
glVertexAttribPointer(loc, 2, GL_FLOAT, GL_FALSE, 0, 0);
#ifdef _DEBUG
GLenum error = GL_NO_ERROR;
if((error = glGetError()) != GL_NO_ERROR){
throw Exception(String("OpenGL Error: \"")+GetGLErrorStr(error)+"\" in function \"ColorVAO::GenerateNormals\"\n\tDoes \"inTexcoord\" exists or is used?");
}
#endif
glEnableVertexAttribArray(loc);
glBindVertexArray(0);
}
void ColorVAO::UpdateTexCoords(const Vector2F* pTexCoords, u32 pSize){
mTexCoords.Update(pTexCoords, pSize);
}
// ################################################################### //
// TEXMESH
void TextureMesh::GenerateTexCoords(const Vector2F* pTexCoords, u32 pSize, Shader* shader, eBufferUsage bu){
glBindVertexArray(mVao);
mTexCoords.Generate(pTexCoords, pSize, bu);
glBindBuffer(GL_ARRAY_BUFFER, mTexCoords.GetBuffer());
GLint loc = glGetAttribLocation(shader->GetProgram(), "inTexcoord");
glVertexAttribPointer(loc, 2, GL_FLOAT, GL_FALSE, 0, 0);
#ifdef _DEBUG
GLenum error = GL_NO_ERROR;
if((error = glGetError()) != GL_NO_ERROR){
throw Exception(String("OpenGL Error: \"")+GetGLErrorStr(error)+"\" in function \"TexMesh::GenerateNormals\"\n\tDoes \"inTexcoord\" exists or is used?");
}
#endif
glEnableVertexAttribArray(loc);
glBindVertexArray(0);
}
void TextureMesh::UpdateTexCoords(const Vector2F* pTexCoords, u32 pSize){
mTexCoords.Update(pTexCoords, pSize);
}
void TextureMesh::GenerateNormals(const Vector3F* pNormals, u32 pSize, Shader* shader, eBufferUsage bu){
glBindVertexArray(mVao);
mNormals.Generate(pNormals, pSize, bu);
glBindBuffer(GL_ARRAY_BUFFER, mNormals.GetBuffer());
GLint loc = glGetAttribLocation(shader->GetProgram(), "inNormal");
glVertexAttribPointer(loc, 3, GL_FLOAT, GL_FALSE, 0, 0);
#ifdef _DEBUG
GLenum error = GL_NO_ERROR;
if((error = glGetError()) != GL_NO_ERROR){
throw Exception(String("OpenGL Error: \"")+GetGLErrorStr(error)+"\" in function \"TexMesh::GenerateNormals\"\n\tDoes \"inNormal\" exists or is used?");
}
#endif
glEnableVertexAttribArray(loc);
glBindVertexArray(0);
}
void TextureMesh::UpdateNormals(const Vector3F* pNormals, u32 pSize){
mNormals.Update(pNormals, pSize);
}
}
| 00xengine | src/Renderer/VAO.cpp | C++ | mit | 5,966 |
#include "Renderer.hpp"
#include "Shader.hpp"
#include "Texture.hpp"
#include "Core/Camera.hpp"
#include "Core/Entity.hpp"
#include "Core/Window.hpp"
#include "Core/Settings.hpp"
#include "Utils/Color.hpp"
#include "Utils/String.hpp"
#include "Debug/Debug.hpp"
namespace engine{
Renderer::Renderer() : mEntityNumber(0), mLastFrameEntityNumber(0), mWindow(0), mCamera(0){
}
Renderer::~Renderer(){
}
void Renderer::Init(Window &pWindow){
mWindow = &pWindow;
mWindowWidth = mWindow->GetWidth();
mWindowHeight = mWindow->GetHeight();
// Initialisation de GLEW sous Windows
#ifdef OOXWIN32
glewExperimental = GL_TRUE;
glewInit();
if(!glewIsSupported("GL_VERSION_3_3"))
throw Exception("GLEW : OpenGL Version 3.3 is not supported");
#endif
// Wireframe
mSpecs.mWireframe = false;
mSpecs.mWireframeChange = false;
// Ambient Color
mSpecs.mAmbientColor = Settings::Call().GetSettingColor("AmbientColor");
// FOV
mSpecs.mFOV = Settings::Call().GetSettingFloat("FOV");
// Near et Far plane
mSpecs.mNearPlane = Settings::Call().GetSettingFloat("NearPlane");
mSpecs.mFarPlane = Settings::Call().GetSettingFloat("FarPlane");
m3DProjectionMatrix.PerspectiveFOV(mSpecs.mFOV, (f32)mWindowWidth / (f32)mWindowHeight, mSpecs.mNearPlane, mSpecs.mFarPlane);
m2DProjectionMatrix.OrthoOffCenter(0,0,(f32)mWindowWidth,(f32)mWindowHeight);
// VSync
mSpecs.mVsync = Settings::Call().GetSettingBool("VSync");
mWindow->GetWindow().SetFramerateLimit(mSpecs.mVsync ? 60 : 0);
// Activation du Z-Depth
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
// Activation du BackFace Culling
mSpecs.mCullingFace= (Settings::Call().GetSettingStr("CullFace") == "CCW" ? GL_CCW : GL_CW);
glFrontFace(mSpecs.mCullingFace);
glEnable(GL_CULL_FACE);
// Niveau d'anisotropy maximum
f32 maxAniso;
glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAniso);
mSpecs.mMaximumAnisotropy = (u32)maxAniso;
// Niveau d'anisotropy demandé
mSpecs.mWantedAnisotropy = Settings::Call().GetSettingInt("Anisotropy");
if(mSpecs.mWantedAnisotropy > mSpecs.mMaximumAnisotropy){
OmniLog << "Wanted Anisotropic Filtering Level is too high (" << mSpecs.mWantedAnisotropy << ")." << eol;
mSpecs.mWantedAnisotropy = mSpecs.mMaximumAnisotropy;
}
// Entity Number drawn text
mEntityNumberText.SetText(String("Entities : ")+mEntityNumber);
mEntityNumberText.SetPosition(10,34);
mEntityNumberText.SetColor(Color::White);
mEntityNumberText.SetSize(12);
}
void Renderer::SetFOV(f32 pFov){
if(pFov >= 44.f){
mSpecs.mFOV = pFov;
m3DProjectionMatrix.PerspectiveFOV(mSpecs.mFOV, (f32)mWindowWidth / (f32)mWindowHeight, mSpecs.mNearPlane, mSpecs.mFarPlane);
m3DViewProjMatrix = m3DViewMatrix * m3DProjectionMatrix;
}
}
void Renderer::WireframeMode(bool pVal){
mSpecs.mWireframe = pVal;
mSpecs.mWireframeChange = true;
}
void Renderer::Resize(){
mWindowWidth = mWindow->GetWidth();
mWindowHeight = mWindow->GetHeight();
m2DProjectionMatrix.OrthoOffCenter(0, 0, (f32)mWindowWidth, (f32)mWindowHeight);
m3DProjectionMatrix.PerspectiveFOV(mSpecs.mFOV, (f32)mWindowWidth / (f32)mWindowHeight, mSpecs.mNearPlane, mSpecs.mFarPlane);
m3DViewProjMatrix = m3DViewMatrix * m3DProjectionMatrix;
}
void Renderer::BeginScene(const Color &pColor) const{
glClearColor(pColor.R(), pColor.G(), pColor.B(), pColor.A());
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
void Renderer::EndScene(){
mWindow->GetWindow().Display();
}
void Renderer::DrawText(Text* pText){
mTextMap.push_back(pText);
}
void Renderer::DrawMesh(Mesh* pEntity){
mMeshMap.push_back(pEntity);
}
void Renderer::DrawObject(Object* pEntity){
mObjectMap.push_back(pEntity);
}
void Renderer::DrawDebugObject(DebugObject* pEntity){
mDebugObjectMap.push_back(pEntity);
}
void Renderer::Render(){
mEntityNumber = 0;
if(mSpecs.mWireframeChange){
mSpecs.mWireframeChange = false;
if(mSpecs.mWireframe)
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
else
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
}
if(!mMeshMap.empty())
RenderMeshes();
if(!mObjectMap.empty())
RenderObjects();
if(!mDebugObjectMap.empty())
RenderDebugObjects();
RenderTexts();
}
void Renderer::RenderTexts(){
// Disable GL Depth and Culling for 2D text drawing
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
for(mTextMapIt = mTextMap.begin(); mTextMapIt != mTextMap.end(); ++mTextMapIt){
mWindow->GetWindow().Draw((*mTextMapIt)->GetSFMLText());
}
// Draw the entity number on screen if debug active
#ifdef _DEBUG
if(mEntityNumber != mLastFrameEntityNumber){
mEntityNumberText.SetText(String("Entities : ")+mEntityNumber);
mLastFrameEntityNumber = mEntityNumber;
}
mWindow->GetWindow().Draw(mEntityNumberText.GetSFMLText());
#endif
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
mTextMap.clear();
}
void Renderer::RenderMeshes(){
static Shader* currentShader;
static Mesh* currentMesh;
currentShader = 0;
currentMesh = 0;
// Using Textures
glActiveTexture(GL_TEXTURE0);
for(mMeshMapIt = mMeshMap.begin(); mMeshMapIt != mMeshMap.end(); ++mMeshMapIt){
// Get the current mesh
currentMesh = (*mMeshMapIt);
// If the mesh possess a different shader, change it
if(currentMesh->GetShader() != currentShader){
currentShader = currentMesh->GetShader();
currentShader->Bind();
}
// Send the Mesh Matrices to the Shader
currentShader->SendMatrix4("ModelViewProjMatrix", currentMesh->GetModelMatrix() * m3DViewProjMatrix );
currentShader->SendMatrix4("ModelViewMatrix", currentMesh->GetModelMatrix() * m3DViewMatrix);
currentShader->SendMatrix4("ViewMatrix", m3DViewMatrix);
currentShader->SendMatrix4("NormalMatrix", m3DNormalMatrix);
// Send the Mesh Material to the Shader
currentShader->SendColor("Ka", currentMesh->GetMaterial().mAmbient);
currentShader->SendColor("Kd", currentMesh->GetMaterial().mDiffuse);
currentShader->SendColor("Ks", currentMesh->GetMaterial().mSpecular);
currentShader->SendFloat("shininess", currentMesh->GetMaterial().mShininess);
// Bind texture
currentMesh->GetTexture().Bind();
// Draw the mesh
currentMesh->GetMesh()->Bind();
glDrawElements(GL_TRIANGLES, currentMesh->GetMesh()->GetIndexCount(), GL_UNSIGNED_INT, 0);
currentMesh->GetMesh()->UnBind();
// Unbind texture
currentMesh->GetTexture().UnBind();
}
currentShader->UnBind();
// Add Mesh number to total
mEntityNumber += mMeshMap.size();
// Clear the vector for next frame
mMeshMap.clear();
}
void Renderer::RenderObjects(){
static Shader* currentShader;
static Object* currentObject;
currentShader = 0;
currentObject = 0;
for(mObjectMapIt = mObjectMap.begin(); mObjectMapIt != mObjectMap.end(); ++mObjectMapIt){
// Get the current Object
currentObject = (*mObjectMapIt);
// If the object possess a different shader, change it
if(currentObject->GetShader() != currentShader){
currentShader = currentObject->GetShader();
currentShader->Bind();
}
// Send the Object Matrices to the Shader
currentShader->SendMatrix4("ModelViewProjMatrix", currentObject->GetModelMatrix() * m3DViewProjMatrix );
currentShader->SendMatrix4("ModelViewMatrix", currentObject->GetModelMatrix() * m3DViewMatrix);
currentShader->SendMatrix4("ViewMatrix", m3DViewMatrix);
currentShader->SendMatrix4("NormalMatrix", m3DNormalMatrix);
// Send the Object Material to the Shader
currentShader->SendColor("Ka", currentObject->GetMaterial().mAmbient);
currentShader->SendColor("Kd", currentObject->GetMaterial().mDiffuse);
currentShader->SendColor("Ks", currentObject->GetMaterial().mSpecular);
currentShader->SendFloat("shininess", currentObject->GetMaterial().mShininess);
// Draw the Object
currentObject->GetMesh()->Bind();
glDrawElements(GL_TRIANGLES, currentObject->GetMesh()->GetIndexCount(), GL_UNSIGNED_INT, 0);
currentObject->GetMesh()->UnBind();
}
currentShader->UnBind();
// Add Object number to total
mEntityNumber += mObjectMap.size();
// Clear the vector for next frame
mObjectMap.clear();
}
void Renderer::RenderDebugObjects(){
static Shader* currentShader;
static DebugObject* currentObject;
currentShader = 0;
currentObject = 0;
// Using Texture
glActiveTexture(GL_TEXTURE0);
for(mDebugObjectMapIt = mDebugObjectMap.begin(); mDebugObjectMapIt != mDebugObjectMap.end(); ++mDebugObjectMapIt){
// Get the current Object
currentObject = (*mDebugObjectMapIt);
// If the object possess a different shader, change it
if(currentObject->GetShader() != currentShader){
currentShader = currentObject->GetShader();
currentShader->Bind();
}
// Send the Object matrices to the shader
currentShader->SendMatrix4("ModelViewProjMatrix", currentObject->GetModelMatrix() * m3DViewProjMatrix );
currentShader->SendMatrix4("ModelViewMatrix", currentObject->GetModelMatrix() * m3DViewMatrix);
currentShader->SendMatrix4("ViewMatrix", m3DViewMatrix);
currentShader->SendMatrix4("NormalMatrix", m3DNormalMatrix);
// Send the Object material to the shader
currentShader->SendColor("Ka", currentObject->GetMaterial().mAmbient);
currentShader->SendColor("Kd", currentObject->GetMaterial().mDiffuse);
currentShader->SendColor("Ks", currentObject->GetMaterial().mSpecular);
currentShader->SendFloat("shininess", currentObject->GetMaterial().mShininess);
// Bind Texture
currentObject->GetTexture().Bind();
// Draw the Object
currentObject->GetMesh()->Bind();
glDrawElements(GL_TRIANGLES, currentObject->GetMesh()->GetIndexCount(), GL_UNSIGNED_INT, 0);
currentObject->GetMesh()->UnBind();
// Unbind texture
currentObject->GetTexture().UnBind();
}
currentShader->UnBind();
// Add DebugObject number to total
mEntityNumber += mDebugObjectMap.size();
// Clear the vector for next frame
mDebugObjectMap.clear();
}
}
| 00xengine | src/Renderer/Renderer.cpp | C++ | mit | 10,085 |
#include "Texture.hpp"
#include "Renderer.hpp"
#include "Debug/Debug.hpp"
namespace engine {
Texture::Texture() : mTexture(0){
}
Texture::~Texture(){
Destroy();
}
void Texture::Destroy(){
if(mTexture)
glDeleteTextures(1, &mTexture);
}
void Texture::LoadFromImage(const Image &pImage, const Rectangle &pSubRect){
// Generation de Binding de la texture a OGL
glGenTextures(1, &mTexture);
glBindTexture(GL_TEXTURE_2D, mTexture);
// Utilisation de linear interpolation pour les min/mag filters
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, (f32)Renderer::Call().GetSpecifications().mWantedAnisotropy);
// creation depuis l'image
// Reconnaissance du rectangle envoye et creation de la texture OGL
if(pSubRect.Width() == 0 && pSubRect.Height() == 0)
glTexImage2D(GL_TEXTURE_2D, 0, pImage.GetBytesPerPixel(), pImage.GetSize().x, pImage.GetSize().y, 0, pImage.GetFormat(), GL_UNSIGNED_BYTE, pImage.GetData());
else
glTexSubImage2D(GL_TEXTURE_2D, 0, pSubRect.Origin.x, pSubRect.Origin.y, pSubRect.Width(), pSubRect.Height(), pImage.GetFormat(), GL_UNSIGNED_BYTE, pImage.GetData());
// glHint(GL_GENERATE_MIPMAP_HINT, GL_NICEST);
glGenerateMipmap(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, 0);
#ifdef _DEBUG
BaseLog << "DEBUG : Texture created from image \"" << pImage.GetName() << "\"."/* RAJOUTER LE RECTANGLE UTILISED*/ << eol;
#endif
}
void Texture::Bind() const{
glBindTexture(GL_TEXTURE_2D, mTexture);
}
void Texture::UnBind() const{
glBindTexture(GL_TEXTURE_2D, 0);
}
}
| 00xengine | src/Renderer/Texture.cpp | C++ | mit | 1,837 |
#include "Light.hpp"
namespace engine{
void Update(){
}
} | 00xengine | src/Renderer/Light.cpp | C++ | mit | 70 |
#ifndef RECTANGLE_HPP
#define RECTANGLE_HPP
#include "Vector2.hpp"
namespace engine {
// Three possible results of an Intersection
enum IntersectionResult{
INTR_In,
INTR_Out,
INTR_Intersect
};
class OOXAPI Rectangle{
public:
// Ctor from 4 boundaries
Rectangle(s32 top, s32 left, s32 width, s32 height);
// Ctor from Top-Left and Bottom-Right Vectors
Rectangle(const Vector2I &topLeft = Vector2I(0,0), const Vector2I &size = Vector2I(0,0));
// Initialize the rectangle from 4 boundaries
void Set(s32 top, s32 left, s32 width, s32 height);
// Getters
s32 Left() const;
s32 Top() const;
s32 Right() const;
s32 Bottom() const;
s32 Width() const;
s32 Height() const;
// Returns the rectangle size (End - Origin)
Vector2I Size() const;
// Returns the intersection type between a point and this rectangle
IntersectionResult Intersects(const Vector2I &Point) const;
// Returns the intersection type between another and this rectangle
IntersectionResult Intersects(const Rectangle &Rect) const;
bool operator==(const Rectangle &Rect) const;
bool operator!=(const Rectangle &Rect) const;
friend std::istream& operator>> (std::istream &iss, Rectangle &Rect);
friend std::ostream& operator<< (std::ostream &oss, const Rectangle &Rect);
// Data
Vector2I Origin;
Vector2I End;
};
}
#endif
| 00xengine | src/Math/Rectangle.hpp | C++ | mit | 1,423 |
#include "Matrix4.hpp"
#include "Quaternion.hpp"
namespace engine {
}
| 00xengine | src/Math/Matrix4.cpp | C++ | mit | 73 |
#ifndef VECTOR2_HPP
#define VECTOR2_HPP
#include "Mathlib.hpp"
namespace engine {
template<typename T>
class Vector2{
public:
Vector2(T x = 0, T y = 0);
// Sets vector components
void Set(T x, T y);
// Returns the vector components in an array
void XY(T pTab[]) const;
// Returns the vector length
T Norme() const;
// Returns the Squared Length (intern use for Norme())
T NormeSq() const;
// Normalize the vector
void Normalize();
// Returns the negate of the vector
Vector2<T> operator- () const;
// Binary operators
Vector2<T> operator+ (const Vector2<T> &V) const;
Vector2<T> operator- (const Vector2<T> &V) const;
Vector2<T>& operator+= (const Vector2<T> &V) const;
Vector2<T>& operator -= (const Vector2<T> &V) const;
Vector2<T> operator*(T t) const;
Vector2<T> operator/(T t) const;
Vector2<T>& operator*= (T t) const;
Vector2<T>& operator /= (T t) const;
// Comparison operators
bool operator==(const Vector2<T> &V) const;
bool operator!=(const Vector2<T> &V) const;
// Returns a pointer on x
operator T*();
// Common Zero Vector
static const OOXAPI Vector2 ZERO;
// Donnees
T x;
T y;
};
// Result of multiplication between a vector and a T
template<class T> Vector2<T> operator* (const Vector2<T> &V, T t);
// Result of division between a vector and a T
template<class T> Vector2<T> operator/ (const Vector2<T> &V, T t);
// Result of multiplication between a T and a vector
template<class T> Vector2<T> operator* (T t, const Vector2<T> &V);
// Dot product between two vector2
template<class T> T Dot(const Vector2<T> &U, const Vector2<T> &V);
// Stream ops
template<class T> std::istream& operator >>(std::istream& iss, Vector2<T> &V);
template<class T> std::ostream& operator <<(std::ostream& oss, const Vector2<T> &V);
typedef Vector2<s32> Vector2I;
typedef Vector2<f32> Vector2F;
// Conversion between SFML and 00xEngine
template<class T> Vector2F To00xVector2F(const sf::Vector2<T> &pVec);
template<class T> Vector2I To00xVector2I(const sf::Vector2<T> &pVec);
template<class T> sf::Vector2f ToSFMLVector2f(const Vector2<T> &pVec);
template<class T> sf::Vector2i ToSFMLVector2i(const Vector2<T> &pVec);
#include "Vector2.inl"
}
#endif
| 00xengine | src/Math/Vector2.hpp | C++ | mit | 2,343 |
template<class T>
inline engine::Vector2<T>::Vector2(T X, T Y) : x(X), y(Y){
}
template<class T>
inline void engine::Vector2<T>::Set(T X, T Y){
x = X;
y = Y;
}
template<class T>
inline void engine::Vector2<T>::XY(T pTab[]) const{
pTab[0] = x;
pTab[1] = y;
}
template<class T>
inline T engine::Vector2<T>::Norme() const{
return Math::Sqrt(NormeSq());
}
template<class T>
inline T engine::Vector2<T>::NormeSq() const{
return x * x + y * y;
}
template<class T>
inline void engine::Vector2<T>::Normalize(){
T Norme = Norme();
if(Math::Abs(Norme) > Math::Epsilon){
x /= Norme;
y /= Norme;
}
}
template<class T>
inline Vector2<T> engine::Vector2<T>::operator-() const{
return Vector2<T>(-x, -y);
}
template<class T>
inline Vector2<T> engine::Vector2<T>::operator+(const Vector2<T> &V) const{
return Vector2<T>(x + V.x, y + V.y);
}
template<class T>
inline Vector2<T> engine::Vector2<T>::operator-(const Vector2<T> &V) const{
return Vector2<T>(x - V.x, y - V.y);
}
template<class T>
inline Vector2<T>& engine::Vector2<T>::operator+=(const Vector2<T> &V) const{
x += V.x;
y += V.y;
return *this;
}
template<class T>
inline Vector2<T>& engine::Vector2<T>::operator-=(const Vector2<T> &V) const{
x -= V.x;
y -= V.y;
return *this;
}
template<class T>
inline Vector2<T> engine::Vector2<T>::operator*(T t) const{
return Vector2<T>(x*t, y*t);
}
template<class T>
inline Vector2<T> engine::Vector2<T>::operator/(T t) const{
return Vector2<T>(x/t, y/t);
}
template<class T>
inline Vector2<T>& engine::Vector2<T>::operator*=(T t) const{
x *= t;
y *= t;
return *this;
}
template<class T>
inline Vector2<T>& engine::Vector2<T>::operator/=(T t) const{
x /= t;
y /= t;
return *this;
}
template<class T>
inline bool engine::Vector2<T>::operator==(const Vector2<T> &V) const{
return ( (Math::Abs(float(x - V.x)) <= Math::Epsilon) &&
(Math::Abs(float(y - V.y)) <= Math::Epsilon) );
}
template<class T>
inline bool engine::Vector2<T>::operator!=(const Vector2<T> &V) const{
return !(*this == V);
}
template<class T>
inline engine::Vector2<T>::operator T*(){
return &x;
}
template<class T>
Vector2<T> operator* (const Vector2<T> &V, T t){
return Vector2<T>(V.x * t, V.y * t);
}
template<class T>
Vector2<T> operator/ (const Vector2<T> &V, T t){
return Vector2<T>(V.x / t, V.y / t);
}
template<class T>
Vector2<T> operator* (T t, const Vector2<T> &V){
return V * t;
}
template<class T>
T Dot(const Vector2<T> &U, const Vector2<T> &V){
return U.x * V.x + U.y * V.y;
}
template<class T>
std::istream& operator >>(std::istream& iss, Vector2<T> &V){
return iss >> V.x >> V.y;
}
template<class T>
std::ostream& operator <<(std::ostream& oss, const Vector2<T> &V){
return oss << V.x << " " << V.y;
}
template<class T>
Vector2F To00xVector2F(const sf::Vector2<T> &pVec){
return Vector2F(static_cast<f32>(pVec.x), static_cast<f32>(pVec.y));
}
template<class T>
Vector2I To00xVector2I(const sf::Vector2<T> &pVec){
return Vector2I(static_cast<s32>(pVec.x), static_cast<s32>(pVec.y));
}
template<class T>
sf::Vector2f ToSFMLVector2f(const Vector2<T> &pVec){
return sf::Vector2f(static_cast<f32>(pVec.x), static_cast<f32>(pVec.y));
}
template<class T>
sf::Vector2i ToSFMLVector2i(const Vector2<T> &pVec){
return sf::Vector2f(static_cast<s32>(pVec.x), static_cast<s32>(pVec.y));
}
| 00xengine | src/Math/Vector2.inl | C++ | mit | 3,627 |
template<class T>
inline engine::Vector3<T>::Vector3(T X, T Y, T Z) : x(X), y(Y), z(Z){
}
template<class T>
inline void engine::Vector3<T>::Set(T X, T Y, T Z){
x = X;
y = Y;
z = Z;
}
template<class T>
inline void engine::Vector3<T>::XYZ(T pTab[]) const{
pTab[0] = x;
pTab[1] = y;
pTab[2] = z;
}
template<class T>
inline T engine::Vector3<T>::Norme() const{
return Math::Sqrt(NormeSq());
}
template<class T>
inline T engine::Vector3<T>::NormeSq() const{
return x * x + y * y + z * z;
}
template<class T>
inline void engine::Vector3<T>::Normalize(){
T norme = Norme();
// on s'assure que norme != 0
if(Math::Abs(norme) > Math::Epsilon){ // Eviter le == non precis des floating points
x /= norme;
y /= norme;
z /= norme;
}
}
template<class T>
inline void engine::Vector3<T>::ScaleFrom(const Vector3<T> &pCenter, f32 pScaleFactor){
Vector3<T> axis = (*this) - pCenter;
(*this) += axis * pScaleFactor;
}
template<class T>
inline Vector3<T> engine::Vector3<T>::operator-() const{
return Vector3<T>(-x, -y, -z);
}
template<class T>
inline Vector3<T> engine::Vector3<T>::operator+(const Vector3<T> &V) const{
return Vector3<T>(x + V.x, y + V.y, z + V.z);
}
template<class T>
inline Vector3<T> engine::Vector3<T>::operator-(const Vector3<T> &V) const{
return Vector3<T>(x - V.x, y - V.y, z - V.z);
}
template<class T>
inline Vector3<T>& engine::Vector3<T>::operator+=(const Vector3<T> &V) {
x += V.x;
y += V.y;
z += V.z;
return *this;
}
template<class T>
inline Vector3<T>& engine::Vector3<T>::operator-=(const Vector3<T> &V) {
x -= V.x;
y -= V.y;
z -= V.z;
return *this;
}
template<class T>
inline Vector3<T> engine::Vector3<T>::operator*(T t) const{
return Vector3<T>(x * t, y * t, z * t);
}
template<class T>
inline Vector3<T> engine::Vector3<T>::operator/(T t) const{
return Vector3<T>(x/t, y/t, z/t);
}
template<class T>
inline Vector3<T>& engine::Vector3<T>::operator*=(T t){
x *= t;
y *= t;
z *= t;
return *this;
}
template<class T>
inline Vector3<T>& engine::Vector3<T>::operator/=(T t){
x /= t;
y /= t;
z /= t;
return *this;
}
template<class T>
inline bool engine::Vector3<T>::operator==(const Vector3<T> &V) const{
return ( (Math::Abs(x - V.x) <= Math::Epsilon) &&
(Math::Abs(y - V.y) <= Math::Epsilon) &&
(Math::Abs(z - V.z) <= Math::Epsilon) );
}
template<class T>
inline bool engine::Vector3<T>::operator!=(const Vector3<T> &V) const{
return !(*this == V);
}
template<class T>
inline engine::Vector3<T>::operator T*(){
return &x;
}
template<class T>
Vector3<T> operator* (const Vector3<T> &V, T t){
return Vector3<T>(V.x * t, V.y * t, V.z * t);
}
template<class T>
Vector3<T> operator/ (const Vector3<T> &V, T t){
return Vector3<T>(V.x / t, V.y / t, V.z / t);
}
template<class T>
Vector3<T> operator* (T t, const Vector3<T> &V){
return V * t;
}
template<class T>
T Dot(const Vector3<T> &U, const Vector3<T> &V){
return U.x * V.x + U.y * V.y + U.z * V.z;
}
template<class T>
Vector3<T> Cross(const Vector3<T> &U, const Vector3<T> &V){
return Vector3<T>( (U.y * V.z) - (V.y * U.z), (U.z * V.x) - (V.z * U.x), (U.x * V.y) - (V.x * U.y) );
}
template<class T>
std::istream& operator >>(std::istream& iss, Vector3<T> &V){
return iss >> V.x >> V.y >> V.z;
}
template<class T>
std::ostream& operator <<(std::ostream& oss, const Vector3<T> &V){
return oss << V.x << " " << V.y << " " << V.z;
}
| 00xengine | src/Math/Vector3.inl | C++ | mit | 3,687 |
inline engine::Matrix4::Matrix4(f32 m11, f32 m12, f32 m13, f32 m14,
f32 m21, f32 m22, f32 m23, f32 m24,
f32 m31, f32 m32, f32 m33, f32 m34,
f32 m41, f32 m42, f32 m43, f32 m44) :
a11(m11), a12(m12), a13(m13), a14(m14),
a21(m21), a22(m22), a23(m23), a24(m24),
a31(m31), a32(m32), a33(m33), a34(m34),
a41(m41), a42(m42), a43(m43), a44(m44) {
};
inline void engine::Matrix4::Identity(){
a11 = 1.0f; a12 = 0.0f; a13 = 0.0f; a14 = 0.0f;
a21 = 0.0f; a22 = 1.0f; a23 = 0.0f; a24 = 0.0f;
a31 = 0.0f; a32 = 0.0f; a33 = 1.0f; a34 = 0.0f;
a41 = 0.0f; a42 = 0.0f; a43 = 0.0f; a44 = 1.0f;
}
inline void engine::Matrix4::ToFloat(f32* tab) const{
tab[0] = a11; tab[1] = a12; tab[2] = a13; tab[3] = a14;
tab[4] = a21; tab[5] = a22; tab[6] = a23; tab[7] = a24;
tab[8] = a31; tab[9] = a32; tab[10] = a33; tab[11] = a34;
tab[12] = a41; tab[13] = a42; tab[14] = a43; tab[15] = a44;
}
inline f32 engine::Matrix4::Det() const{
f32 A = a22 * (a33 * a44 - a43 * a34) - a23 * (a32 * a44 - a34 * a42) + a24 * (a32 * a43 - a33 * a42);
f32 B = a21 * (a33 * a44 - a43 * a34) - a23 * (a31 * a44 - a34 * a41) + a24* (a31 * a43 - a33 * a41);
f32 C = a21 * (a32 * a44 - a34 * a42) - a22 * (a31 * a44 - a34 * a41) + a24 * (a31 * a42 - a32 * a41);
f32 D = a21 * (a32 * a43 - a33 * a42) - a22 * (a31 * a43 - a33 * a41) + a23 * (a31 * a42 - a32 * a41);
return a11 * A - a12 * B + a13 * C - a14 * D; // LaPlace en prenant la premiere Colonne, en trouvant ses cofactors(A..D)
}
inline Matrix4 engine::Matrix4::Transpose() const{
return Matrix4(a11, a21, a31, a41,
a12, a22, a32, a42,
a13, a23, a33, a43,
a14, a24, a34, a44);
}
inline Matrix4 engine::Matrix4::Inverse() const{
f32 det = Det();
Matrix4 inverse;
if(Math::Abs(det) > Math::Epsilon){
inverse.a11 = (a22 * (a33 * a44 - a43 * a34) - a23 * (a32 * a44 - a34 * a42) + a24 * (a32 * a43 - a33 * a42)) / det;
inverse.a21 = -(a21 * (a33 * a44 - a43 * a34) - a23 * (a31 * a44 - a34 * a41) + a24* (a31 * a43 - a33 * a41)) / det;
inverse.a31 = (a21 * (a32 * a44 - a34 * a42) - a22 * (a31 * a44 - a34 * a41) + a24 * (a31 * a42 - a32 * a41)) / det;
inverse.a41 = -(a21 * (a32 * a43 - a33 * a42) - a22 * (a31 * a43 - a33 * a41) + a23 * (a31 * a42 - a32 * a41)) / det;
inverse.a12 = -(a12 * (a33 * a44 - a34 * a43) - a13 * (a32 * a44 - a34 * a42) + a14 * (a32 * a43 - a33 * a42)) / det;
inverse.a22 = (a11 * (a33 * a44 - a34 * a43) - a13 * (a31 * a44 - a34 * a41) + a14 * (a31 * a43 - a33 * a41)) / det;
inverse.a32 = -(a11 * (a32 * a44 - a34 * a42) - a12 * (a31 * a44 - a34 * a41) + a14 * (a31 * a42 - a32 * a41)) / det;
inverse.a42 = (a11 * (a32 * a43 - a33 * a42) - a12 * (a31 * a43 - a33 * a41) + a13 * (a31 * a42 - a32 * a41)) / det;
inverse.a13 = (a12 * (a23 * a44 - a24 * a43) - a13 * (a22 * a44 - a24 * a42) + a14 * (a22 * a43 - a23 * a42)) / det;
inverse.a23 = -(a11 * (a23 * a44 - a24 * a43) - a13 * (a21 * a44 - a24 * a41) + a14 * (a21 * a43 - a23 * a41)) / det;
inverse.a33 = (a11 * (a22 * a44 - a24 * a42) - a12 * (a21 * a44 - a24 * a41) + a14 * (a21 * a42 - a22 * a41)) / det;
inverse.a43 = -(a11 * (a22 * a43 - a23 * a42) - a12 * (a21 * a43 - a23 * a41) + a13 * (a21 * a42 - a22 * a41)) / det;
inverse.a14 = -(a12 * (a23 * a34 - a24 * a33) - a13 * (a22 * a34 - a24 * a32) + a14 * (a22 * a33 - a23 * a32)) / det;
inverse.a24 = (a11 * (a23 * a34 - a24 * a33) - a13 * (a21 * a34 - a24 * a31) + a14 * (a21 * a33 - a23 * a31)) / det;
inverse.a34 = -(a11 * (a22 * a34 - a24 * a32) - a12 * (a21 * a34 - a24 * a31) + a14 * (a21 * a32 - a22 * a31)) / det;
inverse.a44 = (a11 * (a22 * a33 - a23 * a32) - a12 * (a21 * a33 - a23 * a31) + a13 * (a21 * a32 - a22 * a31)) / det;
}
return inverse;
}
inline void engine::Matrix4::SetTranslation(f32 x, f32 y, f32 z){
a41 = x;
a42 = y;
a43 = z;
}
inline void engine::Matrix4::SetTranslation(const Vector3F &V){
a41 = V.x;
a42 = V.y;
a43 = V.z;
}
inline void engine::Matrix4::SetScale(f32 x, f32 y, f32 z){
a11 = x;
a22 = y;
a33 = z;
}
inline void engine::Matrix4::SetScale(const Vector3F &V){
a11 = V.x;
a22 = V.y;
a33 = V.z;
}
inline void engine::Matrix4::SetScale(f32 xyz){
SetScale(xyz, xyz, xyz);
}
inline void engine::Matrix4::SetRotationX(f32 Angle){
f32 Sin = std::sin(Angle);
f32 Cos = std::cos(Angle);
a11= 1.f;a12= 0.f; a13= 0.f;
a21= 0.f;a22= Cos; a23= -Sin;
a31= 0.f;a32= Sin; a33= Cos;
}
inline void engine::Matrix4::SetRotationY(f32 Angle){
f32 Sin =std::sin(Angle);
f32 Cos = std::cos(Angle);
a11= Cos;a12= 0.f; a13= Sin;
a21= 0.f;a22= 1.f; a23= 0.f;
a31= -Sin;a32= 0.f; a33= Cos;
}
inline void engine::Matrix4::SetRotationZ(f32 Angle){
f32 Sin = std::sin(Angle);
f32 Cos = std::cos(Angle);
a11= Cos;a12= -Sin; a13= 0.f;
a21= Sin;a22= Cos; a23= 0.f;
a31= 0.f;a32= 0.f; a33= 1.f;
}
inline void engine::Matrix4::SetRotationX(f32 Angle, const Vector3F &Axis){
Matrix4 Tr1, Tr2, Rot;
Tr1.SetTranslation(Axis.x, Axis.y, Axis.z);
Tr2.SetTranslation(-Axis.x, -Axis.y, -Axis.z);
Rot.SetRotationX(Angle);
*this = Tr1 * Rot * Tr2;
}
inline void engine::Matrix4::SetRotationY(f32 Angle, const Vector3F &Axis){
Matrix4 Tr1, Tr2, Rot;
Tr1.SetTranslation(Axis.x, Axis.y, Axis.z);
Tr2.SetTranslation(-Axis.x, -Axis.y, -Axis.z);
Rot.SetRotationY(Angle);
*this = Tr1 * Rot * Tr2;
}
inline void engine::Matrix4::SetRotationZ(f32 Angle, const Vector3F &Axis){
Matrix4 Tr1, Tr2, Rot;
Tr1.SetTranslation(Axis.x, Axis.y, Axis.z);
Tr2.SetTranslation(-Axis.x, -Axis.y, -Axis.z);
Rot.SetRotationZ(Angle);
*this = Tr1 * Rot * Tr2;
}
inline void engine::Matrix4::Translate(const Vector3F &pVector){
a41 += pVector.x;
a42 += pVector.y;
a43 += pVector.z;
}
inline void engine::Matrix4::Scale(const Vector3F &pVector){
a11 *= pVector.x;
a22 *= pVector.y;
a33 *= pVector.z;
}
inline void engine::Matrix4::Scale(f32 pFactor){
a11 *= pFactor;
a22 *= pFactor;
a33 *= pFactor;
}
inline Vector3F engine::Matrix4::GetTranslation()const{
return Vector3F(a14, a24, a34);
}
inline Vector3F engine::Matrix4::GetScale() const{
return Vector3F(Math::Sqrt(a11*a11+a12*a12+a13*a13), Math::Sqrt(a21*a21+a22*a22+a23*a23), Math::Sqrt(a31*a31+a32*a32+a33*a33));
}
inline Vector3F engine::Matrix4::Transform(const Vector3F &V, f32 w) const{
return Vector3F(a11 * V.x + a12 * V.y + a13 * V.z + a14 * w,
a21 * V.x + a22 * V.y + a23 * V.z + a24 * w,
a31 * V.x + a31 * V.y + a33 * V.z + a34 * w);
}
inline void engine::Matrix4::WorldMatrix(const Vector3F &Translation, const Vector3F &Rotation){
Matrix4 Temp;
Matrix4 Rot;
SetTranslation(Translation);
if(Rotation.x || Rotation.y ||Rotation.z){
Temp.SetRotationX(Rotation.x);
Rot *= Temp;
Temp.SetRotationY(Rotation.y);
Rot *= Temp;
Temp.SetRotationZ(Rotation.z);
Rot *= Temp;
(*this) = Rot * (*this);
}
}
inline Matrix4 engine::Matrix4::operator -() const
{
return Matrix4(-a11, -a12, -a13, -a14,
-a21, -a22, -a23, -a24,
-a31, -a32, -a33, -a34,
-a41, -a42, -a43, -a44);
}
inline Matrix4 engine::Matrix4::operator +(const Matrix4& m) const
{
return Matrix4(a11 + m.a11, a12 + m.a12, a13 + m.a13, a14 + m.a14,
a21 + m.a21, a22 + m.a22, a23 + m.a23, a24 + m.a24,
a31 + m.a31, a32 + m.a32, a33 + m.a33, a34 + m.a34,
a41 + m.a41, a42 + m.a42, a43 + m.a43, a44 + m.a44);
}
inline Matrix4 engine::Matrix4::operator -(const Matrix4& m) const
{
return Matrix4(a11 - m.a11, a12 - m.a12, a13 - m.a13, a14 - m.a14,
a21 - m.a21, a22 - m.a22, a23 - m.a23, a24 - m.a24,
a31 - m.a31, a32 - m.a32, a33 - m.a33, a34 - m.a34,
a41 - m.a41, a42 - m.a42, a43 - m.a43, a44 - m.a44);
}
inline const Matrix4& engine::Matrix4::operator +=(const Matrix4& m)
{
a11 += m.a11; a12 += m.a12; a13 += m.a13; a14 += m.a14;
a21 += m.a21; a22 += m.a22; a23 += m.a23; a24 += m.a24;
a31 += m.a31; a32 += m.a32; a33 += m.a33; a34 += m.a34;
a41 += m.a41; a42 += m.a42; a43 += m.a43; a44 += m.a44;
return *this;
}
inline const Matrix4& engine::Matrix4::operator -=(const Matrix4& m)
{
a11 -= m.a11; a12 -= m.a12; a13 -= m.a13; a14 -= m.a14;
a21 -= m.a21; a22 -= m.a22; a23 -= m.a23; a24 -= m.a24;
a31 -= m.a31; a32 -= m.a32; a33 -= m.a33; a34 -= m.a34;
a41 -= m.a41; a42 -= m.a42; a43 -= m.a43; a44 -= m.a44;
return *this;
}
inline Matrix4 engine::Matrix4::operator*(const Matrix4 &m) const{
return Matrix4(a11 * m.a11 + a12 * m.a21 + a13 * m.a31 + a14 * m.a41,
a11 * m.a12 + a12 * m.a22 + a13 * m.a32 + a14 * m.a42,
a11 * m.a13 + a12 * m.a23 + a13 * m.a33 + a14 * m.a43,
a11 * m.a14 + a12 * m.a24 + a13 * m.a34 + a14 * m.a44,
a21 * m.a11 + a22 * m.a21 + a23 * m.a31 + a24 * m.a41,
a21 * m.a12 + a22 * m.a22 + a23 * m.a32 + a24 * m.a42,
a21 * m.a13 + a22 * m.a23 + a23 * m.a33 + a24 * m.a43,
a21 * m.a14 + a22 * m.a24 + a23 * m.a34 + a24 * m.a44,
a31 * m.a11 + a32 * m.a21 + a33 * m.a31 + a34 * m.a41,
a31 * m.a12 + a32 * m.a22 + a33 * m.a32 + a34 * m.a42,
a31 * m.a13 + a32 * m.a23 + a33 * m.a33 + a34 * m.a43,
a31 * m.a14 + a32 * m.a24 + a33 * m.a34 + a34 * m.a44,
a41 * m.a11 + a42 * m.a21 + a43 * m.a31 + a44 * m.a41,
a41 * m.a12 + a42 * m.a22 + a43 * m.a32 + a44 * m.a42,
a41 * m.a13 + a42 * m.a23 + a43 * m.a33 + a44 * m.a43,
a41 * m.a14 + a42 * m.a24 + a43 * m.a34 + a44 * m.a44);
}
inline const Matrix4& engine::Matrix4::operator *=(const Matrix4& m)
{
*this = *this * m;
return *this;
}
inline const Matrix4& engine::Matrix4::operator *=(f32 t)
{
a11 *= t; a12 *= t; a13 *= t; a14 *= t;
a21 *= t; a22 *= t; a23 *= t; a24 *= t;
a31 *= t; a32 *= t; a33 *= t; a34 *= t;
a41 *= t; a42 *= t; a43 *= t; a44 *= t;
return *this;
}
inline const Matrix4& engine::Matrix4::operator /=(f32 t)
{
a11 /= t; a12 /= t; a13 /= t; a14 /= t;
a21 /= t; a22 /= t; a23 /= t; a24 /= t;
a31 /= t; a32 /= t; a33 /= t; a34 /= t;
a41 /= t; a42 /= t; a43 /= t; a44 /= t;
return *this;
}
inline bool engine::Matrix4::operator ==(const Matrix4& m) const
{
return (Math::IsEqual(a11, m.a11) && Math::IsEqual(a12, m.a12) &&
Math::IsEqual(a13, m.a13) && Math::IsEqual(a14, m.a14) &&
Math::IsEqual(a21, m.a21) && Math::IsEqual(a22, m.a22) &&
Math::IsEqual(a23, m.a23) && Math::IsEqual(a24, m.a24) &&
Math::IsEqual(a31, m.a31) && Math::IsEqual(a32, m.a32) &&
Math::IsEqual(a33, m.a33) && Math::IsEqual(a34, m.a34) &&
Math::IsEqual(a41, m.a41) && Math::IsEqual(a42, m.a42) &&
Math::IsEqual(a43, m.a43) && Math::IsEqual(a44, m.a44));
}
inline bool engine::Matrix4::operator !=(const Matrix4& m) const
{
return !(*this == m);
}
inline f32& engine::Matrix4::operator ()(std::size_t i, std::size_t j)
{
return operator f32*()[i * 4 + j];
}
inline const f32& engine::Matrix4::operator ()(std::size_t i, std::size_t j) const
{
return operator const f32*()[i * 4 + j];
}
inline engine::Matrix4::operator const f32*() const
{
return &a11;
}
inline engine::Matrix4::operator f32*()
{
return &a11;
}
inline engine::Matrix4 operator *(const Matrix4& m, f32 t)
{
return Matrix4(m.a11 * t, m.a12 * t, m.a13 * t, m.a14 * t,
m.a21 * t, m.a22 * t, m.a23 * t, m.a24 * t,
m.a31 * t, m.a32 * t, m.a33 * t, m.a34 * t,
m.a41 * t, m.a42 * t, m.a43 * t, m.a44 * t);
}
inline engine::Matrix4 operator *(f32 t, const Matrix4& m)
{
return m * t;
}
inline engine::Matrix4 operator /(const Matrix4& m, f32 t)
{
return Matrix4(m.a11 / t, m.a12 / t, m.a13 / t, m.a14 / t,
m.a21 / t, m.a22 / t, m.a23 / t, m.a24 / t,
m.a31 / t, m.a32 / t, m.a33 / t, m.a34 / t,
m.a41 / t, m.a42 / t, m.a43 / t, m.a44 / t);
}
inline std::istream& operator >>(std::istream& iss, Matrix4 &m){
iss >> m.a11 >> m.a12 >> m.a13 >> m.a14;
iss >> m.a21 >> m.a22 >> m.a23 >> m.a24;
iss >> m.a31 >> m.a32 >> m.a33 >> m.a34;
iss >> m.a41 >> m.a42 >> m.a43 >> m.a44;
return iss;
}
inline std::ostream& operator <<(std::ostream& oss, const Matrix4 &m){
oss << m.a11 << " " << m.a12 << " " << m.a13 << " " << m.a14 << std::endl;
oss << m.a21 << " " << m.a22 << " " << m.a23 << " " << m.a24 << std::endl;
oss << m.a31 << " " << m.a32 << " " << m.a33 << " " << m.a34 << std::endl;
oss << m.a41 << " " << m.a42 << " " << m.a43 << " " << m.a44 << std::endl;
return oss;
}
inline void engine::Matrix4::OrthoOffCenter(f32 Left, f32 Top, f32 Right, f32 Bottom){
a11 = 2 / (Right - Left); a12 = 0.f; a13 = 0.f; a14 = 0.f;
a21 = 0.f; a22 = 2 / (Top - Bottom); a23 = 0.f; a24 = 0.f;
a31 = 0.f; a32 = 0.f; a33 = 1.f; a34 = 0.f;
a41 = (1+Right)/(1-Right); a42 = (Top + Bottom) / (Bottom - Top); a43 = 0.f; a44 = 1.f;
}
inline void engine::Matrix4::PerspectiveFOV(f32 FOV, f32 Ratio, f32 Near, f32 Far){
f32 height = 1.f / Math::Tan(FOV/ 2.f);
f32 width = height / Ratio;
f32 NearFarCoeff = Far / (Near - Far);
a11 = width; a12 = 0.f; a13 = 0.f; a14 = 0.f;
a21 = 0.f; a22 = height; a23 = 0.f; a24 = 0.f;
a31 = 0.f; a32 = 0.f; a33 = NearFarCoeff; a34 = -1.f;
a41 = 0.f; a42 = 0.f; a43 = Near * NearFarCoeff; a44 = 0.f;
}
inline void engine::Matrix4::LookAt(const Vector3F &From, const Vector3F &To, const Vector3F &Up){
Vector3F zaxis = From - To;
zaxis.Normalize();
Vector3F xaxis = Cross(Up, zaxis);
xaxis.Normalize();
Vector3F yaxis = Cross(zaxis, xaxis);
a11 = xaxis.x; a12 = yaxis.x; a13 = zaxis.x; a14 = 0.f;
a21 = xaxis.y; a22 = yaxis.y; a23 = zaxis.y; a24 = 0.f;
a31 = xaxis.z; a32 = yaxis.z; a33 = zaxis.z; a34 = 0.f;
a41 = -Dot(xaxis, From); a42 = -Dot(yaxis, From); a43 = -Dot(zaxis, From); a44 = 1.0f;
}
| 00xengine | src/Math/Matrix4.inl | C++ | mit | 14,539 |
#include "Mathlib.hpp"
#include "Quaternion.hpp"
#include "Matrix4.hpp"
#include "Vector2.hpp"
#include "Vector3.hpp"
namespace engine {
// Mathlib.hpp
const float Math::Pi = 3.14159265f;
const float Math::HalfPi = 1.570796325f;
const float Math::Epsilon = std::numeric_limits<float>::epsilon();
// Vector2.hpp
template<> const Vector2I Vector2I::ZERO = Vector2I(0,0);
template<> const Vector2F Vector2F::ZERO = Vector2F(0.f, 0.f);
// Vector3.hpp
template<> const Vector3I Vector3I::ZERO = Vector3I(0,0,0);
template<> const Vector3F Vector3F::ZERO = Vector3F(0.f,0.f,0.f);
template<> const Vector3F Vector3F::UNIT_Z = Vector3F(0.f,0.f,1.f);
template<> const Vector3F Vector3F::UNIT_X = Vector3F(1.f,0.f,0.f);
template<> const Vector3F Vector3F::UNIT_Y = Vector3F(0.f,1.f,0.f);
template<> const Vector3F Vector3F::NEGUNIT_Z = Vector3F(0.f,0.f,-1.f);
template<> const Vector3F Vector3F::NEGUNIT_X = Vector3F(-1.f,0.f,0.f);
template<> const Vector3F Vector3F::NEGUNIT_Y = Vector3F(0.f,-1.f,0.f);
// Matrix4.hpp
const Matrix4 Matrix4::IDENTITY = Matrix4();
void Matrix4::SetOrientation(const Quaternion &pQuat){
Matrix4 tempMat = pQuat.ToMatrix();
tempMat.SetTranslation(this->GetTranslation());
*this = tempMat;
}
void Matrix4::Rotate(const Quaternion &pQuat){
Quaternion oldOrient, newOrient;
oldOrient.FromMatrix(*this);
newOrient = oldOrient * pQuat;
this->SetOrientation(newOrient);
}
}
| 00xengine | src/Math/Mathlib.cpp | C++ | mit | 1,461 |
#include "Rectangle.hpp"
namespace engine {
Rectangle::Rectangle(s32 top, s32 left, s32 width, s32 height) : Origin(Vector2I(left, top)), End(Vector2I(left + width, top + height)){
}
Rectangle::Rectangle(const Vector2I &topLeft, const Vector2I &size) : Origin(topLeft), End(topLeft + size){
}
void Rectangle::Set(s32 top, s32 left, s32 width, s32 height){
Origin = Vector2I(left, top);
End = Vector2I(left + width, top + height);
}
s32 Rectangle::Left() const{
return Origin.x;
}
s32 Rectangle::Top() const{
return Origin.y;
}
s32 Rectangle::Right() const{
return End.x;
}
s32 Rectangle::Bottom() const{
return End.y;
}
s32 Rectangle::Width() const{
return End.x - Origin.x;
}
s32 Rectangle::Height() const{
return End.y - Origin.y;
}
Vector2I Rectangle::Size() const{
return End - Origin;
}
IntersectionResult Rectangle::Intersects(const Vector2I &Point) const{
if(Point.x >= Origin.x && Point.x <= End.x && Point.y >= Origin.y && Point.y <= End.y)
return INTR_In;
else
return INTR_Out;
}
IntersectionResult Rectangle::Intersects(const Rectangle &Rect) const{
// Creation du rectangle d'Intersection
Vector2I newRectOrigin(Math::Max(Origin.x, Rect.Origin.x), Math::Max(Origin.y, Rect.Origin.y));
Vector2I newRectEnd(Math::Min(End.x, Rect.End.x), Math::Min(End.y, Rect.End.y));
Rectangle newRect(newRectOrigin, newRectEnd);
if(newRectOrigin.x > newRectEnd.x || newRectOrigin.y > newRectEnd.y) // Si le rectangle d'Intersection est a l'exterieur d'un des deux rectangles
return INTR_Out;
else if(newRect == *this || newRect == Rect) // Si le rectangle d'Intersection est contenu dans un des deux rectangles
return INTR_In;
else // Sinon, une partie seulement est contenue, Intersection simple
return INTR_Intersect;
}
bool Rectangle::operator== (const Rectangle &Rect) const{
return ( Origin == Rect.Origin ) && ( End == Rect.End );
}
bool Rectangle::operator!= (const Rectangle &Rect) const{
return !(*this == Rect);
}
std::istream& operator>>(std::istream& iss, Rectangle& Rect){
return iss >> Rect.Origin >> Rect.End;
}
std::ostream& operator<<(std::ostream& oss, const Rectangle& Rect){
return oss << Rect.Origin << " " << Rect.End;
}
}
| 00xengine | src/Math/Rectangle.cpp | C++ | mit | 2,349 |
#ifndef AABB_HPP
#define AABB_HPP
#include "Vector3.hpp"
namespace engine {
struct Vertex;
class Quaternion;
/// \brief Axis-Aligned Bounding Box Class
class OOXAPI AABB{
/// For BSphere computation
friend class BSphere;
public:
/// \brief Ctor from already known bounding box
AABB(Vector3F pOrigin = Vector3F::ZERO, Vector3F pEnd = Vector3F::ZERO);
/// \brief Initialize the AABB from a vertices array
/// \param pVertices : vertice array
/// \param pSize : element number in above array
void Init(Vector3F* pVertices, u32 pSize);
/// \brief Sets the AABB origin position
void SetOrigin(const Vector3F &pOrigin) { mOrigin = pOrigin; }
/// \brief Sets the AABB end position
void SetEnd(const Vector3F &pEnd) { mEnd = pEnd; }
/// \brief Scales the AABB with factors depending on axis
void Scale(const Vector3F &pScaleFactor);
/// \brief Moves the AABB with a Vector
void Translate(const Vector3F &pTrans);
/// \brief Rotate the AABB with a Quaternion
void Rotate(const Quaternion &pOrient);
/// \brief Returns the 8 positions of the AABB
void GetVertices(Vector3F pTab[8]) const;
protected:
Vector3F mOrigin;
Vector3F mEnd;
};
/// \brief Bounding Sphere class
class BSphere{
public:
/// \brief Ctor from an Origin point and a Radius
BSphere(Vector3F pOrigin = Vector3F::ZERO, f32 mRadius = 1.f);
/// \brief Initialize the BSphere from a vertices array
/// \param pVertices : vertices array
/// \param pSize : element number in above array
void Init(Vertex* pVertices, u32 pSize);
/// \brief Initialize the BSphere from an AABB
void Init(const AABB &pAABB);
/// \brief Sets the BSphere radius
void SetRadius(f32 pValue) { mRadius = pValue; }
/// \brief Sets the BSphere Origin point
void SetOrigin(const Vector3F &pOrigin) { mOrigin = pOrigin; }
/// \brief Moves the BSphere with a Vector3
void Translate(const Vector3F &pTrans){ mOrigin += pTrans; }
/// \brief Scales the BSPhere
void Scale(f32 pScaleFactor) { mRadius *= pScaleFactor; }
/// \brief Returns the BSphere radius
f32 GetRadius() const { return mRadius; }
/// \brief Returns the BSphere origin point
const Vector3F& GetOrigin() const { return mOrigin; }
private:
f32 mRadius;
Vector3F mOrigin;
};
}
#endif
| 00xengine | src/Math/AABB.hpp | C++ | mit | 2,290 |